Skip to content

Commit 777410a

Browse files
committed
Fixed issue with negative dates with fractional seconds (fixes #29)
1 parent 4387c90 commit 777410a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

asynctnt/iproto/ext.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ cdef void datetime_from_py(datetime ob, IProtoDateTime *dt):
187187
ts = <double> ob.timestamp()
188188
dt.seconds = <int64_t> ts
189189
dt.nsec = <int32_t> ((ts - <double> dt.seconds) * 1000000) * 1000
190+
if dt.nsec < 0:
191+
# correction for negative dates
192+
dt.seconds -= 1
193+
dt.nsec += 1000000000
190194

191195
if datetime_tzinfo(ob) is not None:
192196
offset = ob.utcoffset().total_seconds()

0 commit comments

Comments
 (0)