pytoml icon indicating copy to clipboard operation
pytoml copied to clipboard

datetime issue

Open ghost opened this issue 9 years ago • 2 comments

python 3.4.3, pytoml==0.1.7

>>> import pytoml as toml
>>> import datetime
>>> d={'dt':datetime.datetime.now()}
>>> d
{'dt': datetime.datetime(2016, 2, 25, 11, 18, 17, 536767)}

>>> toml.dumps(d)
'dt = 2016-02-25T11:18:17.536767Z\n'
>>> toml.loads(toml.dumps(d))
{'dt': datetime.datetime(2016, 2, 25, 11, 18, 17, 536767, tzinfo=<pytoml.parser._TimeZone object at     0x7f9aca381978>)}
>>> d == toml.loads(toml.dumps(d))
False

ghost avatar Feb 24 '16 22:02 ghost

TOML 0.4 only allowed datetimes with timezone information attached - what Python calls a "datetime aware" datetime. When you dump a "naive" timezone, with no timezone info, it looks like pytoml opts to treat that as meaning UTC.

TOML 1.0 (not out yet) adds a separate 'local datetime' type for timestamps without timezone information. https://github.com/toml-lang/toml/pull/414

takluyver avatar May 29 '18 14:05 takluyver

Thanks for the issue!

As @takluyver points out, this is not a bug, pytoml accepts naive datetimes only as a convenience. Adding compliance with 1.0 would be a new feature and I'm not working on those anymore. Feel free to send a PR though!

avakar avatar May 30 '18 08:05 avakar