diff options
author | 2021-03-26 15:19:25 -0700 | |
---|---|---|
committer | 2021-03-26 15:19:25 -0700 | |
commit | cc3c47463d4317b072810deb622d54dddf9a132c (patch) | |
tree | 5710811250e188fb17215f70214851eda019550a | |
parent | Use correct constant for each type of help session user (diff) |
Switch to datetime.fromtimestamp() to avoid over-compensation
Previously we were using `utcfromtimestamp()` which would compensate
the timestamp when converting to UTC even though the timestamp itself
was in UTC:
>>> datetime.utcnow()
datetime.datetime(2021, 3, 26, 22, 8, 47, 441603)
>>> a = datetime.utcnow().timestamp()
1616821624.207364
>>> a = datetime.utcfromtimestamp(a)
datetime.datetime(2021, 3, 27, 5, 7, 4, 207364)
By switching to `fromtimestamp()` this avoids that behaviour.
-rw-r--r-- | bot/exts/help_channels/_channel.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py index d46969d4f..b1960531d 100644 --- a/bot/exts/help_channels/_channel.py +++ b/bot/exts/help_channels/_channel.py @@ -57,11 +57,11 @@ async def get_closing_time(channel: discord.TextChannel, init_done: bool) -> t.T return msg.created_at + timedelta(minutes=idle_minutes_claimant), "latest_message" # Switch to datetime objects so we can use time deltas - claimant_last_message_time = datetime.utcfromtimestamp(claimant_last_message_time) + claimant_last_message_time = datetime.fromtimestamp(claimant_last_message_time) non_claimant_last_message_time = await _caches.non_claimant_last_message_times.get(channel.id) if non_claimant_last_message_time: - non_claimant_last_message_time = datetime.utcfromtimestamp(non_claimant_last_message_time) + non_claimant_last_message_time = datetime.fromtimestamp(non_claimant_last_message_time) else: # If it's falsey, then it indicates a non-claimant has yet to reply to this session. # Set to min date time so it isn't considered when calculating the closing time. @@ -92,7 +92,7 @@ async def get_in_use_time(channel_id: int) -> t.Optional[timedelta]: claimed_timestamp = await _caches.claim_times.get(channel_id) if claimed_timestamp: - claimed = datetime.utcfromtimestamp(claimed_timestamp) + claimed = datetime.fromtimestamp(claimed_timestamp) return datetime.utcnow() - claimed |