Skip to content

Commit 9ab6210

Browse files
committed
Adds os specific timestamp parsing. Re: #58
1 parent ed15354 commit 9ab6210

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

sc2reader/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from sc2reader.utils import PersonDict, AttributeDict
99

1010
Location = namedtuple('Location',('x','y'))
11-
Details = namedtuple('Details',['players','map','unknown1','unknown2','unknown3','file_time','utc_adjustment','unknown4','unknown5','unknown6','unknown7','unknown8','unknown9','unknown10'])
11+
Details = namedtuple('Details',['players','map','unknown1','unknown2','os','file_time','utc_adjustment','unknown4','unknown5','unknown6','unknown7','unknown8','unknown9','unknown10'])
1212

1313
MapData = namedtuple('MapData',['unknown','gateway','map_hash'])
1414
PlayerData = namedtuple('PlayerData',['name','bnet','race','color','unknown1','unknown2','handicap','unknown3','result'])

sc2reader/resources.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,34 @@ class Replay(Resource):
3838
#: The full version release string as seen on Battle.net
3939
release_string = str()
4040

41+
#: The UTC time the game was ended as represented by the Windows OS
42+
windows_timestamp = int()
43+
44+
#: The UTC time the game was ended as represented by the Unix OS
45+
unix_timestamp = int()
46+
47+
#: The time zone adjustment for the location the replay was recorded at
48+
time_zone= int()
49+
50+
#: Deprecated: See `end_time` below.
51+
date = None
52+
53+
#: A datetime object representing the local time at the end of the game.
54+
end_time = None
55+
56+
#: A datetime object representing the local time at the start of the game
57+
start_time = None
58+
4159
#: The :class:`Length` of the replay as an alternative to :attr:`frames`
4260
length = utils.Length()
4361

4462
#: The effective game speed when the game was played.
4563
speed = str()
4664

65+
#: The operating system the replay was recorded on.
66+
#: Useful for interpretting certain kind of raw data.
67+
os = str()
68+
4769
#: The game type: 1v1, 2v2, 3v3, 4v4, FFA
4870
type = str()
4971

@@ -119,6 +141,8 @@ def __init__(self, replay_file, filename=None, **options):
119141
self.other_people = set()
120142
self.speed = ""
121143
self.type = ""
144+
145+
self.os = str()
122146
self.category = ""
123147
self.is_ladder = False
124148
self.is_private = False
@@ -186,11 +210,21 @@ def load_details(self):
186210

187211
self.map_name = details.map
188212

189-
self.windows_timestamp = details.file_time-details.utc_adjustment
190-
self.unix_timestamp = utils.windows_to_unix(self.windows_timestamp)
191-
self.time_zone = details.utc_adjustment/(10**7*60*60)
213+
if details.os == 0:
214+
self.os = "Windows"
215+
self.windows_timestamp = details.file_time-details.utc_adjustment
216+
self.unix_timestamp = utils.windows_to_unix(self.windows_timestamp)
217+
self.time_zone = details.utc_adjustment/(10**7*60*60)
218+
self.end_time = datetime.utcfromtimestamp(self.unix_timestamp)
219+
elif details.os == 1:
220+
self.os = "Mac"
221+
self.windows_timestamp = details.utc_adjustment
222+
self.unix_timestamp = utils.windows_to_unix(self.windows_timestamp)
223+
self.time_zone = (details.utc_adjustment-details.file_time)/(10**7*60*60)
224+
self.end_time = datetime.utcfromtimestamp(self.unix_timestamp)
225+
else:
226+
raise ValueError("Unknown operating system {} detected.".format(details.os))
192227

193-
self.end_time = datetime.utcfromtimestamp(self.unix_timestamp)
194228
self.game_length = self.length
195229
self.real_length = utils.Length(seconds=int(self.length.seconds/GAME_SPEED_FACTOR[self.speed]))
196230
self.start_time = datetime.utcfromtimestamp(self.unix_timestamp-self.real_length.seconds)

0 commit comments

Comments
 (0)