Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d37e1a6

Browse files
committed
Merge pull request ernw#2 from sschmieta/datetime
DatetimeTextRecord isn't handled correctly
2 parents 3b09052 + ecbabce commit d37e1a6

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

wcf/records/text.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,32 @@ def __str__(self):
415415
return dt.isoformat()
416416

417417
def to_bytes(self):
418-
bytes = super(DateTimeTextRecord, self).to_bytes()
418+
"""
419+
>>> ''.join('%02X' % ord(i) for i in DatetimeTextRecord(632834208000000000, 0).to_bytes())
420+
'9600408EF95B47C808'
421+
>>> ''.join('%02X' % ord(i) for i in DatetimeTextRecord(632834208000000000, 2).to_bytes())
422+
'9600408EF95B47C888'
423+
"""
424+
bytes = super(DatetimeTextRecord, self).to_bytes()
419425
bytes += struct.pack('<Q',
420-
(self.tz & 3) | (self.value & 0x1FFFFFFFFFFFFFFF) << 2)
426+
((self.tz & 3) << 62) | (self.value & 0x3FFFFFFFFFFFFFFF))
421427

422428
return bytes
423429

424430
@classmethod
425431
def parse(cls, fp):
432+
"""
433+
>>> import StringIO
434+
>>> fp = StringIO.StringIO('\\xFF\\x3F\\x37\\xF4\\x75\\x28\\xCA\\x2B')
435+
>>> str(DatetimeTextRecord.parse(fp))
436+
'9999-12-31T23:59:59.999999'
437+
>>> fp = StringIO.StringIO('\\x00\\x40\\x8E\\xF9\\x5B\\x47\\xC8\\x08')
438+
>>> str(DatetimeTextRecord.parse(fp))
439+
'2006-05-17T00:00:00'
440+
"""
426441
data = struct.unpack('<Q', fp.read(8))[0]
427-
tz = data & 3
428-
value = data >> 2
442+
tz = data >> 62
443+
value = data & 0x3FFFFFFFFFFFFFFF
429444

430445
return DatetimeTextRecord(value, tz)
431446

0 commit comments

Comments
 (0)