Page 1 of 1
Frozen on November Fourth
Posted: Mon Mar 19, 2012 10:40 pm
by NZN37
I want some code which lists days in order:
on mouseUp
put empty into fld test
put "10/31/12" into temp
repeat with zz=1 to 6
convert temp to seconds
add 86400 to temp
convert temp to short date
put temp into line zz of fld test
end repeat
end mouseUp
But the thing hangs on 11/4/12 and repeats that date indefinitely.
What gives??
Re: Frozen on November Fourth
Posted: Mon Mar 19, 2012 11:20 pm
by bn
Hi NZN37,
apparently you live in a country that reverts from daylight saving time on Nov fourth. The night is one hour longer and you are stuck on that date because of your data/seconds conversions. 86400 will not be enough to go to the next day on that day. (where I live it is Oct 28th)
I just changed your code a bit:
Code: Select all
on mouseUp
put empty into fld test
put "10/26/12" into temp
convert temp to seconds
repeat with zz=1 to 16
put temp into temp2
convert temp2 to short date
put temp2 into line zz of fld test
add 86400 to temp
end repeat
end mouseUp
Kind regards
Bernd
Re: Frozen on November Fourth
Posted: Tue Mar 20, 2012 2:34 am
by dunbarx
Well done Bernd.
The way around this of course is to add 1 to item 3 of the dateItems.
Did I mention that it was well done?
Craig Newman
Re: Frozen on November Fourth
Posted: Tue Mar 20, 2012 9:31 am
by bn
Hi Craig,
thank you. But unfortunately my solution was not well done. It ran into the same problem I was describing. When daylight saving ends the day has 90.000 seconds. I did not take that into account. It gives the ending date twice.
(I did test the code but overlooked this)
Here is a solution with dateItems
Code: Select all
on mouseUp
put empty into fld test
put "10/26/12" into temp
convert temp to dateItems
repeat with zz=1 to 16
put temp into temp2
convert temp2 to short date
put temp2 into line zz of fld test
add 1 to item 3 of temp
end repeat
end mouseUp
sorry for the confusion and thank you Craig for bringing this up again.
If you want to stick to adding 86400 seconds you would have to start from noon. That is what Sarah Reichelt recomends.
Code: Select all
on mouseUp
put empty into fld test
put "12:00" into tNoon
put "10/26/12" && tNoon into temp
convert temp to seconds
repeat with zz=1 to 16
put temp into temp2
convert temp2 to short date
put temp2 into line zz of fld test
add 86400 to temp
end repeat
end mouseUp
Craig's suggestion to use dateItems is definitely the way to go.
Kind regards
Bernd