-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(timestamps): generate timestamps correctly and remove the depreca…
…ted pytz
- Loading branch information
1 parent
4126c4c
commit 1e0b397
Showing
4 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import datetime | ||
|
||
from bot.shared.tools import ( | ||
fetch_timestamp, | ||
fetch_timestamp_from_time_obj, | ||
timestamp_fmt, | ||
timestamp_fmt_short, | ||
) | ||
|
||
|
||
class TestTimeHelpers: | ||
def test_fetch_timestamp_generates_the_correct_timestamp(self): | ||
utc_timestamp = fetch_timestamp(timezone="UTC") | ||
melbourne_timestamp = fetch_timestamp(timezone="Australia/Melbourne") | ||
|
||
parsed_melbourne = datetime.datetime.strptime( | ||
utc_timestamp[:13], "%Y-%m-%dT%H" | ||
) | ||
parsed_utc = datetime.datetime.strptime( | ||
melbourne_timestamp[:13], "%Y-%m-%dT%H" | ||
) | ||
|
||
assert ( | ||
parsed_melbourne.hour != parsed_utc.hour | ||
), "The timestamps should have different hours when using differnt timezones" | ||
|
||
def test_fetch_timestamp_short(self): | ||
short_timestamp = fetch_timestamp(short=True, timezone="UTC") | ||
|
||
assert datetime.datetime.strptime( | ||
short_timestamp, timestamp_fmt_short | ||
), "Should be able to reparse the short format" | ||
|
||
def test_fetch_timestamp_from_time_obj(self): | ||
now = datetime.datetime.now(datetime.UTC) | ||
|
||
now_as_est = fetch_timestamp_from_time_obj( | ||
now, timezone="Australia/Melbourne" | ||
) | ||
|
||
now_as_melbourne_datetime = datetime.datetime.strptime( | ||
now_as_est, timestamp_fmt | ||
) | ||
assert now_as_melbourne_datetime.hour != now.hour |