Skip to content

Commit f72ee3d

Browse files
committed
Encodes a recent clarification by sheutka regarding the parsing of the replay date. sheutka pointed out that it was represented in file by a Windows nano time stamp (100^-7) measured from January 1st 1601. This allowed us to make clear some procedures that were previously 'magic'.
1 parent de34ab3 commit f72ee3d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

sc2reader/readers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sc2reader.parsers import *
44
from sc2reader.objects import *
55
from sc2reader.utils import ByteStream
6-
from sc2reader.utils import key_in_bases
6+
from sc2reader.utils import key_in_bases, timestamp_from_windows_time
77

88
#####################################################
99
# Metaclass used to help enforce the usage contract
@@ -116,8 +116,9 @@ def read(self, filecontents, replay):
116116
# This might be due to wrong value of the magic constant 116444735995904000
117117
# or rounding errors. Ceiling or Rounding the result didn't produce consistent
118118
# results either.
119-
replay.date = datetime.fromtimestamp((replay.file_time-116444735995904000)/10000000)
120-
replay.utc_date = datetime.utcfromtimestamp((replay.file_time-116444735995904000)/10000000)
119+
unix_timestamp = timestamp_from_windows_time(replay.file_time)
120+
replay.date = datetime.fromtimestamp(unix_timestamp)
121+
replay.utc_date = datetime.utcfromtimestamp(unix_timestamp)
121122

122123
replay.details_data = data
123124

sc2reader/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ def read_header(file):
196196
#return the release and frames information
197197
return data[1],data[3]
198198

199+
def timestamp_from_windows_time(windows_time):
200+
# This windows timestamp measures the number of 100 nanosecond periods since
201+
# January 1st, 1601. First we subtract the number of nanosecond periods from
202+
# 1601-1970, then we divide by 10^7 to bring it back to seconds.
203+
return (windows_time-116444735995904000)/10**7
199204

200205
import inspect
201206
def key_in_bases(key,bases):

0 commit comments

Comments
 (0)