bobfang1992 / pytomlpp

A python wrapper for tomlplusplus
https://bobfang1992.github.io/pytomlpp/pytomlpp.html
MIT License
86 stars 11 forks source link

Incorrect dump of date-time objects #34

Closed EpicWink closed 4 years ago

EpicWink commented 4 years ago

Dumping seems to giving an incorrect value for date-time objects. I added some round-trip tests to show this.

See the failed workflow, with the datetime test outputting:

# Original text
bestdayever = 1987-07-05T17:45:00Z
numoffset = 1977-06-28T07:32:00-05:00
milliseconds = 1977-12-21T10:32:00.555+07:00

# Loaded value (correct)
{
  'bestdayever': datetime.datetime(1987, 7, 5, 17, 45, tzinfo=datetime.timezone.utc), 
  'milliseconds': datetime.datetime(1977, 12, 21, 10, 32, 0, 555000, tzinfo=datetime.timezone(datetime.timedelta(seconds=25200))), 
  'numoffset': datetime.datetime(1977, 6, 28, 7, 32, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=68400)))
}

# Written text (incorrect)
bestdayever = 0005-07-195T07:195:07.332077Z
milliseconds = 0021-12-185T07:185:12+07:00
numoffset = 0028-06-185T07:185:06-05:00
chaitan94 commented 4 years ago

Addressed and fixed this - check #35. I was assuming since we had a test suite some sanity tests for all types were covered so I went a bit off-guard while writing this code. Seems I was wrong, pretty bad bugs crept in indeed :sweat_smile:

chaitan94 commented 4 years ago

Currently passthrough tests for all three date/time types work:

import pytomlpp
t = pytomlpp.loads('bestdateever = 1987-07-05')
print(t)
t = pytomlpp.dumps(t)
print(t)
t = pytomlpp.loads('besttimeever = 17:45:00')
print(t)
t = pytomlpp.dumps(t)
print(t)
t = pytomlpp.loads('bestdatetimeever = 1987-07-05T17:45:00Z')
print(t)
t = pytomlpp.dumps(t)
print(t)
{'bestdateever': datetime.date(1987, 7, 5)}
bestdateever = 1987-07-05
{'besttimeever': datetime.time(17, 45)}
besttimeever = 17:45:00
{'bestdatetimeever': datetime.datetime(1987, 7, 5, 17, 45, tzinfo=datetime.timezone.utc)}
bestdatetimeever = 1987-07-05T17:45:00Z
EpicWink commented 4 years ago

Yeah my bad, I failed to add dump tests