Debian Codegraph @

jedi/third_party/typeshed/stdlib/datetime.pyi

raw symbols SCIP
1 import sys
2 from abc import abstractmethod
3 from time import struct_time
4 from typing import ClassVar, Final, NoReturn, SupportsIndex, final, overload, type_check_only
5 from typing_extensions import CapsuleType, Self, TypeAlias, deprecated, disjoint_base
6
7 if sys.version_info >= (3, 11):
8 __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC")
9 else:
10 __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR")
11
12 MINYEAR: Final = 1
13 MAXYEAR: Final = 9999
14
15 class tzinfo:
16 @abstractmethod
17 def tzname(self, dt: datetime | None, /) -> str | None: ...
18 @abstractmethod
19 def utcoffset(self, dt: datetime | None, /) -> timedelta | None: ...
20 @abstractmethod
21 def dst(self, dt: datetime | None, /) -> timedelta | None: ...
22 def fromutc(self, dt: datetime, /) -> datetime: ...
23
24 # Alias required to avoid name conflicts with date(time).tzinfo.
25 _TzInfo: TypeAlias = tzinfo
26
27 @final
28 class timezone(tzinfo):
29 utc: ClassVar[timezone]
30 min: ClassVar[timezone]
31 max: ClassVar[timezone]
32 def __new__(cls, offset: timedelta, name: str = ...) -> Self: ...
33 def tzname(self, dt: datetime | None, /) -> str: ...
34 def utcoffset(self, dt: datetime | None, /) -> timedelta: ...
35 def dst(self, dt: datetime | None, /) -> None: ...
36 def __hash__(self) -> int: ...
37 def __eq__(self, value: object, /) -> bool: ...
38
39 if sys.version_info >= (3, 11):
40 UTC: timezone
41
42 # This class calls itself datetime.IsoCalendarDate. It's neither
43 # NamedTuple nor structseq.
44 @final
45 @type_check_only
46 class _IsoCalendarDate(tuple[int, int, int]):
47 @property
48 def year(self) -> int: ...
49 @property
50 def week(self) -> int: ...
51 @property
52 def weekday(self) -> int: ...
53
54 @disjoint_base
55 class date:
56 min: ClassVar[date]
57 max: ClassVar[date]
58 resolution: ClassVar[timedelta]
59 def __new__(cls, year: SupportsIndex, month: SupportsIndex, day: SupportsIndex) -> Self: ...
60 @classmethod
61 def fromtimestamp(cls, timestamp: float, /) -> Self: ...
62 @classmethod
63 def today(cls) -> Self: ...
64 @classmethod
65 def fromordinal(cls, n: int, /) -> Self: ...
66 @classmethod
67 def fromisoformat(cls, date_string: str, /) -> Self: ...
68 @classmethod
69 def fromisocalendar(cls, year: int, week: int, day: int) -> Self: ...
70 @property
71 def year(self) -> int: ...
72 @property
73 def month(self) -> int: ...
74 @property
75 def day(self) -> int: ...
76 def ctime(self) -> str: ...
77
78 if sys.version_info >= (3, 14):
79 @classmethod
80 def strptime(cls, date_string: str, format: str, /) -> Self: ...
81
82 # On <3.12, the name of the parameter in the pure-Python implementation
83 # didn't match the name in the C implementation,
84 # meaning it is only *safe* to pass it as a keyword argument on 3.12+
85 if sys.version_info >= (3, 12):
86 def strftime(self, format: str) -> str: ...
87 else:
88 def strftime(self, format: str, /) -> str: ...
89
90 def __format__(self, fmt: str, /) -> str: ...
91 def isoformat(self) -> str: ...
92 def timetuple(self) -> struct_time: ...
93 def toordinal(self) -> int: ...
94 if sys.version_info >= (3, 13):
95 def __replace__(self, /, *, year: SupportsIndex = ..., month: SupportsIndex = ..., day: SupportsIndex = ...) -> Self: ...
96
97 def replace(self, year: SupportsIndex = ..., month: SupportsIndex = ..., day: SupportsIndex = ...) -> Self: ...
98 def __le__(self, value: date, /) -> bool: ...
99 def __lt__(self, value: date, /) -> bool: ...
100 def __ge__(self, value: date, /) -> bool: ...
101 def __gt__(self, value: date, /) -> bool: ...
102 def __eq__(self, value: object, /) -> bool: ...
103 def __add__(self, value: timedelta, /) -> Self: ...
104 def __radd__(self, value: timedelta, /) -> Self: ...
105 @overload
106 def __sub__(self, value: datetime, /) -> NoReturn: ...
107 @overload
108 def __sub__(self, value: Self, /) -> timedelta: ...
109 @overload
110 def __sub__(self, value: timedelta, /) -> Self: ...
111 def __hash__(self) -> int: ...
112 def weekday(self) -> int: ...
113 def isoweekday(self) -> int: ...
114 def isocalendar(self) -> _IsoCalendarDate: ...
115
116 @disjoint_base
117 class time:
118 min: ClassVar[time]
119 max: ClassVar[time]
120 resolution: ClassVar[timedelta]
121 def __new__(
122 cls,
123 hour: SupportsIndex = 0,
124 minute: SupportsIndex = 0,
125 second: SupportsIndex = 0,
126 microsecond: SupportsIndex = 0,
127 tzinfo: _TzInfo | None = None,
128 *,
129 fold: int = 0,
130 ) -> Self: ...
131 @property
132 def hour(self) -> int: ...
133 @property
134 def minute(self) -> int: ...
135 @property
136 def second(self) -> int: ...
137 @property
138 def microsecond(self) -> int: ...
139 @property
140 def tzinfo(self) -> _TzInfo | None: ...
141 @property
142 def fold(self) -> int: ...
143 def __le__(self, value: time, /) -> bool: ...
144 def __lt__(self, value: time, /) -> bool: ...
145 def __ge__(self, value: time, /) -> bool: ...
146 def __gt__(self, value: time, /) -> bool: ...
147 def __eq__(self, value: object, /) -> bool: ...
148 def __hash__(self) -> int: ...
149 def isoformat(self, timespec: str = "auto") -> str: ...
150 @classmethod
151 def fromisoformat(cls, time_string: str, /) -> Self: ...
152
153 if sys.version_info >= (3, 14):
154 @classmethod
155 def strptime(cls, date_string: str, format: str, /) -> Self: ...
156
157 # On <3.12, the name of the parameter in the pure-Python implementation
158 # didn't match the name in the C implementation,
159 # meaning it is only *safe* to pass it as a keyword argument on 3.12+
160 if sys.version_info >= (3, 12):
161 def strftime(self, format: str) -> str: ...
162 else:
163 def strftime(self, format: str, /) -> str: ...
164
165 def __format__(self, fmt: str, /) -> str: ...
166 def utcoffset(self) -> timedelta | None: ...
167 def tzname(self) -> str | None: ...
168 def dst(self) -> timedelta | None: ...
169 if sys.version_info >= (3, 13):
170 def __replace__(
171 self,
172 /,
173 *,
174 hour: SupportsIndex = ...,
175 minute: SupportsIndex = ...,
176 second: SupportsIndex = ...,
177 microsecond: SupportsIndex = ...,
178 tzinfo: _TzInfo | None = ...,
179 fold: int = ...,
180 ) -> Self: ...
181
182 def replace(
183 self,
184 hour: SupportsIndex = ...,
185 minute: SupportsIndex = ...,
186 second: SupportsIndex = ...,
187 microsecond: SupportsIndex = ...,
188 tzinfo: _TzInfo | None = ...,
189 *,
190 fold: int = ...,
191 ) -> Self: ...
192
193 _Date: TypeAlias = date
194 _Time: TypeAlias = time
195
196 @disjoint_base
197 class timedelta:
198 min: ClassVar[timedelta]
199 max: ClassVar[timedelta]
200 resolution: ClassVar[timedelta]
201 def __new__(
202 cls,
203 days: float = 0,
204 seconds: float = 0,
205 microseconds: float = 0,
206 milliseconds: float = 0,
207 minutes: float = 0,
208 hours: float = 0,
209 weeks: float = 0,
210 ) -> Self: ...
211 @property
212 def days(self) -> int: ...
213 @property
214 def seconds(self) -> int: ...
215 @property
216 def microseconds(self) -> int: ...
217 def total_seconds(self) -> float: ...
218 def __add__(self, value: timedelta, /) -> timedelta: ...
219 def __radd__(self, value: timedelta, /) -> timedelta: ...
220 def __sub__(self, value: timedelta, /) -> timedelta: ...
221 def __rsub__(self, value: timedelta, /) -> timedelta: ...
222 def __neg__(self) -> timedelta: ...
223 def __pos__(self) -> timedelta: ...
224 def __abs__(self) -> timedelta: ...
225 def __mul__(self, value: float, /) -> timedelta: ...
226 def __rmul__(self, value: float, /) -> timedelta: ...
227 @overload
228 def __floordiv__(self, value: timedelta, /) -> int: ...
229 @overload
230 def __floordiv__(self, value: int, /) -> timedelta: ...
231 @overload
232 def __truediv__(self, value: timedelta, /) -> float: ...
233 @overload
234 def __truediv__(self, value: float, /) -> timedelta: ...
235 def __mod__(self, value: timedelta, /) -> timedelta: ...
236 def __divmod__(self, value: timedelta, /) -> tuple[int, timedelta]: ...
237 def __le__(self, value: timedelta, /) -> bool: ...
238 def __lt__(self, value: timedelta, /) -> bool: ...
239 def __ge__(self, value: timedelta, /) -> bool: ...
240 def __gt__(self, value: timedelta, /) -> bool: ...
241 def __eq__(self, value: object, /) -> bool: ...
242 def __bool__(self) -> bool: ...
243 def __hash__(self) -> int: ...
244
245 @disjoint_base
246 class datetime(date):
247 min: ClassVar[datetime]
248 max: ClassVar[datetime]
249 def __new__(
250 cls,
251 year: SupportsIndex,
252 month: SupportsIndex,
253 day: SupportsIndex,
254 hour: SupportsIndex = 0,
255 minute: SupportsIndex = 0,
256 second: SupportsIndex = 0,
257 microsecond: SupportsIndex = 0,
258 tzinfo: _TzInfo | None = None,
259 *,
260 fold: int = 0,
261 ) -> Self: ...
262 @property
263 def hour(self) -> int: ...
264 @property
265 def minute(self) -> int: ...
266 @property
267 def second(self) -> int: ...
268 @property
269 def microsecond(self) -> int: ...
270 @property
271 def tzinfo(self) -> _TzInfo | None: ...
272 @property
273 def fold(self) -> int: ...
274 # On <3.12, the name of the first parameter in the pure-Python implementation
275 # didn't match the name in the C implementation,
276 # meaning it is only *safe* to pass it as a keyword argument on 3.12+
277 if sys.version_info >= (3, 12):
278 @classmethod
279 def fromtimestamp(cls, timestamp: float, tz: _TzInfo | None = None) -> Self: ...
280 else:
281 @classmethod
282 def fromtimestamp(cls, timestamp: float, /, tz: _TzInfo | None = None) -> Self: ...
283
284 @classmethod
285 @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .fromtimestamp(datetime.timezone.utc)")
286 def utcfromtimestamp(cls, t: float, /) -> Self: ...
287 @classmethod
288 def now(cls, tz: _TzInfo | None = None) -> Self: ...
289 @classmethod
290 @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.timezone.utc)")
291 def utcnow(cls) -> Self: ...
292 @classmethod
293 def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo | None = ...) -> Self: ...
294 def timestamp(self) -> float: ...
295 def utctimetuple(self) -> struct_time: ...
296 def date(self) -> _Date: ...
297 def time(self) -> _Time: ...
298 def timetz(self) -> _Time: ...
299 if sys.version_info >= (3, 13):
300 def __replace__(
301 self,
302 /,
303 *,
304 year: SupportsIndex = ...,
305 month: SupportsIndex = ...,
306 day: SupportsIndex = ...,
307 hour: SupportsIndex = ...,
308 minute: SupportsIndex = ...,
309 second: SupportsIndex = ...,
310 microsecond: SupportsIndex = ...,
311 tzinfo: _TzInfo | None = ...,
312 fold: int = ...,
313 ) -> Self: ...
314
315 def replace(
316 self,
317 year: SupportsIndex = ...,
318 month: SupportsIndex = ...,
319 day: SupportsIndex = ...,
320 hour: SupportsIndex = ...,
321 minute: SupportsIndex = ...,
322 second: SupportsIndex = ...,
323 microsecond: SupportsIndex = ...,
324 tzinfo: _TzInfo | None = ...,
325 *,
326 fold: int = ...,
327 ) -> Self: ...
328 def astimezone(self, tz: _TzInfo | None = None) -> Self: ...
329 def isoformat(self, sep: str = "T", timespec: str = "auto") -> str: ...
330 @classmethod
331 def strptime(cls, date_string: str, format: str, /) -> Self: ...
332 def utcoffset(self) -> timedelta | None: ...
333 def tzname(self) -> str | None: ...
334 def dst(self) -> timedelta | None: ...
335 def __le__(self, value: datetime, /) -> bool: ... # type: ignore[override]
336 def __lt__(self, value: datetime, /) -> bool: ... # type: ignore[override]
337 def __ge__(self, value: datetime, /) -> bool: ... # type: ignore[override]
338 def __gt__(self, value: datetime, /) -> bool: ... # type: ignore[override]
339 def __eq__(self, value: object, /) -> bool: ...
340 def __hash__(self) -> int: ...
341 @overload # type: ignore[override]
342 def __sub__(self, value: Self, /) -> timedelta: ...
343 @overload
344 def __sub__(self, value: timedelta, /) -> Self: ...
345
346 datetime_CAPI: CapsuleType