Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

Remove usage of `int` method within SQLite interface TimestampType #100

Closed jaridmargolin closed 4 years ago

jaridmargolin commented 4 years ago

int(...) is used several times within the convert method of TimestampType. This, however, leads to the unintended consequence of trimming off leading 0s from any string segment. All usages of int(...) should be replaced with alternative solutions.

Jaymon commented 4 years ago

By way of example, notice the milliseconds in the original (057350) and the converted (573500)

'original': '2020-03-25T19:34:05.057350Z
'converted': datetime.datetime(2020, 3, 25, 19, 34, 5, 573500)
Jaymon commented 4 years ago

This was the only discussion I could find even remotely about this problem: python: subtraction of timestamps fails due to omitted leading zeros in microsec

And it lead me to the discovery that the timedelta class has a milliseconds argument I could use, which allowed me to break up the microseconds into two chunks of 3 and then add them to the timestamp to keep the correct value from the parsed string datetime.

search: