Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3....
File: datetime.py
[1500] Fix | Delete
def replace(self, hour=None, minute=None, second=None, microsecond=None,
[1501] Fix | Delete
tzinfo=True, *, fold=None):
[1502] Fix | Delete
"""Return a new time with new values for the specified fields."""
[1503] Fix | Delete
if hour is None:
[1504] Fix | Delete
hour = self.hour
[1505] Fix | Delete
if minute is None:
[1506] Fix | Delete
minute = self.minute
[1507] Fix | Delete
if second is None:
[1508] Fix | Delete
second = self.second
[1509] Fix | Delete
if microsecond is None:
[1510] Fix | Delete
microsecond = self.microsecond
[1511] Fix | Delete
if tzinfo is True:
[1512] Fix | Delete
tzinfo = self.tzinfo
[1513] Fix | Delete
if fold is None:
[1514] Fix | Delete
fold = self._fold
[1515] Fix | Delete
return type(self)(hour, minute, second, microsecond, tzinfo, fold=fold)
[1516] Fix | Delete
[1517] Fix | Delete
# Pickle support.
[1518] Fix | Delete
[1519] Fix | Delete
def _getstate(self, protocol=3):
[1520] Fix | Delete
us2, us3 = divmod(self._microsecond, 256)
[1521] Fix | Delete
us1, us2 = divmod(us2, 256)
[1522] Fix | Delete
h = self._hour
[1523] Fix | Delete
if self._fold and protocol > 3:
[1524] Fix | Delete
h += 128
[1525] Fix | Delete
basestate = bytes([h, self._minute, self._second,
[1526] Fix | Delete
us1, us2, us3])
[1527] Fix | Delete
if self._tzinfo is None:
[1528] Fix | Delete
return (basestate,)
[1529] Fix | Delete
else:
[1530] Fix | Delete
return (basestate, self._tzinfo)
[1531] Fix | Delete
[1532] Fix | Delete
def __setstate(self, string, tzinfo):
[1533] Fix | Delete
if tzinfo is not None and not isinstance(tzinfo, _tzinfo_class):
[1534] Fix | Delete
raise TypeError("bad tzinfo state arg")
[1535] Fix | Delete
h, self._minute, self._second, us1, us2, us3 = string
[1536] Fix | Delete
if h > 127:
[1537] Fix | Delete
self._fold = 1
[1538] Fix | Delete
self._hour = h - 128
[1539] Fix | Delete
else:
[1540] Fix | Delete
self._fold = 0
[1541] Fix | Delete
self._hour = h
[1542] Fix | Delete
self._microsecond = (((us1 << 8) | us2) << 8) | us3
[1543] Fix | Delete
self._tzinfo = tzinfo
[1544] Fix | Delete
[1545] Fix | Delete
def __reduce_ex__(self, protocol):
[1546] Fix | Delete
return (self.__class__, self._getstate(protocol))
[1547] Fix | Delete
[1548] Fix | Delete
def __reduce__(self):
[1549] Fix | Delete
return self.__reduce_ex__(2)
[1550] Fix | Delete
[1551] Fix | Delete
_time_class = time # so functions w/ args named "time" can get at the class
[1552] Fix | Delete
[1553] Fix | Delete
time.min = time(0, 0, 0)
[1554] Fix | Delete
time.max = time(23, 59, 59, 999999)
[1555] Fix | Delete
time.resolution = timedelta(microseconds=1)
[1556] Fix | Delete
[1557] Fix | Delete
class datetime(date):
[1558] Fix | Delete
"""datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
[1559] Fix | Delete
[1560] Fix | Delete
The year, month and day arguments are required. tzinfo may be None, or an
[1561] Fix | Delete
instance of a tzinfo subclass. The remaining arguments may be ints.
[1562] Fix | Delete
"""
[1563] Fix | Delete
__slots__ = date.__slots__ + time.__slots__
[1564] Fix | Delete
[1565] Fix | Delete
def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0,
[1566] Fix | Delete
microsecond=0, tzinfo=None, *, fold=0):
[1567] Fix | Delete
if (isinstance(year, (bytes, str)) and len(year) == 10 and
[1568] Fix | Delete
1 <= ord(year[2:3])&0x7F <= 12):
[1569] Fix | Delete
# Pickle support
[1570] Fix | Delete
if isinstance(year, str):
[1571] Fix | Delete
try:
[1572] Fix | Delete
year = bytes(year, 'latin1')
[1573] Fix | Delete
except UnicodeEncodeError:
[1574] Fix | Delete
# More informative error message.
[1575] Fix | Delete
raise ValueError(
[1576] Fix | Delete
"Failed to encode latin1 string when unpickling "
[1577] Fix | Delete
"a datetime object. "
[1578] Fix | Delete
"pickle.load(data, encoding='latin1') is assumed.")
[1579] Fix | Delete
self = object.__new__(cls)
[1580] Fix | Delete
self.__setstate(year, month)
[1581] Fix | Delete
self._hashcode = -1
[1582] Fix | Delete
return self
[1583] Fix | Delete
year, month, day = _check_date_fields(year, month, day)
[1584] Fix | Delete
hour, minute, second, microsecond, fold = _check_time_fields(
[1585] Fix | Delete
hour, minute, second, microsecond, fold)
[1586] Fix | Delete
_check_tzinfo_arg(tzinfo)
[1587] Fix | Delete
self = object.__new__(cls)
[1588] Fix | Delete
self._year = year
[1589] Fix | Delete
self._month = month
[1590] Fix | Delete
self._day = day
[1591] Fix | Delete
self._hour = hour
[1592] Fix | Delete
self._minute = minute
[1593] Fix | Delete
self._second = second
[1594] Fix | Delete
self._microsecond = microsecond
[1595] Fix | Delete
self._tzinfo = tzinfo
[1596] Fix | Delete
self._hashcode = -1
[1597] Fix | Delete
self._fold = fold
[1598] Fix | Delete
return self
[1599] Fix | Delete
[1600] Fix | Delete
# Read-only field accessors
[1601] Fix | Delete
@property
[1602] Fix | Delete
def hour(self):
[1603] Fix | Delete
"""hour (0-23)"""
[1604] Fix | Delete
return self._hour
[1605] Fix | Delete
[1606] Fix | Delete
@property
[1607] Fix | Delete
def minute(self):
[1608] Fix | Delete
"""minute (0-59)"""
[1609] Fix | Delete
return self._minute
[1610] Fix | Delete
[1611] Fix | Delete
@property
[1612] Fix | Delete
def second(self):
[1613] Fix | Delete
"""second (0-59)"""
[1614] Fix | Delete
return self._second
[1615] Fix | Delete
[1616] Fix | Delete
@property
[1617] Fix | Delete
def microsecond(self):
[1618] Fix | Delete
"""microsecond (0-999999)"""
[1619] Fix | Delete
return self._microsecond
[1620] Fix | Delete
[1621] Fix | Delete
@property
[1622] Fix | Delete
def tzinfo(self):
[1623] Fix | Delete
"""timezone info object"""
[1624] Fix | Delete
return self._tzinfo
[1625] Fix | Delete
[1626] Fix | Delete
@property
[1627] Fix | Delete
def fold(self):
[1628] Fix | Delete
return self._fold
[1629] Fix | Delete
[1630] Fix | Delete
@classmethod
[1631] Fix | Delete
def _fromtimestamp(cls, t, utc, tz):
[1632] Fix | Delete
"""Construct a datetime from a POSIX timestamp (like time.time()).
[1633] Fix | Delete
[1634] Fix | Delete
A timezone info object may be passed in as well.
[1635] Fix | Delete
"""
[1636] Fix | Delete
frac, t = _math.modf(t)
[1637] Fix | Delete
us = round(frac * 1e6)
[1638] Fix | Delete
if us >= 1000000:
[1639] Fix | Delete
t += 1
[1640] Fix | Delete
us -= 1000000
[1641] Fix | Delete
elif us < 0:
[1642] Fix | Delete
t -= 1
[1643] Fix | Delete
us += 1000000
[1644] Fix | Delete
[1645] Fix | Delete
converter = _time.gmtime if utc else _time.localtime
[1646] Fix | Delete
y, m, d, hh, mm, ss, weekday, jday, dst = converter(t)
[1647] Fix | Delete
ss = min(ss, 59) # clamp out leap seconds if the platform has them
[1648] Fix | Delete
result = cls(y, m, d, hh, mm, ss, us, tz)
[1649] Fix | Delete
if tz is None:
[1650] Fix | Delete
# As of version 2015f max fold in IANA database is
[1651] Fix | Delete
# 23 hours at 1969-09-30 13:00:00 in Kwajalein.
[1652] Fix | Delete
# Let's probe 24 hours in the past to detect a transition:
[1653] Fix | Delete
max_fold_seconds = 24 * 3600
[1654] Fix | Delete
[1655] Fix | Delete
# On Windows localtime_s throws an OSError for negative values,
[1656] Fix | Delete
# thus we can't perform fold detection for values of time less
[1657] Fix | Delete
# than the max time fold. See comments in _datetimemodule's
[1658] Fix | Delete
# version of this method for more details.
[1659] Fix | Delete
if t < max_fold_seconds and sys.platform.startswith("win"):
[1660] Fix | Delete
return result
[1661] Fix | Delete
[1662] Fix | Delete
y, m, d, hh, mm, ss = converter(t - max_fold_seconds)[:6]
[1663] Fix | Delete
probe1 = cls(y, m, d, hh, mm, ss, us, tz)
[1664] Fix | Delete
trans = result - probe1 - timedelta(0, max_fold_seconds)
[1665] Fix | Delete
if trans.days < 0:
[1666] Fix | Delete
y, m, d, hh, mm, ss = converter(t + trans // timedelta(0, 1))[:6]
[1667] Fix | Delete
probe2 = cls(y, m, d, hh, mm, ss, us, tz)
[1668] Fix | Delete
if probe2 == result:
[1669] Fix | Delete
result._fold = 1
[1670] Fix | Delete
else:
[1671] Fix | Delete
result = tz.fromutc(result)
[1672] Fix | Delete
return result
[1673] Fix | Delete
[1674] Fix | Delete
@classmethod
[1675] Fix | Delete
def fromtimestamp(cls, t, tz=None):
[1676] Fix | Delete
"""Construct a datetime from a POSIX timestamp (like time.time()).
[1677] Fix | Delete
[1678] Fix | Delete
A timezone info object may be passed in as well.
[1679] Fix | Delete
"""
[1680] Fix | Delete
_check_tzinfo_arg(tz)
[1681] Fix | Delete
[1682] Fix | Delete
return cls._fromtimestamp(t, tz is not None, tz)
[1683] Fix | Delete
[1684] Fix | Delete
@classmethod
[1685] Fix | Delete
def utcfromtimestamp(cls, t):
[1686] Fix | Delete
"""Construct a naive UTC datetime from a POSIX timestamp."""
[1687] Fix | Delete
return cls._fromtimestamp(t, True, None)
[1688] Fix | Delete
[1689] Fix | Delete
@classmethod
[1690] Fix | Delete
def now(cls, tz=None):
[1691] Fix | Delete
"Construct a datetime from time.time() and optional time zone info."
[1692] Fix | Delete
t = _time.time()
[1693] Fix | Delete
return cls.fromtimestamp(t, tz)
[1694] Fix | Delete
[1695] Fix | Delete
@classmethod
[1696] Fix | Delete
def utcnow(cls):
[1697] Fix | Delete
"Construct a UTC datetime from time.time()."
[1698] Fix | Delete
t = _time.time()
[1699] Fix | Delete
return cls.utcfromtimestamp(t)
[1700] Fix | Delete
[1701] Fix | Delete
@classmethod
[1702] Fix | Delete
def combine(cls, date, time, tzinfo=True):
[1703] Fix | Delete
"Construct a datetime from a given date and a given time."
[1704] Fix | Delete
if not isinstance(date, _date_class):
[1705] Fix | Delete
raise TypeError("date argument must be a date instance")
[1706] Fix | Delete
if not isinstance(time, _time_class):
[1707] Fix | Delete
raise TypeError("time argument must be a time instance")
[1708] Fix | Delete
if tzinfo is True:
[1709] Fix | Delete
tzinfo = time.tzinfo
[1710] Fix | Delete
return cls(date.year, date.month, date.day,
[1711] Fix | Delete
time.hour, time.minute, time.second, time.microsecond,
[1712] Fix | Delete
tzinfo, fold=time.fold)
[1713] Fix | Delete
[1714] Fix | Delete
@classmethod
[1715] Fix | Delete
def fromisoformat(cls, date_string):
[1716] Fix | Delete
"""Construct a datetime from the output of datetime.isoformat()."""
[1717] Fix | Delete
if not isinstance(date_string, str):
[1718] Fix | Delete
raise TypeError('fromisoformat: argument must be str')
[1719] Fix | Delete
[1720] Fix | Delete
# Split this at the separator
[1721] Fix | Delete
dstr = date_string[0:10]
[1722] Fix | Delete
tstr = date_string[11:]
[1723] Fix | Delete
[1724] Fix | Delete
try:
[1725] Fix | Delete
date_components = _parse_isoformat_date(dstr)
[1726] Fix | Delete
except ValueError:
[1727] Fix | Delete
raise ValueError(f'Invalid isoformat string: {date_string!r}')
[1728] Fix | Delete
[1729] Fix | Delete
if tstr:
[1730] Fix | Delete
try:
[1731] Fix | Delete
time_components = _parse_isoformat_time(tstr)
[1732] Fix | Delete
except ValueError:
[1733] Fix | Delete
raise ValueError(f'Invalid isoformat string: {date_string!r}')
[1734] Fix | Delete
else:
[1735] Fix | Delete
time_components = [0, 0, 0, 0, None]
[1736] Fix | Delete
[1737] Fix | Delete
return cls(*(date_components + time_components))
[1738] Fix | Delete
[1739] Fix | Delete
def timetuple(self):
[1740] Fix | Delete
"Return local time tuple compatible with time.localtime()."
[1741] Fix | Delete
dst = self.dst()
[1742] Fix | Delete
if dst is None:
[1743] Fix | Delete
dst = -1
[1744] Fix | Delete
elif dst:
[1745] Fix | Delete
dst = 1
[1746] Fix | Delete
else:
[1747] Fix | Delete
dst = 0
[1748] Fix | Delete
return _build_struct_time(self.year, self.month, self.day,
[1749] Fix | Delete
self.hour, self.minute, self.second,
[1750] Fix | Delete
dst)
[1751] Fix | Delete
[1752] Fix | Delete
def _mktime(self):
[1753] Fix | Delete
"""Return integer POSIX timestamp."""
[1754] Fix | Delete
epoch = datetime(1970, 1, 1)
[1755] Fix | Delete
max_fold_seconds = 24 * 3600
[1756] Fix | Delete
t = (self - epoch) // timedelta(0, 1)
[1757] Fix | Delete
def local(u):
[1758] Fix | Delete
y, m, d, hh, mm, ss = _time.localtime(u)[:6]
[1759] Fix | Delete
return (datetime(y, m, d, hh, mm, ss) - epoch) // timedelta(0, 1)
[1760] Fix | Delete
[1761] Fix | Delete
# Our goal is to solve t = local(u) for u.
[1762] Fix | Delete
a = local(t) - t
[1763] Fix | Delete
u1 = t - a
[1764] Fix | Delete
t1 = local(u1)
[1765] Fix | Delete
if t1 == t:
[1766] Fix | Delete
# We found one solution, but it may not be the one we need.
[1767] Fix | Delete
# Look for an earlier solution (if `fold` is 0), or a
[1768] Fix | Delete
# later one (if `fold` is 1).
[1769] Fix | Delete
u2 = u1 + (-max_fold_seconds, max_fold_seconds)[self.fold]
[1770] Fix | Delete
b = local(u2) - u2
[1771] Fix | Delete
if a == b:
[1772] Fix | Delete
return u1
[1773] Fix | Delete
else:
[1774] Fix | Delete
b = t1 - u1
[1775] Fix | Delete
assert a != b
[1776] Fix | Delete
u2 = t - b
[1777] Fix | Delete
t2 = local(u2)
[1778] Fix | Delete
if t2 == t:
[1779] Fix | Delete
return u2
[1780] Fix | Delete
if t1 == t:
[1781] Fix | Delete
return u1
[1782] Fix | Delete
# We have found both offsets a and b, but neither t - a nor t - b is
[1783] Fix | Delete
# a solution. This means t is in the gap.
[1784] Fix | Delete
return (max, min)[self.fold](u1, u2)
[1785] Fix | Delete
[1786] Fix | Delete
[1787] Fix | Delete
def timestamp(self):
[1788] Fix | Delete
"Return POSIX timestamp as float"
[1789] Fix | Delete
if self._tzinfo is None:
[1790] Fix | Delete
s = self._mktime()
[1791] Fix | Delete
return s + self.microsecond / 1e6
[1792] Fix | Delete
else:
[1793] Fix | Delete
return (self - _EPOCH).total_seconds()
[1794] Fix | Delete
[1795] Fix | Delete
def utctimetuple(self):
[1796] Fix | Delete
"Return UTC time tuple compatible with time.gmtime()."
[1797] Fix | Delete
offset = self.utcoffset()
[1798] Fix | Delete
if offset:
[1799] Fix | Delete
self -= offset
[1800] Fix | Delete
y, m, d = self.year, self.month, self.day
[1801] Fix | Delete
hh, mm, ss = self.hour, self.minute, self.second
[1802] Fix | Delete
return _build_struct_time(y, m, d, hh, mm, ss, 0)
[1803] Fix | Delete
[1804] Fix | Delete
def date(self):
[1805] Fix | Delete
"Return the date part."
[1806] Fix | Delete
return date(self._year, self._month, self._day)
[1807] Fix | Delete
[1808] Fix | Delete
def time(self):
[1809] Fix | Delete
"Return the time part, with tzinfo None."
[1810] Fix | Delete
return time(self.hour, self.minute, self.second, self.microsecond, fold=self.fold)
[1811] Fix | Delete
[1812] Fix | Delete
def timetz(self):
[1813] Fix | Delete
"Return the time part, with same tzinfo."
[1814] Fix | Delete
return time(self.hour, self.minute, self.second, self.microsecond,
[1815] Fix | Delete
self._tzinfo, fold=self.fold)
[1816] Fix | Delete
[1817] Fix | Delete
def replace(self, year=None, month=None, day=None, hour=None,
[1818] Fix | Delete
minute=None, second=None, microsecond=None, tzinfo=True,
[1819] Fix | Delete
*, fold=None):
[1820] Fix | Delete
"""Return a new datetime with new values for the specified fields."""
[1821] Fix | Delete
if year is None:
[1822] Fix | Delete
year = self.year
[1823] Fix | Delete
if month is None:
[1824] Fix | Delete
month = self.month
[1825] Fix | Delete
if day is None:
[1826] Fix | Delete
day = self.day
[1827] Fix | Delete
if hour is None:
[1828] Fix | Delete
hour = self.hour
[1829] Fix | Delete
if minute is None:
[1830] Fix | Delete
minute = self.minute
[1831] Fix | Delete
if second is None:
[1832] Fix | Delete
second = self.second
[1833] Fix | Delete
if microsecond is None:
[1834] Fix | Delete
microsecond = self.microsecond
[1835] Fix | Delete
if tzinfo is True:
[1836] Fix | Delete
tzinfo = self.tzinfo
[1837] Fix | Delete
if fold is None:
[1838] Fix | Delete
fold = self.fold
[1839] Fix | Delete
return type(self)(year, month, day, hour, minute, second,
[1840] Fix | Delete
microsecond, tzinfo, fold=fold)
[1841] Fix | Delete
[1842] Fix | Delete
def _local_timezone(self):
[1843] Fix | Delete
if self.tzinfo is None:
[1844] Fix | Delete
ts = self._mktime()
[1845] Fix | Delete
else:
[1846] Fix | Delete
ts = (self - _EPOCH) // timedelta(seconds=1)
[1847] Fix | Delete
localtm = _time.localtime(ts)
[1848] Fix | Delete
local = datetime(*localtm[:6])
[1849] Fix | Delete
# Extract TZ data
[1850] Fix | Delete
gmtoff = localtm.tm_gmtoff
[1851] Fix | Delete
zone = localtm.tm_zone
[1852] Fix | Delete
return timezone(timedelta(seconds=gmtoff), zone)
[1853] Fix | Delete
[1854] Fix | Delete
def astimezone(self, tz=None):
[1855] Fix | Delete
if tz is None:
[1856] Fix | Delete
tz = self._local_timezone()
[1857] Fix | Delete
elif not isinstance(tz, tzinfo):
[1858] Fix | Delete
raise TypeError("tz argument must be an instance of tzinfo")
[1859] Fix | Delete
[1860] Fix | Delete
mytz = self.tzinfo
[1861] Fix | Delete
if mytz is None:
[1862] Fix | Delete
mytz = self._local_timezone()
[1863] Fix | Delete
myoffset = mytz.utcoffset(self)
[1864] Fix | Delete
else:
[1865] Fix | Delete
myoffset = mytz.utcoffset(self)
[1866] Fix | Delete
if myoffset is None:
[1867] Fix | Delete
mytz = self.replace(tzinfo=None)._local_timezone()
[1868] Fix | Delete
myoffset = mytz.utcoffset(self)
[1869] Fix | Delete
[1870] Fix | Delete
if tz is mytz:
[1871] Fix | Delete
return self
[1872] Fix | Delete
[1873] Fix | Delete
# Convert self to UTC, and attach the new time zone object.
[1874] Fix | Delete
utc = (self - myoffset).replace(tzinfo=tz)
[1875] Fix | Delete
[1876] Fix | Delete
# Convert from UTC to tz's local time.
[1877] Fix | Delete
return tz.fromutc(utc)
[1878] Fix | Delete
[1879] Fix | Delete
# Ways to produce a string.
[1880] Fix | Delete
[1881] Fix | Delete
def ctime(self):
[1882] Fix | Delete
"Return ctime() style string."
[1883] Fix | Delete
weekday = self.toordinal() % 7 or 7
[1884] Fix | Delete
return "%s %s %2d %02d:%02d:%02d %04d" % (
[1885] Fix | Delete
_DAYNAMES[weekday],
[1886] Fix | Delete
_MONTHNAMES[self._month],
[1887] Fix | Delete
self._day,
[1888] Fix | Delete
self._hour, self._minute, self._second,
[1889] Fix | Delete
self._year)
[1890] Fix | Delete
[1891] Fix | Delete
def isoformat(self, sep='T', timespec='auto'):
[1892] Fix | Delete
"""Return the time formatted according to ISO.
[1893] Fix | Delete
[1894] Fix | Delete
The full format looks like 'YYYY-MM-DD HH:MM:SS.mmmmmm'.
[1895] Fix | Delete
By default, the fractional part is omitted if self.microsecond == 0.
[1896] Fix | Delete
[1897] Fix | Delete
If self.tzinfo is not None, the UTC offset is also attached, giving
[1898] Fix | Delete
giving a full format of 'YYYY-MM-DD HH:MM:SS.mmmmmm+HH:MM'.
[1899] Fix | Delete
[1900] Fix | Delete
Optional argument sep specifies the separator between date and
[1901] Fix | Delete
time, default 'T'.
[1902] Fix | Delete
[1903] Fix | Delete
The optional argument timespec specifies the number of additional
[1904] Fix | Delete
terms of the time to include. Valid options are 'auto', 'hours',
[1905] Fix | Delete
'minutes', 'seconds', 'milliseconds' and 'microseconds'.
[1906] Fix | Delete
"""
[1907] Fix | Delete
s = ("%04d-%02d-%02d%c" % (self._year, self._month, self._day, sep) +
[1908] Fix | Delete
_format_time(self._hour, self._minute, self._second,
[1909] Fix | Delete
self._microsecond, timespec))
[1910] Fix | Delete
[1911] Fix | Delete
off = self.utcoffset()
[1912] Fix | Delete
tz = _format_offset(off)
[1913] Fix | Delete
if tz:
[1914] Fix | Delete
s += tz
[1915] Fix | Delete
[1916] Fix | Delete
return s
[1917] Fix | Delete
[1918] Fix | Delete
def __repr__(self):
[1919] Fix | Delete
"""Convert to formal string, for repr()."""
[1920] Fix | Delete
L = [self._year, self._month, self._day, # These are never zero
[1921] Fix | Delete
self._hour, self._minute, self._second, self._microsecond]
[1922] Fix | Delete
if L[-1] == 0:
[1923] Fix | Delete
del L[-1]
[1924] Fix | Delete
if L[-1] == 0:
[1925] Fix | Delete
del L[-1]
[1926] Fix | Delete
s = "%s.%s(%s)" % (self.__class__.__module__,
[1927] Fix | Delete
self.__class__.__qualname__,
[1928] Fix | Delete
", ".join(map(str, L)))
[1929] Fix | Delete
if self._tzinfo is not None:
[1930] Fix | Delete
assert s[-1:] == ")"
[1931] Fix | Delete
s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")"
[1932] Fix | Delete
if self._fold:
[1933] Fix | Delete
assert s[-1:] == ")"
[1934] Fix | Delete
s = s[:-1] + ", fold=1)"
[1935] Fix | Delete
return s
[1936] Fix | Delete
[1937] Fix | Delete
def __str__(self):
[1938] Fix | Delete
"Convert to string, for str()."
[1939] Fix | Delete
return self.isoformat(sep=' ')
[1940] Fix | Delete
[1941] Fix | Delete
@classmethod
[1942] Fix | Delete
def strptime(cls, date_string, format):
[1943] Fix | Delete
'string, format -> new datetime parsed from a string (like time.strptime()).'
[1944] Fix | Delete
import _strptime
[1945] Fix | Delete
return _strptime._strptime_datetime(cls, date_string, format)
[1946] Fix | Delete
[1947] Fix | Delete
def utcoffset(self):
[1948] Fix | Delete
"""Return the timezone offset as timedelta positive east of UTC (negative west of
[1949] Fix | Delete
UTC)."""
[1950] Fix | Delete
if self._tzinfo is None:
[1951] Fix | Delete
return None
[1952] Fix | Delete
offset = self._tzinfo.utcoffset(self)
[1953] Fix | Delete
_check_utc_offset("utcoffset", offset)
[1954] Fix | Delete
return offset
[1955] Fix | Delete
[1956] Fix | Delete
def tzname(self):
[1957] Fix | Delete
"""Return the timezone name.
[1958] Fix | Delete
[1959] Fix | Delete
Note that the name is 100% informational -- there's no requirement that
[1960] Fix | Delete
it mean anything in particular. For example, "GMT", "UTC", "-500",
[1961] Fix | Delete
"-5:00", "EDT", "US/Eastern", "America/New York" are all valid replies.
[1962] Fix | Delete
"""
[1963] Fix | Delete
if self._tzinfo is None:
[1964] Fix | Delete
return None
[1965] Fix | Delete
name = self._tzinfo.tzname(self)
[1966] Fix | Delete
_check_tzname(name)
[1967] Fix | Delete
return name
[1968] Fix | Delete
[1969] Fix | Delete
def dst(self):
[1970] Fix | Delete
"""Return 0 if DST is not in effect, or the DST offset (as timedelta
[1971] Fix | Delete
positive eastward) if DST is in effect.
[1972] Fix | Delete
[1973] Fix | Delete
This is purely informational; the DST offset has already been added to
[1974] Fix | Delete
the UTC offset returned by utcoffset() if applicable, so there's no
[1975] Fix | Delete
need to consult dst() unless you're interested in displaying the DST
[1976] Fix | Delete
info.
[1977] Fix | Delete
"""
[1978] Fix | Delete
if self._tzinfo is None:
[1979] Fix | Delete
return None
[1980] Fix | Delete
offset = self._tzinfo.dst(self)
[1981] Fix | Delete
_check_utc_offset("dst", offset)
[1982] Fix | Delete
return offset
[1983] Fix | Delete
[1984] Fix | Delete
# Comparisons of datetime objects with other.
[1985] Fix | Delete
[1986] Fix | Delete
def __eq__(self, other):
[1987] Fix | Delete
if isinstance(other, datetime):
[1988] Fix | Delete
return self._cmp(other, allow_mixed=True) == 0
[1989] Fix | Delete
elif not isinstance(other, date):
[1990] Fix | Delete
return NotImplemented
[1991] Fix | Delete
else:
[1992] Fix | Delete
return False
[1993] Fix | Delete
[1994] Fix | Delete
def __le__(self, other):
[1995] Fix | Delete
if isinstance(other, datetime):
[1996] Fix | Delete
return self._cmp(other) <= 0
[1997] Fix | Delete
elif not isinstance(other, date):
[1998] Fix | Delete
return NotImplemented
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function