Lines Matching defs:year

25 # both directions.  Difference:  Dates.py calls January 1 of year 0 day
26 # number 1. The code here calls January 1 of year 1 day number 1. This is
42 def _is_leap(year):
43 "year -> 1 if leap year, else 0."
44 return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
46 def _days_before_year(year):
47 "year -> number of days before January 1st of year."
48 y = year - 1
51 def _days_in_month(year, month):
52 "year, month -> number of days in that month in that year."
54 if month == 2 and _is_leap(year):
58 def _days_before_month(year, month):
59 "year, month -> number of days in year preceding first day of month."
61 return _DAYS_BEFORE_MONTH[month] + (month > 2 and _is_leap(year))
63 def _ymd2ord(year, month, day):
64 "year, month, day -> ordinal, considering 01-Jan-0001 as day 1."
66 dim = _days_in_month(year, month)
68 return (_days_before_year(year) +
69 _days_before_month(year, month) +
76 # A 4-year cycle has an extra leap day over what we'd get from pasting
80 # Similarly, a 400-year cycle has an extra leap day over what we'd get from
81 # pasting together 4 100-year cycles.
84 # OTOH, a 100-year cycle has one fewer leap day than we'd get from
85 # pasting together 25 4-year cycles.
89 "ordinal -> (year, month, day), considering 01-Jan-0001 as day 1."
93 # closest 400-year boundary at or before n, then work with the offset
95 # n first -- then the values of n at 400-year boundaries are exactly
101 # 1 Jan -399 -_DI400Y +1 -_DI400Y 400-year boundary
105 # 1 Jan 001 1 0 400-year boundary
110 # 1 Jan 401 _DI400Y +1 _DI400Y 400-year boundary
113 year = n400 * 400 + 1 # ..., -399, 1, 401, ...
115 # Now n is the (non-negative) offset, in days, from January 1 of year, to
116 # the desired date. Now compute how many 100-year cycles precede n.
118 # 100-year cycles precede the desired day, which implies the desired
119 # day is December 31 at the end of a 400-year cycle.
122 # Now compute how many 4-year cycles precede it.
126 # that the desired day is December 31 at the end of the 4-year cycle.
129 year += n100 * 100 + n4 * 4 + n1
132 return year-1, 12, 31
134 # Now the year is correct, and n is the offset from January 1. We find
137 assert leapyear == _is_leap(year)
144 assert 0 <= n < _days_in_month(year, month)
146 # Now the year and month are correct, and n is the offset from the
148 return year, month, n+1
329 year = int(dtstr[0:4])
348 return list(_isoweek_to_gregorian(year, weekno, dayno))
358 return [year, month, day]
459 def _isoweek_to_gregorian(year, week, day):
461 if not MINYEAR <= year <= MAXYEAR:
462 raise ValueError(f"Year is out of range: {year}")
470 first_weekday = _ymd2ord(year, 1, 1) % 7
472 _is_leap(year))):
485 day_1 = _isoweek1monday(year)
515 def _check_date_fields(year, month, day):
516 year = _index(year)
519 if not MINYEAR <= year <= MAXYEAR:
520 raise ValueError('year must be in %d..%d' % (MINYEAR, MAXYEAR), year)
523 dim = _days_in_month(year, month)
526 return year, month, day
919 year, month, day
923 def __new__(cls, year, month=None, day=None):
928 year, month, day (required, base 1)
931 isinstance(year, (bytes, str)) and len(year) == 4 and
932 1 <= ord(year[2:3]) <= 12):
934 if isinstance(year, str):
936 year = year.encode('latin1')
944 self.__setstate(year)
947 year, month, day = _check_date_fields(year, month, day)
949 self._year = year
973 January 1 of year 1 is day 1. Only the year, month and day are
994 def fromisocalendar(cls, year, week, day):
995 """Construct a date from the ISO year, week number and weekday.
998 return cls(*_isoweek_to_gregorian(year, week, day))
1062 def year(self):
1063 """year (1-9999)"""
1085 """Return proleptic Gregorian ordinal for the year, month and day.
1087 January 1 of year 1 is day 1. Only the year, month and day values
1092 def replace(self, year=None, month=None, day=None):
1094 if year is None:
1095 year = self._year
1100 return type(self)(year, month, day)
1168 # Day-of-the-week and week-of-the-year, according to ISO
1176 """Return a named tuple containing ISO year, week number, and weekday.
1178 The first ISO week of the year is the (Mon-Sun) week
1179 containing the year's first Thursday; everything else derives
1188 year = self._year
1189 week1monday = _isoweek1monday(year)
1194 year -= 1
1195 week1monday = _isoweek1monday(year)
1198 if today >= _isoweek1monday(year+1):
1199 year += 1
1201 return _IsoCalendarDate(year, week+1, day+1)
1286 def __new__(cls, year, week, weekday, /):
1287 return super().__new__(cls, (year, week, weekday))
1290 def year(self):
1308 f'(year={self[0]}, week={self[1]}, weekday={self[2]})')
1558 # The year must be >= 1000 else Python's strftime implementation
1670 """datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
1672 The year, month and day arguments are required. tzinfo may be None, or an
1677 def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0,
1679 if (isinstance(year, (bytes, str)) and len(year) == 10 and
1680 1 <= ord(year[2:3])&0x7F <= 12):
1682 if isinstance(year, str):
1684 year = bytes(year, 'latin1')
1692 self.__setstate(year, month)
1695 year, month, day = _check_date_fields(year, month, day)
1700 self._year = year
1822 return cls(date.year, date.month, date.day,
1866 return _build_struct_time(self.year, self.month, self.day,
1918 y, m, d = self.year, self.month, self.day
1935 def replace(self, year=None, month=None, day=None, hour=None,
1939 if year is None:
1940 year = self.year
1957 return type(self)(year, month, day, hour, minute, second,
2236 days = _ymd2ord(self.year, self.month, self.day)
2285 def _isoweek1monday(year):
2289 firstday = _ymd2ord(year, 1, 1)
2612 # doesn't matter if daylight time transition points change from year to year, or