Dates In Revolution
Ken Ray
kray at sonsothunder.com
Tue Jan 31 13:22:43 EST 2006
On 1/31/06 11:50 AM, "Gregory Lypny" <gregory.lypny at videotron.ca> wrote:
> Hello Everyone,
>
> I know this is an old problem. I just want to confirm whether it has
> been fixed. I suspect not.
>
> Suppose it's ten past six in the morning on Saturday, May 1st, 1999
> in Montreal. I enter this date in the handler below.
>
> put "May 1, 1999" && "6:10" into d
> convert d to dateItems
> put d & return
> convert d to internet date
> put d after msg
>
> Here's what appears in the message box.
>
> 1999,5,1,7,10,0,7
> Sat, 1 May 1999 08:10:00 -0500
>
> The dateItems say that it's ten past seven, so I suppose it adjusted
> for Daylight Savings Time. The problem is, it is ten past six local
> time as entered, so it already reflects Daylight Savings Time.
> Converting it to the internet date then tells me it's ten past
> eight. I see the hours and my life slipping away, so I close my
> computer and go to Schwartz's for a big, fat smoked meat sandwich
> because I figure it may as well be lunchtime.
>
> What am I misunderstanding here?
Well, you have it right - the first convert is taking into account DST and
bumping your time ahead... but then you feed the new time into another
convert and it doesn't know that it's already been adjusted for DST, so it
adjusts it *again*. This will happen every time you move the date into
another convert statement. Here's what I mean:
put "May 1, 1999" && "6:10" into d
convert d to dateItems
put d & return
convert d to dateItems
put d & return after msg
convert d to dateItems
put d after msg
You get:
1999,5,1,7,10,0,7
1999,5,1,8,10,0,7
1999,5,1,9,10,0,7
However, if you use my handy-dandy date routines, you will smell like a rose
- as it takes into account DST to give you what you want:
----------------------------------------
--| stsConvert acts like the "convert" command, but (a) is a function, and
--| (b) does not adjust the returned value based on Daylight Savings Time.
----------------------------------------
function stsConvert pDateTime,pFormat
-- pFormat is a 'convert' phrase, like "short date and short time"
put pDateTime into tItems
convert tItems to dateItems
put item 1 of tItems into tYear
convert pDateTime to seconds
put stsDSTDate("spring",tYear) into tSpringDST
put stsDSTDate("fall",tYear) into tFallDST
convert tSpringDST to seconds
convert tFallDST to seconds
put the date && the time into tNow
convert tNow to dateItems
put tYear into item 1 of tNow
convert tNow to seconds
if (tNow > tSpringDST) and (tNow < tFallDST) then
-- add 1 hour to any date on the "other side" of DST
if (pDateTime <= tSpringDST) or (pDateTime >= tFallDST) then
add 3600 to pDateTime
end if
else
if (pDateTime >= tSpringDST) and (pDateTime <= tFallDST) then
subtract 3600 from pDateTime
end if
end if
do "convert pDateTime to" && pFormat
return pDateTime
end stsConvert
----------------------------------------
--| stsDSTDate retrieves the Spring or Fall date for a given year that will
--| be the date for the Daylight Savings Time changeover. The Spring date is
--| the 1st Sunday in April; the Fall date is the last Sunday in October.
----------------------------------------
function stsDSTDate pType,pYear
-- pType is either "spring" or "fall"
-- Spring DST is 1st Sunday in April
-- Fall DST is last Sunday in October
if pYear = "" then
put the date into tNow
convert tNow to dateItems
put item 1 of tNow into pYear
end if
switch pType
case "Spring"
repeat with x = 1 to 7
put "4/" & x & "/" & pYear into tDate
put tDate into tDateTest
convert tDateTest to dateItems
if item -1 of tDateTest = "1" then -- Sunday
return tDate
end if
end repeat
break
case "Fall"
repeat with x = 31 down to 25
put "10/" & x & "/" & pYear into tDate
put tDate into tDateTest
convert tDateTest to dateItems
if item -1 of tDateTest = "1" then -- Sunday
return tDate
end if
end repeat
break
end switch
end stsDSTDate
NOW, you can do this:
put stsConvert("May 6, 1999 6:10","dateItems")
and get:
1999,5,1,6,10,0,7
:-)
Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com
More information about the use-livecode
mailing list