Odd results with converting dates
Posted: Sun Jan 18, 2015 12:05 pm
I ran across some odd behavior while writing some unit tests against a stack. My test cycles through the calendar and everything goes fine until I reach November. For some reason it appears convert to long date is not giving me what I expect and the date this happens is different depending upon the year. Maybe there is a better way to increment the date by a day that I am unaware of.
Here is sample code and example output that shows what I am seeing..
put "1/1/2015" into theDate
put "" into card field “testOutput”
repeat for 700 times
convert theDate to long date
put theDate after field “testOutput”
convert theDate to seconds
put " = " & theDate & "(sec) next day: " after field “testOutput”
add 86400 to theDate
convert theDate to long date
convert theDate to seconds
put theDate &"(sec)" & CRLF after field “testOutput”
end repeat
[sample output]…
Friday, October 23, 2015 = 1445583600(sec) next day: 1445670000(sec)
Saturday, October 24, 2015 = 1445670000(sec) next day: 1445756400(sec)
Sunday, October 25, 2015 = 1445756400(sec) next day: 1445842800(sec)
Monday, October 26, 2015 = 1445842800(sec) next day: 1445929200(sec)
Tuesday, October 27, 2015 = 1445929200(sec) next day: 1446015600(sec)
Wednesday, October 28, 2015 = 1446015600(sec) next day: 1446102000(sec)
Thursday, October 29, 2015 = 1446102000(sec) next day: 1446188400(sec)
Friday, October 30, 2015 = 1446188400(sec) next day: 1446274800(sec)
Saturday, October 31, 2015 = 1446274800(sec) next day: 1446361200(sec)
Sunday, November 1, 2015 = 1446361200(sec) next day: 1446361200(sec)
Sunday, November 1, 2015 = 1446361200(sec) next day: 1446361200(sec)
Sunday, November 1, 2015 = 1446361200(sec) next day: 1446361200(sec)
Sunday, November 1, 2015 = 1446361200(sec) next day: 1446361200(sec)
Sunday, November 1, 2015 = 1446361200(sec) next day: 1446361200(sec)
…
If I change the year that the test starts from it hangs at a different date..
In 2016 it gets hung up on Sunday, November 6, 2016
In 2017 : Sunday, November 5, 2017
In 2018 : Sunday, November 4, 2018
Also if I have the test start with Nov 2, 2015 it runs fine until it reaches Nov 6, 2016.
I’m running LiveCode 7 Community Edition 7.0.1 | Build 10023 on a Mac with OS/X 10.10.1
Thanks,
Alan
Here is sample code and example output that shows what I am seeing..
put "1/1/2015" into theDate
put "" into card field “testOutput”
repeat for 700 times
convert theDate to long date
put theDate after field “testOutput”
convert theDate to seconds
put " = " & theDate & "(sec) next day: " after field “testOutput”
add 86400 to theDate
convert theDate to long date
convert theDate to seconds
put theDate &"(sec)" & CRLF after field “testOutput”
end repeat
[sample output]…
Friday, October 23, 2015 = 1445583600(sec) next day: 1445670000(sec)
Saturday, October 24, 2015 = 1445670000(sec) next day: 1445756400(sec)
Sunday, October 25, 2015 = 1445756400(sec) next day: 1445842800(sec)
Monday, October 26, 2015 = 1445842800(sec) next day: 1445929200(sec)
Tuesday, October 27, 2015 = 1445929200(sec) next day: 1446015600(sec)
Wednesday, October 28, 2015 = 1446015600(sec) next day: 1446102000(sec)
Thursday, October 29, 2015 = 1446102000(sec) next day: 1446188400(sec)
Friday, October 30, 2015 = 1446188400(sec) next day: 1446274800(sec)
Saturday, October 31, 2015 = 1446274800(sec) next day: 1446361200(sec)
Sunday, November 1, 2015 = 1446361200(sec) next day: 1446361200(sec)
Sunday, November 1, 2015 = 1446361200(sec) next day: 1446361200(sec)
Sunday, November 1, 2015 = 1446361200(sec) next day: 1446361200(sec)
Sunday, November 1, 2015 = 1446361200(sec) next day: 1446361200(sec)
Sunday, November 1, 2015 = 1446361200(sec) next day: 1446361200(sec)
…
If I change the year that the test starts from it hangs at a different date..
In 2016 it gets hung up on Sunday, November 6, 2016
In 2017 : Sunday, November 5, 2017
In 2018 : Sunday, November 4, 2018
Also if I have the test start with Nov 2, 2015 it runs fine until it reaches Nov 6, 2016.
I’m running LiveCode 7 Community Edition 7.0.1 | Build 10023 on a Mac with OS/X 10.10.1
Thanks,
Alan