Page 1 of 1
Concerning Dateitems
Posted: Sat Mar 28, 2015 4:51 pm
by Rage
I have a snippet of code which is as follows:
put the date into DateNum
Convert Datenum to dateitems
put item 1 of Datenum into Dyear
put item 2 of Datenum into Dmonth
put item 3 of Datenum into Dday
put item 4 of Datenum into Dhour
put item 7 of Datenum into Dnumofday
Seems straight forward......the returning data for Datenum after conversion is 2015,3,28,0,0,7
but the value for Dday is 27 and the conversion seems to not pick up anything for the hour or minute.
Any thoughts as to why this is happening?.........the code I included is line for line with no other calculations in between
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 6:03 pm
by dunbarx
Hi.
DateItems does not concern itself with the time. There are other tools to do that, for example, the "internet date". If you are ambitious, you can use "the seconds".
There are issues with daylight savings time, time zones and midnights, calculating the difference between events in light of those, etc. But if you are getting the 27th as the date, then your system thinks it is the 27th. The call to the "date" function depends entirely on your machine and its settings. It is not a LC thing.
Craig
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 6:12 pm
by FourthWorld
The answer to the output is in the input: "the date" returns a date with no time, so conversion to dateItems uses midnight, or zero values.
If you need the current time it's probably simplest to use "seconds".
Interesting tidbit about "seconds" in LiveCode that I didn't learn until a few years ago: the integer returned is not merely the number of seconds elapsed from an arbitrary date (January 1, 1970, FWIW), but it's also expressed in GMT, adjusted from the time zone settings of the OS. So if you store the seconds at 10:00 AM on a machine in PDT, and then read the value and convert it to something like "the time" on a machine in EDT, the value you'll read will be automatically adjusted for the local time zone, with the time portion reading "1:00 PM". Very handy.
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 6:16 pm
by Rage
Thank you Craig for your reply.........
I would have thought the same thing but my system indicates the correct date, so to apply your thought pattern
it would have to think it was one date and then display another. Which isn't a logical conclusion.
in the Livecode dictionary under dateitems it states:
Use the dateItems keyword with the convert command to store a date and/or time.
Comments:
The dateItems format is a comma-separated list of numbers:
* the year
* the month number
* the day of the month
* the hour in 24-hour time
* the minute
* the second
* the numeric day of the week where Sunday is day 1, Monday is day 2, and so forth
The dateItems does not change depending on the user's settings, so you can use it (or the seconds format) to store a date and time with a stack, in an invariant form that won't change.
Is this to mean then that the dictionary is incorrect?
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 6:21 pm
by dunbarx
Hi.
If you want the time as well in the dateItems, you have to explicitly request it, otherwise only date info will appear:
Code: Select all
on mouseUp
get the long date && the time
convert it to dateItems
end mouseUp
I should have been clearer. The dictionary deals with this pretty well. Check it out again.
Craig
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 6:54 pm
by Rage
Thank you for your suggestion Craig
So I placed the following code based on your suggestion
get the long date && the time
put it into DateNum
convert DateNum to dateItems
And the hour, minutes and seconds work perfectly..........but the day is still off by 1 indicating it's
the 27th and not the 28th.........strange
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 6:57 pm
by Rage
I should note that the return of dateitem indicates that it is the 28th
but the line:
put item 3 of Datenum into Dday
seems to somehow shift it by 1 day
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 7:02 pm
by SparkOut
Can you step through the code and check that each line is working? If your date items string is "2015,3,28,0,0,7" then item 3 of the string is 28, and like you, I would imagine that to be stored in Dday as 28, regardless of any fancy reference to the offset from the start of epoch. Is Dday being set, or just holding a value from when you tried yesterday and something gone wrong with applying a code update to your script?
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 7:09 pm
by Rage
Thank you for replying Sparkout
Every time I change the code I save and then close out the script and any open 'cards' then reload via the 'Open recent files'
Per chance the IDE might have retained the value I closed the entire program and reloaded it and re-running the file gave me the same incorrect
results.
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 7:18 pm
by SparkOut
Try putting empty into Dday at the beginning of the script, then step through and watch the variable change when you get to the line "put item 3 of Datenum into Dday". If you can see the variable Datenum contains "2015,3,28,0,0,7" and you watch Dday change from empty to 27, then I'd consider this a bug, but having copied and pasted your original code and tried it here, showing 28 displayed in Dday, I still think there might be something wrong in the script.
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 7:43 pm
by FourthWorld
Rage wrote:Thank you for your suggestion Craig
So I placed the following code based on your suggestion
get the long date && the time
put it into DateNum
convert DateNum to dateItems
And the hour, minutes and seconds work perfectly..........but the day is still off by 1 indicating it's
the 27th and not the 28th.........strange
Unable to reproduce. What time zone are you in?
Re: Concerning Dateitems
Posted: Sat Mar 28, 2015 10:45 pm
by Rage
Ok so I did a line by line trace of the entire script and found where the value of Dday had changed to compensate for a
variant in the Julian date..........bottom line is my bad for not going through the entire script prior to posting.........
But at least I did learn some valuable information concerning the time issue.
Thank you for your time and replies