-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
10 changed files
with
101 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def is_unix_timestamp(timestamp: int | float) -> bool: | ||
""" | ||
Check if the provided integer is a valid UNIX timestamp. | ||
UNIX timestamps are typically in the range from 0 to 2**31 - 1, | ||
covering dates from 1970-01-01 to 2038-01-19. | ||
Source: https://www.unixtimestamp.com/ | ||
Args: | ||
timestamp (int): The integer to check. | ||
Returns: | ||
bool: True if the integer is a valid UNIX timestamp, False otherwise. | ||
""" | ||
|
||
MIN_UNIX_TIMESTAMP = 0 # 1 January 1970 | ||
MAX_UNIX_TIMESTAMP = 2**31 - 1 # 19 January 2038 for a 32-bit signed integer | ||
return MIN_UNIX_TIMESTAMP <= timestamp <= MAX_UNIX_TIMESTAMP |
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
from pydantic import BaseModel | ||
|
||
UNIX_TIMESTAMP = int | float | ||
|
||
|
||
class BaseConfig(BaseModel): | ||
""" | ||
|
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
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
Empty file.
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,14 @@ | ||
from firedust._utils.checks import is_unix_timestamp | ||
|
||
|
||
def test_is_unix_timestamp() -> None: | ||
# Test valid unix timestamp | ||
assert is_unix_timestamp(1625097600) is True | ||
assert is_unix_timestamp(1625097600.5) is True | ||
assert is_unix_timestamp(0) is True | ||
|
||
# Before 1970 | ||
assert is_unix_timestamp(-1) is False | ||
|
||
# After 2038 | ||
assert is_unix_timestamp(2**31) is False |