File: time.py

package info (click to toggle)
python-falcon 4.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 33,608; javascript: 92; sh: 50; makefile: 50
file content (74 lines) | stat: -rw-r--r-- 1,834 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Time and date utilities.

This module provides utility functions and classes for dealing with
times and dates. These functions are hoisted into the `falcon` module
for convenience::

    import falcon

    tz = falcon.TimezoneGMT()
"""

from __future__ import annotations

import datetime
from typing import Optional

from .deprecation import deprecated

__all__ = ('TimezoneGMT',)


class TimezoneGMT(datetime.tzinfo):
    """GMT timezone class implementing the :class:`datetime.tzinfo` interface.

    .. deprecated:: 4.0
        :class:`TimezoneGMT` is deprecated, use :attr:`datetime.timezone.utc`
        instead. (This class will be removed in Falcon 5.0.)
    """

    GMT_ZERO = datetime.timedelta(hours=0)

    @deprecated(
        'TimezoneGMT is deprecated, use datetime.timezone.utc instead. '
        '(TimezoneGMT will be removed in Falcon 5.0.)'
    )
    def __init__(self) -> None:
        super().__init__()

    def utcoffset(self, dt: Optional[datetime.datetime]) -> datetime.timedelta:
        """Get the offset from UTC.

        Args:
            dt(datetime.datetime): Ignored

        Returns:
            datetime.timedelta: GMT offset, which is equivalent to UTC and
            so is always 0.
        """

        return self.GMT_ZERO

    def tzname(self, dt: Optional[datetime.datetime]) -> str:
        """Get the name of this timezone.

        Args:
            dt(datetime.datetime): Ignored

        Returns:
            str: "GMT"
        """

        return 'GMT'

    def dst(self, dt: Optional[datetime.datetime]) -> datetime.timedelta:
        """Return the daylight saving time (DST) adjustment.

        Args:
            dt(datetime.datetime): Ignored

        Returns:
            datetime.timedelta: DST adjustment for GMT, which is always 0.
        """

        return self.GMT_ZERO