Skip to content

Commit 8daf03b

Browse files
committed
Fix date to unix for old dates
1 parent 8674a7d commit 8daf03b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "recnetpy"
7-
version = "0.2.54"
7+
version = "0.2.55"
88
authors = [
99
{ name="RecNetBot Development"}
1010
]

src/recnetpy/dataclasses/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def patch_data(self, data: 'AccountResponse') -> None:
7878
self.platforms = bitmask_decode(data['platforms'], PLATFORM_LIST)
7979
self.personal_pronouns = bitmask_decode(data['personalPronouns'], PERSONAL_PRONOUNS_LIST)
8080
self.identity_flags = bitmask_decode(data['identityFlags'], IDENTITY_FLAGS_LIST)
81-
self.created_at = date_to_unix(data['createdAt'])
81+
self.created_at = date_to_unix(data['createdAt'], new=True)
8282

8383
async def get_events(self, take: int = 16, skip: int = 0, force: bool = False) -> List['Event']:
8484
"""

src/recnetpy/misc/date_to_unix.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
from datetime import datetime
2+
from dateutil.parser import isoparse
23

3-
def date_to_unix(date: str) -> int:
4+
def date_to_unix(date: str, new: bool = False) -> int:
45
"""
56
Converts dates from RecNet to an unix timestamp, that can be used to show dates more elegantly.
67
78
Credit to Jegarde for this function.
89
910
@param date: String representation of a date.
11+
@param new: Use the new date type
1012
@return: Unix date represented as an integer.
1113
"""
1214

13-
timestamp = datetime.strptime(date, '%m/%d/%Y %H:%M:%S %p').timestamp()
15+
if new:
16+
timestamp = datetime.strptime(date, '%m/%d/%Y %H:%M:%S %p').timestamp()
17+
else:
18+
timestamp = isoparse(date).timestamp()
1419

1520
return int(timestamp) # Return UNIX timestamp

0 commit comments

Comments
 (0)