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

Skip to content

Commit ecbabce

Browse files
committed
Fix DatetimeTextRecord parse() and to_bytes()
The implementation was assuming big-endian ordering of the tz and value bits but it should be little-endian.
1 parent f806197 commit ecbabce

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

wcf/records/text.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def to_bytes(self):
423423
"""
424424
bytes = super(DatetimeTextRecord, self).to_bytes()
425425
bytes += struct.pack('<Q',
426-
(self.tz & 3) | (self.value & 0x1FFFFFFFFFFFFFFF) << 2)
426+
((self.tz & 3) << 62) | (self.value & 0x3FFFFFFFFFFFFFFF))
427427

428428
return bytes
429429

@@ -439,8 +439,8 @@ def parse(cls, fp):
439439
'2006-05-17T00:00:00'
440440
"""
441441
data = struct.unpack('<Q', fp.read(8))[0]
442-
tz = data & 3
443-
value = data >> 2
442+
tz = data >> 62
443+
value = data & 0x3FFFFFFFFFFFFFFF
444444

445445
return DatetimeTextRecord(value, tz)
446446

0 commit comments

Comments
 (0)