neotime.Date

A Date object represents a date in the proleptic Gregorian Calendar. Years between 0001 and 9999 are supported, with additional support for the “zero date” used in some contexts.

Each date is based on a proleptic Gregorian ordinal, which models 1 Jan 0001 as day 1 and counts each subsequent day up to, and including, 31 Dec 9999. The standard year, month and day value of each date is also available.

Internally, the day of the month is always stored as-is, with the exception of the last three days of that month. These are always stored as -1, -2 and -3 (counting from the last day). This system allows some temporal arithmetic (particularly adding or subtracting months) to produce a more desirable outcome than would otherwise be produced. Externally, the day number is always the same as would be written on a calendar.

Constructors and other class methods

class Date(year, month, day)

Construct a new Date object. All arguments are required and should be integers. For general dates, the following ranges are supported:

Argument Minimum Maximum
year MIN_YEAR (0001) MAX_YEAR (9999)
month 1 12
day 1 Date.days_in_month(year, month)

A zero date can also be acquired by passing all zeroes to the Date constructor or by using the ZeroDate constant.

classmethod Date.today()
classmethod Date.utc_today()

Return the current Date according to UTC.

classmethod Date.from_timestamp(timestamp, tz=None)
classmethod Date.utc_from_timestamp(timestamp)
classmethod Date.from_ordinal(ordinal)

Construct and return a Date from a proleptic Gregorian ordinal. This is simply an integer value that corresponds to a day, starting with 1 for 1 Jan 0001.

classmethod Date.parse(s)
Date.from_clock_time(cls, t, epoch):
classmethod Date.is_leap_year(year)

Return a bool value that indicates whether or not year is a leap year.

classmethod Date.days_in_year(year)

Return the number of days in year.

classmethod Date.days_in_month(year, month)

Return the number of days in month of year.

Class attributes

Date.min
Date.max
Date.resolution

Instance attributes

d.year
d.month
d.day
d.year_month_day
d.year_week_day
d.year_day

Return a 2-tuple of year and day number. This is the number of the day relative to the start of the year, with 1 Jan corresponding to 1.

Operations

Instance methods

d.replace(year=self.year, month=self.month, day=self.day)

Return a Date with one or more components replaced with new values.

d.time_tuple()
d.to_ordinal()
d.weekday()
d.iso_weekday()
dt.iso_calendar()
d.iso_format()
d.__repr__()
d.__str__()
d.__format__()

Special values

ZeroDate

A Date instance set to 0000-00-00. This has an ordinal value of 0.