Skip to content

Commit

Permalink
Unify to UTC timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
joweich committed Dec 3, 2023
1 parent 030c7b3 commit 5c71025
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions chatminer/chatparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _parse_message(self, mess: Dict[str, Any]):
self._logger.warning("Skipped message with unknown format: %s", mess)
return None

time = dt.datetime.fromtimestamp(mess["timestamp_ms"] / 1000)
time = dt.datetime.utcfromtimestamp(mess["timestamp_ms"] / 1000)
author = mess["sender_name"].encode("latin-1").decode("utf-8")
body = body.encode("latin-1").decode("utf-8")
return ParsedMessage(time, author, body)
Expand Down Expand Up @@ -263,7 +263,7 @@ def _parse_message(self, mess: Dict[str, Any]):
self._logger.warning("Skipped message with unknown format: %s", mess)
return None

time = dt.datetime.fromtimestamp(mess["timestamp_ms"] / 1000)
time = dt.datetime.utcfromtimestamp(mess["timestamp_ms"] / 1000)
author = mess["sender_name"].encode("latin-1").decode("utf-8")
body = body.encode("latin-1").decode("utf-8")
return ParsedMessage(time, author, body)
Expand Down Expand Up @@ -313,7 +313,7 @@ def _parse_message(self, mess: Dict[str, Any]):
else:
raise ValueError(f"Unable to parse type {type(mess['text'])} in {mess}")

time = dt.datetime.fromtimestamp(int(mess["date_unixtime"]))
time = dt.datetime.utcfromtimestamp(int(mess["date_unixtime"]))
author = mess["from"]
return ParsedMessage(time, author, body)
return None
Expand Down
4 changes: 2 additions & 2 deletions test/instagram/target.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[
{
"timestamp": "2020-01-17T21:49:00",
"timestamp": "2020-01-17T20:49:00",
"author": "John Doe",
"message": "Hello Jane!"
},
{
"timestamp": "2019-12-24T12:23:00",
"timestamp": "2019-12-24T11:23:00",
"author": "Jane Doe",
"message": "Hello John!"
}
Expand Down
4 changes: 2 additions & 2 deletions test/telegram/target.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[
{
"timestamp": "2018-12-05T11:39:10",
"timestamp": "2018-12-05T10:39:10",
"author": "Author 1",
"message": "Minimal Message"
},
{
"timestamp": "2018-12-05T11:49:24",
"timestamp": "2018-12-05T10:49:24",
"author": "Author 2",
"message": "Link: https://telegram.org/"
}
Expand Down

0 comments on commit 5c71025

Please sign in to comment.