Lines Matching refs:self

686         self = object.__new__(cls)
687 self._days = d
688 self._seconds = s
689 self._microseconds = us
690 self._hashcode = -1
691 return self
693 def __repr__(self):
695 if self._days:
696 args.append("days=%d" % self._days)
697 if self._seconds:
698 args.append("seconds=%d" % self._seconds)
699 if self._microseconds:
700 args.append("microseconds=%d" % self._microseconds)
703 return "%s.%s(%s)" % (self.__class__.__module__,
704 self.__class__.__qualname__,
707 def __str__(self):
708 mm, ss = divmod(self._seconds, 60)
711 if self._days:
714 s = ("%d day%s, " % plural(self._days)) + s
715 if self._microseconds:
716 s = s + ".%06d" % self._microseconds
719 def total_seconds(self):
721 return ((self.days * 86400 + self.seconds) * 10**6 +
722 self.microseconds) / 10**6
726 def days(self):
728 return self._days
731 def seconds(self):
733 return self._seconds
736 def microseconds(self):
738 return self._microseconds
740 def __add__(self, other):
744 return timedelta(self._days + other._days,
745 self._seconds + other._seconds,
746 self._microseconds + other._microseconds)
751 def __sub__(self, other):
755 return timedelta(self._days - other._days,
756 self._seconds - other._seconds,
757 self._microseconds - other._microseconds)
760 def __rsub__(self, other):
762 return -self + other
765 def __neg__(self):
768 return timedelta(-self._days,
769 -self._seconds,
770 -self._microseconds)
772 def __pos__(self):
773 return self
775 def __abs__(self):
776 if self._days < 0:
777 return -self
779 return self
781 def __mul__(self, other):
785 return timedelta(self._days * other,
786 self._seconds * other,
787 self._microseconds * other)
789 usec = self._to_microseconds()
796 def _to_microseconds(self):
797 return ((self._days * (24*3600) + self._seconds) * 1000000 +
798 self._microseconds)
800 def __floordiv__(self, other):
803 usec = self._to_microseconds()
809 def __truediv__(self, other):
812 usec = self._to_microseconds()
821 def __mod__(self, other):
823 r = self._to_microseconds() % other._to_microseconds()
827 def __divmod__(self, other):
829 q, r = divmod(self._to_microseconds(),
836 def __eq__(self, other):
838 return self._cmp(other) == 0
842 def __le__(self, other):
844 return self._cmp(other) <= 0
848 def __lt__(self, other):
850 return self._cmp(other) < 0
854 def __ge__(self, other):
856 return self._cmp(other) >= 0
860 def __gt__(self, other):
862 return self._cmp(other) > 0
866 def _cmp(self, other):
868 return _cmp(self._getstate(), other._getstate())
870 def __hash__(self):
871 if self._hashcode == -1:
872 self._hashcode = hash(self._getstate())
873 return self._hashcode
875 def __bool__(self):
876 return (self._days != 0 or
877 self._seconds != 0 or
878 self._microseconds != 0)
882 def _getstate(self):
883 return (self._days, self._seconds, self._microseconds)
885 def __reduce__(self):
886 return (self.__class__, self._getstate())
943 self = object.__new__(cls)
944 self.__setstate(year)
945 self._hashcode = -1
946 return self
948 self = object.__new__(cls)
949 self._year = year
950 self._month = month
951 self._day = day
952 self._hashcode = -1
953 return self
1002 def __repr__(self):
1013 return "%s.%s(%d, %d, %d)" % (self.__class__.__module__,
1014 self.__class__.__qualname__,
1015 self._year,
1016 self._month,
1017 self._day)
1024 def ctime(self):
1026 weekday = self.toordinal() % 7 or 7
1029 _MONTHNAMES[self._month],
1030 self._day, self._year)
1032 def strftime(self, fmt):
1038 return _wrap_strftime(self, fmt, self.timetuple())
1040 def __format__(self, fmt):
1044 return self.strftime(fmt)
1045 return str(self)
1047 def isoformat(self):
1056 return "%04d-%02d-%02d" % (self._year, self._month, self._day)
1062 def year(self):
1064 return self._year
1067 def month(self):
1069 return self._month
1072 def day(self):
1074 return self._day
1079 def timetuple(self):
1081 return _build_struct_time(self._year, self._month, self._day,
1084 def toordinal(self):
1090 return _ymd2ord(self._year, self._month, self._day)
1092 def replace(self, year=None, month=None, day=None):
1095 year = self._year
1097 month = self._month
1099 day = self._day
1100 return type(self)(year, month, day)
1104 def __eq__(self, other):
1106 return self._cmp(other) == 0
1109 def __le__(self, other):
1111 return self._cmp(other) <= 0
1114 def __lt__(self, other):
1116 return self._cmp(other) < 0
1119 def __ge__(self, other):
1121 return self._cmp(other) >= 0
1124 def __gt__(self, other):
1126 return self._cmp(other) > 0
1129 def _cmp(self, other):
1131 y, m, d = self._year, self._month, self._day
1135 def __hash__(self):
1137 if self._hashcode == -1:
1138 self._hashcode = hash(self._getstate())
1139 return self._hashcode
1143 def __add__(self, other):
1146 o = self.toordinal() + other.days
1148 return type(self).fromordinal(o)
1154 def __sub__(self, other):
1157 return self + timedelta(-other.days)
1159 days1 = self.toordinal()
1164 def weekday(self):
1166 return (self.toordinal() + 6) % 7
1170 def isoweekday(self):
1173 return self.toordinal() % 7 or 7
1175 def isocalendar(self):
1188 year = self._year
1190 today = _ymd2ord(self._year, self._month, self._day)
1205 def _getstate(self):
1206 yhi, ylo = divmod(self._year, 256)
1207 return bytes([yhi, ylo, self._month, self._day]),
1209 def __setstate(self, string):
1210 yhi, ylo, self._month, self._day = string
1211 self._year = yhi * 256 + ylo
1213 def __reduce__(self):
1214 return (self.__class__, self._getstate())
1230 def tzname(self, dt):
1234 def utcoffset(self, dt):
1238 def dst(self, dt):
1246 def fromutc(self, dt):
1251 if dt.tzinfo is not self:
1252 raise ValueError("dt.tzinfo is not self")
1275 def __reduce__(self):
1276 getinitargs = getattr(self, "__getinitargs__", None)
1281 return (self.__class__, args, self.__getstate__())
1290 def year(self):
1291 return self[0]
1294 def week(self):
1295 return self[1]
1298 def weekday(self):
1299 return self[2]
1301 def __reduce__(self):
1304 return (tuple, (tuple(self),))
1306 def __repr__(self):
1307 return (f'{self.__class__.__name__}'
1308 f'(year={self[0]}, week={self[1]}, weekday={self[2]})')
1362 self = object.__new__(cls)
1363 self.__setstate(hour, minute or None)
1364 self._hashcode = -1
1365 return self
1369 self = object.__new__(cls)
1370 self._hour = hour
1371 self._minute = minute
1372 self._second = second
1373 self._microsecond = microsecond
1374 self._tzinfo = tzinfo
1375 self._hashcode = -1
1376 self._fold = fold
1377 return self
1381 def hour(self):
1383 return self._hour
1386 def minute(self):
1388 return self._minute
1391 def second(self):
1393 return self._second
1396 def microsecond(self):
1398 return self._microsecond
1401 def tzinfo(self):
1403 return self._tzinfo
1406 def fold(self):
1407 return self._fold
1413 def __eq__(self, other):
1415 return self._cmp(other, allow_mixed=True) == 0
1419 def __le__(self, other):
1421 return self._cmp(other) <= 0
1425 def __lt__(self, other):
1427 return self._cmp(other) < 0
1431 def __ge__(self, other):
1433 return self._cmp(other) >= 0
1437 def __gt__(self, other):
1439 return self._cmp(other) > 0
1443 def _cmp(self, other, allow_mixed=False):
1445 mytz = self._tzinfo
1452 myoff = self.utcoffset()
1457 return _cmp((self._hour, self._minute, self._second,
1458 self._microsecond),
1466 myhhmm = self._hour * 60 + self._minute - myoff//timedelta(minutes=1)
1468 return _cmp((myhhmm, self._second, self._microsecond),
1471 def __hash__(self):
1473 if self._hashcode == -1:
1474 if self.fold:
1475 t = self.replace(fold=0)
1477 t = self
1480 self._hashcode = hash(t._getstate()[0])
1482 h, m = divmod(timedelta(hours=self.hour, minutes=self.minute) - tzoff,
1487 self._hashcode = hash(time(h, m, self.second, self.microsecond))
1489 self._hashcode = hash((h, m, self.second, self.microsecond))
1490 return self._hashcode
1494 def _tzstr(self):
1496 off = self.utcoffset()
1499 def __repr__(self):
1501 if self._microsecond != 0:
1502 s = ", %d, %d" % (self._second, self._microsecond)
1503 elif self._second != 0:
1504 s = ", %d" % self._second
1507 s= "%s.%s(%d, %d%s)" % (self.__class__.__module__,
1508 self.__class__.__qualname__,
1509 self._hour, self._minute, s)
1510 if self._tzinfo is not None:
1512 s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")"
1513 if self._fold:
1518 def isoformat(self, timespec='auto'):
1522 part is omitted if self.microsecond == 0.
1528 s = _format_time(self._hour, self._minute, self._second,
1529 self._microsecond, timespec)
1530 tz = self._tzstr()
1554 def strftime(self, fmt):
1561 self._hour, self._minute, self._second,
1563 return _wrap_strftime(self, fmt, timetuple)
1565 def __format__(self, fmt):
1569 return self.strftime(fmt)
1570 return str(self)
1574 def utcoffset(self):
1577 if self._tzinfo is None:
1579 offset = self._tzinfo.utcoffset(None)
1583 def tzname(self):
1590 if self._tzinfo is None:
1592 name = self._tzinfo.tzname(None)
1596 def dst(self):
1605 if self._tzinfo is None:
1607 offset = self._tzinfo.dst(None)
1611 def replace(self, hour=None, minute=None, second=None, microsecond=None,
1615 hour = self.hour
1617 minute = self.minute
1619 second = self.second
1621 microsecond = self.microsecond
1623 tzinfo = self.tzinfo
1625 fold = self._fold
1626 return type(self)(hour, minute, second, microsecond, tzinfo, fold=fold)
1630 def _getstate(self, protocol=3):
1631 us2, us3 = divmod(self._microsecond, 256)
1633 h = self._hour
1634 if self._fold and protocol > 3:
1636 basestate = bytes([h, self._minute, self._second,
1638 if self._tzinfo is None:
1641 return (basestate, self._tzinfo)
1643 def __setstate(self, string, tzinfo):
1646 h, self._minute, self._second, us1, us2, us3 = string
1648 self._fold = 1
1649 self._hour = h - 128
1651 self._fold = 0
1652 self._hour = h
1653 self._microsecond = (((us1 << 8) | us2) << 8) | us3
1654 self._tzinfo = tzinfo
1656 def __reduce_ex__(self, protocol):
1657 return (self.__class__, self._getstate(protocol))
1659 def __reduce__(self):
1660 return self.__reduce_ex__(2)
1691 self = object.__new__(cls)
1692 self.__setstate(year, month)
1693 self._hashcode = -1
1694 return self
1699 self = object.__new__(cls)
1700 self._year = year
1701 self._month = month
1702 self._day = day
1703 self._hour = hour
1704 self._minute = minute
1705 self._second = second
1706 self._microsecond = microsecond
1707 self._tzinfo = tzinfo
1708 self._hashcode = -1
1709 self._fold = fold
1710 return self
1714 def hour(self):
1716 return self._hour
1719 def minute(self):
1721 return self._minute
1724 def second(self):
1726 return self._second
1729 def microsecond(self):
1731 return self._microsecond
1734 def tzinfo(self):
1736 return self._tzinfo
1739 def fold(self):
1740 return self._fold
1857 def timetuple(self):
1859 dst = self.dst()
1866 return _build_struct_time(self.year, self.month, self.day,
1867 self.hour, self.minute, self.second,
1870 def _mktime(self):
1874 t = (self - epoch) // timedelta(0, 1)
1887 u2 = u1 + (-max_fold_seconds, max_fold_seconds)[self.fold]
1902 return (max, min)[self.fold](u1, u2)
1905 def timestamp(self):
1907 if self._tzinfo is None:
1908 s = self._mktime()
1909 return s + self.microsecond / 1e6
1911 return (self - _EPOCH).total_seconds()
1913 def utctimetuple(self):
1915 offset = self.utcoffset()
1917 self -= offset
1918 y, m, d = self.year, self.month, self.day
1919 hh, mm, ss = self.hour, self.minute, self.second
1922 def date(self):
1924 return date(self._year, self._month, self._day)
1926 def time(self):
1928 return time(self.hour, self.minute, self.second, self.microsecond, fold=self.fold)
1930 def timetz(self):
1932 return time(self.hour, self.minute, self.second, self.microsecond,
1933 self._tzinfo, fold=self.fold)
1935 def replace(self, year=None, month=None, day=None, hour=None,
1940 year = self.year
1942 month = self.month
1944 day = self.day
1946 hour = self.hour
1948 minute = self.minute
1950 second = self.second
1952 microsecond = self.microsecond
1954 tzinfo = self.tzinfo
1956 fold = self.fold
1957 return type(self)(year, month, day, hour, minute, second,
1960 def _local_timezone(self):
1961 if self.tzinfo is None:
1962 ts = self._mktime()
1964 ts = (self - _EPOCH) // timedelta(seconds=1)
1972 def astimezone(self, tz=None):
1974 tz = self._local_timezone()
1978 mytz = self.tzinfo
1980 mytz = self._local_timezone()
1981 myoffset = mytz.utcoffset(self)
1983 myoffset = mytz.utcoffset(self)
1985 mytz = self.replace(tzinfo=None)._local_timezone()
1986 myoffset = mytz.utcoffset(self)
1989 return self
1991 # Convert self to UTC, and attach the new time zone object.
1992 utc = (self - myoffset).replace(tzinfo=tz)
1999 def ctime(self):
2001 weekday = self.toordinal() % 7 or 7
2004 _MONTHNAMES[self._month],
2005 self._day,
2006 self._hour, self._minute, self._second,
2007 self._year)
2009 def isoformat(self, sep='T', timespec='auto'):
2013 By default, the fractional part is omitted if self.microsecond == 0.
2015 If self.tzinfo is not None, the UTC offset is also attached, giving
2025 s = ("%04d-%02d-%02d%c" % (self._year, self._month, self._day, sep) +
2026 _format_time(self._hour, self._minute, self._second,
2027 self._microsecond, timespec))
2029 off = self.utcoffset()
2036 def __repr__(self):
2038 L = [self._year, self._month, self._day, # These are never zero
2039 self._hour, self._minute, self._second, self._microsecond]
2044 s = "%s.%s(%s)" % (self.__class__.__module__,
2045 self.__class__.__qualname__,
2047 if self._tzinfo is not None:
2049 s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")"
2050 if self._fold:
2055 def __str__(self):
2057 return self.isoformat(sep=' ')
2065 def utcoffset(self):
2068 if self._tzinfo is None:
2070 offset = self._tzinfo.utcoffset(self)
2074 def tzname(self):
2081 if self._tzinfo is None:
2083 name = self._tzinfo.tzname(self)
2087 def dst(self):
2096 if self._tzinfo is None:
2098 offset = self._tzinfo.dst(self)
2104 def __eq__(self, other):
2106 return self._cmp(other, allow_mixed=True) == 0
2112 def __le__(self, other):
2114 return self._cmp(other) <= 0
2118 _cmperror(self, other)
2120 def __lt__(self, other):
2122 return self._cmp(other) < 0
2126 _cmperror(self, other)
2128 def __ge__(self, other):
2130 return self._cmp(other) >= 0
2134 _cmperror(self, other)
2136 def __gt__(self, other):
2138 return self._cmp(other) > 0
2142 _cmperror(self, other)
2144 def _cmp(self, other, allow_mixed=False):
2146 mytz = self._tzinfo
2153 myoff = self.utcoffset()
2157 if myoff != self.replace(fold=not self.fold).utcoffset():
2164 return _cmp((self._year, self._month, self._day,
2165 self._hour, self._minute, self._second,
2166 self._microsecond),
2176 diff = self - other # this will take offsets into account
2181 def __add__(self, other):
2185 delta = timedelta(self.toordinal(),
2186 hours=self._hour,
2187 minutes=self._minute,
2188 seconds=self._second,
2189 microseconds=self._microsecond)
2194 return type(self).combine(date.fromordinal(delta.days),
2197 tzinfo=self._tzinfo))
2202 def __sub__(self, other):
2206 return self + -other
2209 days1 = self.toordinal()
2211 secs1 = self._second + self._minute * 60 + self._hour * 3600
2215 self._microsecond - other._microsecond)
2216 if self._tzinfo is other._tzinfo:
2218 myoff = self.utcoffset()
2226 def __hash__(self):
2227 if self._hashcode == -1:
2228 if self.fold:
2229 t = self.replace(fold=0)
2231 t = self
2234 self._hashcode = hash(t._getstate()[0])
2236 days = _ymd2ord(self.year, self.month, self.day)
2237 seconds = self.hour * 3600 + self.minute * 60 + self.second
2238 self._hashcode = hash(timedelta(days, seconds, self.microsecond) - tzoff)
2239 return self._hashcode
2243 def _getstate(self, protocol=3):
2244 yhi, ylo = divmod(self._year, 256)
2245 us2, us3 = divmod(self._microsecond, 256)
2247 m = self._month
2248 if self._fold and protocol > 3:
2250 basestate = bytes([yhi, ylo, m, self._day,
2251 self._hour, self._minute, self._second,
2253 if self._tzinfo is None:
2256 return (basestate, self._tzinfo)
2258 def __setstate(self, string, tzinfo):
2261 (yhi, ylo, m, self._day, self._hour,
2262 self._minute, self._second, us1, us2, us3) = string
2264 self._fold = 1
2265 self._month = m - 128
2267 self._fold = 0
2268 self._month = m
2269 self._year = yhi * 256 + ylo
2270 self._microsecond = (((us1 << 8) | us2) << 8) | us3
2271 self._tzinfo = tzinfo
2273 def __reduce_ex__(self, protocol):
2274 return (self.__class__, self._getstate(protocol))
2276 def __reduce__(self):
2277 return self.__reduce_ex__(2)
2319 self = tzinfo.__new__(cls)
2320 self._offset = offset
2321 self._name = name
2322 return self
2324 def __getinitargs__(self):
2326 if self._name is None:
2327 return (self._offset,)
2328 return (self._offset, self._name)
2330 def __eq__(self, other):
2332 return self._offset == other._offset
2335 def __hash__(self):
2336 return hash(self._offset)
2338 def __repr__(self):
2348 if self is self.utc:
2350 if self._name is None:
2351 return "%s.%s(%r)" % (self.__class__.__module__,
2352 self.__class__.__qualname__,
2353 self._offset)
2354 return "%s.%s(%r, %r)" % (self.__class__.__module__,
2355 self.__class__.__qualname__,
2356 self._offset, self._name)
2358 def __str__(self):
2359 return self.tzname(None)
2361 def utcoffset(self, dt):
2363 return self._offset
2367 def tzname(self, dt):
2369 if self._name is None:
2370 return self._name_from_offset(self._offset)
2371 return self._name
2375 def dst(self, dt):
2381 def fromutc(self, dt):
2383 if dt.tzinfo is not self:
2385 "is not self")
2386 return dt + self._offset