[New-bugs-announce] [issue23332] datetime.isoformat() -> explicitly mark UTC string as such

Mirko Vogt report at bugs.python.org
Tue Jan 27 18:37:29 CET 2015


New submission from Mirko Vogt:

I trapped into a pitfall today with web programming using DateTime.isoformat() in the backend and Javascript on the frontend side.

isoformat() string'yfies a DateTime-object according to ISO 8601, which states that, if no timezone is specified, the string is supposed to be interpreted as UTC implicitly. isoformat() doesn't append any TZ if the object is UTC - so far so good.

However when interacting with JavaScript that leads to errors, as the ECMAScript ed 6 draft states (and most browser act like that): "date time strings without a time zone are to be treated as local, not UTC)."[1]

That is not Python's fault - however considering the issues this behaviour could cause as well as following the philosophy 'explicit is better than implicit', I'd suggest explicitly marking UTC-strings as such by adding a trailing 'Z'. According ISO 8601 that is totally fine, optional though.

[1]https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse

----------
messages: 234829
nosy: mirkovogt
priority: normal
severity: normal
status: open
title: datetime.isoformat() -> explicitly mark UTC string as such
type: behavior

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23332>
_______________________________________


More information about the New-bugs-announce mailing list