MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / __init__

Method __init__

bson/timestamp.py:38–70  ·  view source on GitHub ↗

Create a new :class:`Timestamp`. This class is only for use with the MongoDB opLog. If you need to store a regular timestamp, please use a :class:`~datetime.datetime`. Raises :class:`TypeError` if `time` is not an instance of :class: `int` or :class:`~dateti

(self, time: Union[datetime.datetime, int], inc: int)

Source from the content-addressed store, hash-verified

36 _type_marker = 17
37
38 def __init__(self, time: Union[datetime.datetime, int], inc: int) -> None:
39 """Create a new :class:`Timestamp`.
40
41 This class is only for use with the MongoDB opLog. If you need
42 to store a regular timestamp, please use a
43 :class:`~datetime.datetime`.
44
45 Raises :class:`TypeError` if `time` is not an instance of
46 :class: `int` or :class:`~datetime.datetime`, or `inc` is not
47 an instance of :class:`int`. Raises :class:`ValueError` if
48 `time` or `inc` is not in [0, 2**32).
49
50 :param time: time in seconds since epoch UTC, or a naive UTC
51 :class:`~datetime.datetime`, or an aware
52 :class:`~datetime.datetime`
53 :param inc: the incrementing counter
54 """
55 if isinstance(time, datetime.datetime):
56 offset = time.utcoffset()
57 if offset is not None:
58 time = time - offset
59 time = int(calendar.timegm(time.timetuple()))
60 if not isinstance(time, int):
61 raise TypeError(f"time must be an instance of int, not {type(time)}")
62 if not isinstance(inc, int):
63 raise TypeError(f"inc must be an instance of int, not {type(inc)}")
64 if not 0 <= time < UPPERBOUND:
65 raise ValueError("time must be contained in [0, 2**32)")
66 if not 0 <= inc < UPPERBOUND:
67 raise ValueError("inc must be contained in [0, 2**32)")
68
69 self.__time = time
70 self.__inc = inc
71
72 @property
73 def time(self) -> int:

Callers

nothing calls this directly

Calls 1

utcoffsetMethod · 0.45

Tested by

no test coverage detected