mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-16 11:12:21 +03:00
- one line boolean condition
- add types
This commit is contained in:
parent
73cbb9cd4a
commit
c74365117e
|
@ -1,7 +1,7 @@
|
||||||
from datetime import datetime, timezone, tzinfo
|
from datetime import datetime, timezone, tzinfo
|
||||||
|
|
||||||
|
|
||||||
def datetime_exists(dt):
|
def datetime_exists(dt: datetime) -> bool:
|
||||||
"""Check if a datetime exists. Taken from: https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html"""
|
"""Check if a datetime exists. Taken from: https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html"""
|
||||||
# There are no non-existent times in UTC, and comparisons between
|
# There are no non-existent times in UTC, and comparisons between
|
||||||
# aware time zones always compare absolute times; if a datetime is
|
# aware time zones always compare absolute times; if a datetime is
|
||||||
|
@ -9,7 +9,7 @@ def datetime_exists(dt):
|
||||||
return dt.astimezone(timezone.utc) == dt
|
return dt.astimezone(timezone.utc) == dt
|
||||||
|
|
||||||
|
|
||||||
def datetime_ambiguous(dt: datetime):
|
def datetime_ambiguous(dt: datetime) -> bool:
|
||||||
"""Check whether a datetime is ambiguous. Taken from: https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html"""
|
"""Check whether a datetime is ambiguous. Taken from: https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html"""
|
||||||
# If a datetime exists and its UTC offset changes in response to
|
# If a datetime exists and its UTC offset changes in response to
|
||||||
# changing `fold`, it is ambiguous in the zone specified.
|
# changing `fold`, it is ambiguous in the zone specified.
|
||||||
|
@ -18,8 +18,6 @@ def datetime_ambiguous(dt: datetime):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def valid_datetime(dt):
|
def valid_datetime(dt: datetime) -> bool:
|
||||||
"""Returns True if the datetime is not ambiguous or imaginary, False otherwise."""
|
"""Returns True if the datetime is not ambiguous or imaginary, False otherwise."""
|
||||||
if isinstance(dt.tzinfo, tzinfo) and not datetime_ambiguous(dt):
|
return isinstance(dt.tzinfo, tzinfo) and not datetime_ambiguous(dt)
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user