LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Fri Jul 18, 2008 4:45 pm
I searched for info in the documents, guide and here, but I can't see anything that points me right so please direct me to the proper place if necessary.
I have made a date entry checker function, to make it quicker than a calendar popup and less tedious than entering a whole date. (It will only be used for dd/mm/yyyy short format dates, although I could expand that if necessary, not that it will be.) If the user enters only a single value then it's assumed to be the day of the current month, current year. If the user puts two values separated by a slash, then it's assumed to be the day and month of the current year. If the user enters three values separated by slash then the user input is accepted as a date.
The following function works fine except for dates before 1970. If I want to check a date of birth entry field, for example, how do I set Rev to accept a year before the epoch start?
Code: Select all
function fnCheckValidDate pDate
local tDate
set the useSystemDate to true
put the date into tDate
convert tDate to short date
set the itemDelimiter to slash
if pDate is not empty then
if (0 < the number of items of pDate) and (the number of items of pDate < 4) then
if item 1 of pDate is not empty then put item 1 of pDate into item 1 of tDate
if item 2 of pDate is not empty then put item 2 of pDate into item 2 of tDate
if item 3 of pDate is not empty then put item 3 of pDate into item 3 of tDate
convert tDate to short date
if (tDate is not a date) or (the length of tDate is not 10) then
put empty into tDate
answer "The date has not been entered correctly"
end if
end if
end if
return tDate
end fnCheckValidDate
-
Mark
- Livecode Opensource Backer

- Posts: 5150
- Joined: Thu Feb 23, 2006 9:24 pm
-
Contact:
Post
by Mark » Sat Jul 19, 2008 12:15 am
Hi SparkOut,
Checking out the centuryCutoff in the docs might help.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Sat Jul 19, 2008 11:17 am
Thanks Mark
I already looked at the centuryCutoff but I couldn't see how that could apply here. The docs quote centuryCutoff as
Value:
The centuryCutoff is a two-digit number.
By default, the centuryCutoff is set to 35.
Comments:
The centuryCutoff specifies the two-digit year that ends the century. Two-digit years less than or equal to the centuryCutoff belong to the next century; two-digit years greater than the centuryCutoff belong to the previous century.
For example, if the centuryCutoff is set to 50, and the current year is 2000, then the date 4/12/51 is interpreted as being in the year 1951, while the date 4/12/50 is interpreted as being in 2050.
So the default of 35 shouldn't have any bearing on the date epoch problem not working with dates pre 1970, and in any event, my years are specified in unambiguous 4 digits, ie 1969.
If I simply do:
Code: Select all
local tDate
set the useSystemDate to true
--set the centuryCutoff to 20
--or 69, or 70, or 90, or any other centuryCutoff value makes no difference
put "01/02/1970" into tDate
if tDate is a date then answer tDate && "is a valid date"
put "01/02/1969" into tDate
if tDate is not a date then answer tDate && "is not a date"
then I get 1970 as valid and 1969 as invalid. I don't see how the centuryCutoff would help in this situation but I've tried it and it certainly seems to have no effect if I try the code snippet above (with uncommented centuryCutoff line). I get 1970 reported as valid, and 1969 reported as invalid. It doesn't help if I deliberate force a "convert tDate to short date" before testing either.
Any better ideas?
Last edited by
SparkOut on Sat Jul 19, 2008 11:52 am, edited 1 time in total.
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Sat Jul 19, 2008 11:29 am
There's definitely something problematic with the epoch cutoff pre 1970.
Code: Select all
local tDate
set the useSystemDate to true
put "01/01/1970" into tDate
convert tDate to dateItems
if tDate is a date then answer tDate && "is a valid date" -- this is valid
subtract 1 from item 1 of tDate
convert tDate to short date --this fails
if tDate is not a date then answer tDate && "is not a date" -- this is invalid
add 1 to item 1 of tDate
if tDate is a date then answer tDate && "is a valid date" -- this is valid again
I know the seconds count starts from midnight 1st January 1970, but does Rev have no way of validating a date prior to the epoch start?
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Sat Jul 19, 2008 11:36 am
I should also mention I'm using Windows (XP). Rereading the documentation for the "convert" command I notice
Note: The range of dates that the convertcommand can handle is limited by the operating system's date routines. In particular, Windows systems are limited to dates after 1/1/1970.
Although I'm baffled as to why "operating system limitations" apply. I guess I'm resigned to writing my own date validation handlers for anything that might be pre-1970 (which applies to so many situations it really means ditching the native Rev functions completely)?