Skip to content

Commit

Permalink
Merge pull request #13 from blimmo/master
Browse files Browse the repository at this point in the history
Convert timestamp to datetime.datetime object
  • Loading branch information
kszlim authored May 22, 2017
2 parents 1040674 + b064220 commit 45077e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions osrparse/replay.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .enums import GameMode, Mod
import lzma, struct
import lzma, struct, datetime


class ReplayEvent(object):
Expand Down Expand Up @@ -123,7 +123,8 @@ def parse_life_bar_graph(self, replay_data):

def parse_timestamp_and_replay_length(self, replay_data):
format_specifier = "<qi"
(self.timestamp, self.__replay_length) = struct.unpack_from(format_specifier, replay_data, self.offset)
(t, self.__replay_length) = struct.unpack_from(format_specifier, replay_data, self.offset)
self.timestamp = datetime.datetime.min + datetime.timedelta(microseconds=t/10)
self.offset += struct.calcsize(format_specifier)

def parse_play_data(self, replay_data):
Expand Down
4 changes: 2 additions & 2 deletions tests/replay_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unittest
import unittest, datetime
from osrparse.replay import parse_replay, parse_replay_file, ReplayEvent
from osrparse.enums import GameMode, Mod

Expand Down Expand Up @@ -54,7 +54,7 @@ def test_mod_combination(self):

def test_timestamp(self):
for replay in self._replays:
self.assertEqual(replay.timestamp, 634953330940000000, "Timestamp is wrong")
self.assertEqual(replay.timestamp, datetime.datetime(2013, 2, 1, 16, 31, 34), "Timestamp is wrong")

def test_play_data(self):
for replay in self._replays:
Expand Down

0 comments on commit 45077e5

Please sign in to comment.