Cameron McCormack wrote:
I want to serialize my times such that they match this regular expression:
m[^(....)/(..)/(..)T(..):(..):(..)(D?)/(.*)]
G'day Cameron,
Looks good to a point .. however you're duplicating data or missing data
depending on how you're defining your time zone.
If your time zone is 'Australia/Melbourne' then you're duplicating it.
2005-06-10 can only ever be non-daylight savings and so your optional
'D' is redundant.
However if your time zone is a UTC offset (such as +1000) then you're
missing data. See right now Hobart, Melbourne, Sydney and Brisbane are
all at UTC+1000, so given a datetime such as:
"2005/06/10T21:47:00/+1000", to use your format, we seem to be OK.
However the problem is calculating around the DST changeover and once
DST is in effect. See Hobart changes one weekend, then the next weekend
Melbourne and Sydney will change, and Brisbane have cleverly decided
that DST is silly and so will never change. Given your string we can't
know which of these zones to follow for the change (or even if we might
be in any of the other possible +1000 zones)
The best way to serialize is to store the Olson Time Zone with an ISO date:
'2005-06-10T21:47:00 Australia/Melbourne'
(If that's too long I'm sure it wouldn't be hard for you to create zone
abreviations such as AUho AUme AUsy and AYbr which would then be
reinflated before turning back into DateTime objects.)
but of course there is no 'dst' parameter to pass to the constructor.
There must be an easy way to the DateTime object taking into account the
DST-ness of the time. Any hints?
Just to reiterate, there is no way to take into account the 'DST-ness'
of a datetime simply because the rules are too ambiguous.
Once you have a DateTime object however, you can use the ->is_dst method
to determine the DST-ness.
Cheers!
Rick Measham