Skip to content

Commit 06e6131

Browse files
committed
Attempt 3 at timestamps. Always show times in UTC.
details.file_time is always the windows timestamp of the utc time. details.utc_adjustment is either the adjusted windows timestamp or the value required to make that adjustment.
1 parent d47e30d commit 06e6131

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

sc2reader/resources.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,22 +282,18 @@ def load_details(self):
282282
else:
283283
raise ValueError("Unknown operating system {} detected.".format(details.os))
284284

285-
# If the utc_adjustment is really an adjustment it's magnitude will be
286-
# less than 24 hours in the unit of 1/10**7 of a second. Negative values
287-
# must always be adjustments
285+
self.windows_timestamp = details.file_time
286+
self.unix_timestamp = utils.windows_to_unix(self.windows_timestamp)
287+
self.end_time = datetime.utcfromtimestamp(self.unix_timestamp)
288+
289+
# The utc_adjustment is either the adjusted windows timestamp OR
290+
# the value required to get the adjusted timestamp. We know the upper
291+
# limit for any adjustment number so use that to distinguish between
292+
# the two cases.
288293
if details.utc_adjustment < 10**7*60*60*24:
289-
self.windows_timestamp = details.file_time-details.utc_adjustment
290-
self.unix_timestamp = utils.windows_to_unix(self.windows_timestamp)
291294
self.time_zone = details.utc_adjustment/(10**7*60*60)
292-
self.end_time = datetime.utcfromtimestamp(self.unix_timestamp)
293-
294-
# Otherwise the utc_adjustment is the windows timestamp of the local time
295-
# And the file_time is the windows timestamp of the utc time.
296295
else:
297-
self.windows_timestamp = details.file_time
298-
self.unix_timestamp = utils.windows_to_unix(self.windows_timestamp)
299296
self.time_zone = (details.utc_adjustment-details.file_time)/(10**7*60*60)
300-
self.end_time = datetime.utcfromtimestamp(self.unix_timestamp)
301297

302298
self.game_length = self.length
303299
self.real_length = utils.Length(seconds=int(self.length.seconds/GAME_SPEED_FACTOR[self.speed]))

0 commit comments

Comments
 (0)