File: dt.py

package info (click to toggle)
simplisafe-python 2024.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,268 kB
  • sloc: python: 5,252; sh: 50; makefile: 19
file content (31 lines) | stat: -rw-r--r-- 649 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Define datetime utilities."""
from datetime import datetime

try:
    from datetime import UTC
except ImportError:
    # In place for support of Python 3.10
    from datetime import timezone

    UTC = timezone.utc


def utcnow() -> datetime:
    """Return the current UTC time.

    Returns:
        A ``datetime.datetime`` object.
    """
    return datetime.now(tz=UTC)


def utc_from_timestamp(timestamp: float) -> datetime:
    """Return a UTC time from a timestamp.

    Args:
        timestamp: The epoch to convert.

    Returns:
        A parsed ``datetime.datetime`` object.
    """
    return datetime.fromtimestamp(timestamp, tz=UTC)