-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e854fa1
commit b310993
Showing
5 changed files
with
131 additions
and
337 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,45 @@ | ||
from __future__ import annotations | ||
|
||
import time | ||
from math import floor | ||
|
||
|
||
class Timestamp: | ||
""" | ||
This class represents a Unix timestamp along with the timezone offset from | ||
UTC. | ||
""" | ||
|
||
@staticmethod | ||
def now() -> Timestamp: | ||
""" | ||
:return: A `Timestamp` instance representing the current time. | ||
""" | ||
ts: float = time.time() | ||
return Timestamp( | ||
unix_ts=floor(ts * 1000), | ||
utc_offset=time.localtime(ts).tm_isdst, | ||
) | ||
|
||
def __init__(self, unix_ts: int, utc_offset: int): | ||
""" | ||
Initializes a `Timestamp` instance with the current time. | ||
:param unix_ts: Unix timestamp in milliseconds. | ||
:param utc_offset: The number of seconds the timezone is ahead of | ||
(positive) or behind (negative) UTC. | ||
""" | ||
self._utc_offset: int = utc_offset | ||
self._unix_ts: int = unix_ts | ||
|
||
def get_unix_ts(self) -> int: | ||
""" | ||
:return: The Unix timestamp (milliseconds since the Unix epoch). | ||
""" | ||
return self._unix_ts | ||
|
||
def get_utc_offset(self) -> int: | ||
""" | ||
:return: The number of seconds the timezone is ahead of (positive) or behind (negative) UTC. | ||
""" | ||
return self._utc_offset |
Oops, something went wrong.