Checking and comparing Date and Time
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Checking and comparing Date and Time
Hi everyone!
Me again with another - hopefully for this app atleast - last question.
In my app I only allow the user to do things in certain time spans. So for example: The user is only allowed to use the app on the first day inbetween 3pm and 5pm on the second day inbetween 9am and 11am and so on. Then on the seventh day the user isn't allowed to use the app anymore (it's a medical study, that's why)
What I'd do is to just lock the screen if the current date and time isn't one of those allowed times and otherwise he can answer the survey in my app.
What I kinda thought would be the way is that I save the date + time into two hidden fields when the user opens the app for the first time - that's my StartDate and StartTime. Then whenever the user opens the app I'd do a "on preopenStack"-command to check for the current date and time and compare it with my StartDate/StartTime - I thought of some switch-case-scenario kinda like "case actualdate = startdate+1" if that is the case then some "if-command" for the time-span.
But atleast as I tried it I didn't get it to work yet, so I was hoping that someone could give me some advise for this, how to do it better.
Thanks in advance!!
Me again with another - hopefully for this app atleast - last question.
In my app I only allow the user to do things in certain time spans. So for example: The user is only allowed to use the app on the first day inbetween 3pm and 5pm on the second day inbetween 9am and 11am and so on. Then on the seventh day the user isn't allowed to use the app anymore (it's a medical study, that's why)
What I'd do is to just lock the screen if the current date and time isn't one of those allowed times and otherwise he can answer the survey in my app.
What I kinda thought would be the way is that I save the date + time into two hidden fields when the user opens the app for the first time - that's my StartDate and StartTime. Then whenever the user opens the app I'd do a "on preopenStack"-command to check for the current date and time and compare it with my StartDate/StartTime - I thought of some switch-case-scenario kinda like "case actualdate = startdate+1" if that is the case then some "if-command" for the time-span.
But atleast as I tried it I didn't get it to work yet, so I was hoping that someone could give me some advise for this, how to do it better.
Thanks in advance!!
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Checking and comparing Date and Time
Hi,
If those flelds are in your standalone, don't forget that a standalone can't be save
Best regards
Jean-Marc
Why don't use the seconds to define the available times ?I save the date + time into two hidden fields
If those flelds are in your standalone, don't forget that a standalone can't be save
Best regards
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 9660
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Checking and comparing Date and Time
After reading your post I instantly knew the "seconds" as the way forward. Then I saw that Jean-Marc posted the very same idea.
So, not being sure of how far along with LC you are, do you see how this might work? (pseudo)
You have to calculate the translation from the seconds to the start/end value pairs which are likely in time/date format. This is probably best be done on that very first opening of the app. You know, there are 86,400 seconds in a day, 3600 in an hour, that sort of thing. A little bit of thought may be required to isolate that first opening from all the others. You OK with that?
Craig Newman
So, not being sure of how far along with LC you are, do you see how this might work? (pseudo)
Code: Select all
on openstack
if this is the first opening, set a custom property (say, "the startTime") with the seconds. Also load your start/end pairs of clock times
--for each subsequent opening, if the seconds - the startTime is between pairs of two pre-defined values
switch
case the seconds - starTime is between timeValuePair1
do firstDayStuff
break[
case the seconds - starTime is between timeValuePair2
do secondDayStuff
break[
end switch
Craig Newman
Re: Checking and comparing Date and Time
Thanks a lot to both of you! I managed to do it!
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Checking and comparing Date and Time
Don't forget to think about what to do when a user changes his system time and/or disconnects from internet
shiftLock happens
Re: Checking and comparing Date and Time
Do you know that there is a specific date/time library? See https://github.com/derbrill/libdate
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w