Convert timezone-aware `datetime` to POSIX timestamp and return seconds since UNIX epoch. Note: similar to `datetime.timestamp()` in Python 3.3+.
(dt: datetime)
| 26 | |
| 27 | |
| 28 | def datetime_to_timestamp(dt: datetime) -> float: |
| 29 | """Convert timezone-aware `datetime` to POSIX timestamp and |
| 30 | return seconds since UNIX epoch. |
| 31 | |
| 32 | Note: similar to `datetime.timestamp()` in Python 3.3+. |
| 33 | """ |
| 34 | |
| 35 | epoch = datetime.fromtimestamp(0, tz=UTC) |
| 36 | return (dt - epoch).total_seconds() |
| 37 | |
| 38 | |
| 39 | def utcnow() -> datetime: |
no outgoing calls
no test coverage detected