| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /usr/lib/python3/dist-packages/fs/ |
Upload File : |
"""Time related tools.
"""
from __future__ import print_function, unicode_literals
import typing
from calendar import timegm
from datetime import datetime
try:
from datetime import timezone
except ImportError:
from ._tzcompat import timezone # type: ignore
if typing.TYPE_CHECKING:
from typing import Optional
def datetime_to_epoch(d):
# type: (datetime) -> int
"""Convert datetime to epoch."""
return timegm(d.utctimetuple())
@typing.overload
def epoch_to_datetime(t): # noqa: D103
# type: (None) -> None
pass
@typing.overload
def epoch_to_datetime(t): # noqa: D103
# type: (int) -> datetime
pass
def epoch_to_datetime(t):
# type: (Optional[int]) -> Optional[datetime]
"""Convert epoch time to a UTC datetime."""
if t is None:
return None
return datetime.fromtimestamp(t, tz=timezone.utc)