File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -415,17 +415,32 @@ def __str__(self):
415
415
return dt .isoformat ()
416
416
417
417
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 ()
419
425
bytes += struct .pack ('<Q' ,
420
- (self .tz & 3 ) | (self .value & 0x1FFFFFFFFFFFFFFF ) << 2 )
426
+ (( self .tz & 3 ) << 62 ) | (self .value & 0x3FFFFFFFFFFFFFFF ) )
421
427
422
428
return bytes
423
429
424
430
@classmethod
425
431
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
+ """
426
441
data = struct .unpack ('<Q' , fp .read (8 ))[0 ]
427
- tz = data & 3
428
- value = data >> 2
442
+ tz = data >> 62
443
+ value = data & 0x3FFFFFFFFFFFFFFF
429
444
430
445
return DatetimeTextRecord (value , tz )
431
446
You can’t perform that action at this time.
0 commit comments