Subject: | datetime() / iso8601() method discards timezone information |
Date: | Tue, 17 Mar 2015 15:14:55 -0700 |
To: | bug-DateTime [...] rt.cpan.org |
From: | Adam Williamson <awilliam [...] redhat.com> |
I noticed that datetime seems to have no way to produce an ISO8601
string with a timezone offset. When you do web searches for this you
find multiple places where people have reinvented essentially the same
fairly trivial function to stuff the timezone offset on the end of the
output of datetime() / iso8601().
A patch to include this was submitted before but rejected:
https://rt.cpan.org/Public/Bug/Display.html?id=83689
I find the rejection strange, however. The cited reason is:
"since the time zone is specified in a way that loses info"
however, isn't the current code losing way *more* information? A
datetime object will often have a timezone explicitly specified.
Surely simply entirely throwing it away when producing an 'ISO8601'
representation of that date/time is losing more information than
representing it with a slight loss of detail?
Almost more importantly, note that per ISO8601, a string with no TZ
offset is not considered to have an 'unknown' timezone, but is
considered to be for the 'local' timezone, whatever that may be in
context.
Effectively, when I call 'iso8601' on a datetime object which has a
specific timezone, the timezone is entirely thrown away, and the
resulting string is a valid ISO8601 string but one which clearly does
not accurately represent the datetime object from which it was produced.
Surely it's better to represent the timezone with a slight loss of
precision than it is not to include it at all?
Obviously the existing behaviour has been around sufficiently long
that it would probably need to remain the default, but it should at
least be possible to obtain a more correct outcome via a parameter or
similar.
--
Adam Williamson
Fedora QA Community Monkey
IRC: adamw | Twitter: AdamW_Fedora | XMPP: adamw AT happyassassin . net
http://www.happyassassin.net