adafruit_datetime

Concrete date/time and related types.

See http://www.iana.org/time-zones/repository/tz-link.html for time zone and DST data sources.

Implementation Notes

Software and Dependencies:

class adafruit_datetime.date(year: int, month: int, day: int)

A date object represents a date (year, month and day) in an idealized calendar, the current Gregorian calendar indefinitely extended in both directions. Objects of this type are always naive.

Creates a new date object.

Parameters
  • year (int) – Year within range, MINYEAR <= year <= MAXYEAR

  • month (int) – Month within range, 1 <= month <= 12

  • day (int) – Day within range, 1 <= day <= number of days in the given month and year

property day: int

Between 1 and the number of days in the given month of the given year.

classmethod fromisoformat(date_string: str) date

Return a date object constructed from an ISO date format. Valid format is YYYY-MM-DD

classmethod fromordinal(ordinal: int) date

Return the date corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1.

classmethod fromtimestamp(t: float) date

Return the local date corresponding to the POSIX timestamp, such as is returned by time.time().

isoformat() str

Return a string representing the date in ISO 8601 format, YYYY-MM-DD:

isoweekday() int

Return the day of the week as an integer, where Monday is 1 and Sunday is 7.

property month: int

Between 1 and 12 inclusive.

replace(year: Optional[int] = None, month: Optional[int] = None, day: Optional[int] = None)

Return a date with the same value, except for those parameters given new values by whichever keyword arguments are specified. If no keyword arguments are specified - values are obtained from datetime object.

timetuple() struct_time

Return a time.struct_time such as returned by time.localtime(). The hours, minutes and seconds are 0, and the DST flag is -1.

classmethod today() date

Return the current local date.

toordinal() int

Return the proleptic Gregorian ordinal of the date, where January 1 of year 1 has ordinal 1.

weekday() int

Return the day of the week as an integer, where Monday is 0 and Sunday is 6.

property year: int

Between MINYEAR and MAXYEAR inclusive.

class adafruit_datetime.datetime(year: int, month: int, day: int, hour: int = 0, minute: int = 0, second: int = 0, microsecond: int = 0, tzinfo: Optional[tzinfo] = None, *, fold: int = 0)

A datetime object is a single object containing all the information from a date object and a time object. Like a date object, datetime assumes the current Gregorian calendar extended in both directions; like a time object, datetime assumes there are exactly 3600*24 seconds in every day.

Creates a new date object.

Parameters
  • year (int) – Year within range, MINYEAR <= year <= MAXYEAR

  • month (int) – Month within range, 1 <= month <= 12

  • day (int) – Day within range, 1 <= day <= number of days in the given month and year

classmethod combine(date: date, time: time, tzinfo: bool = True) datetime

Return a new datetime object whose date components are equal to the given date object’s, and whose time components are equal to the given time object’s.

ctime() str

Return string representing the datetime.

date() date

Return date object with same year, month and day.

property day: int

Between 1 and the number of days in the given month of the given year.

dst() Optional[timedelta]

If tzinfo is None, returns None, else returns self.tzinfo.dst(self), and raises an exception if the latter doesn’t return None or a timedelta object with magnitude less than one day.

property fold: int

Fold.

classmethod fromisoformat(date_string: str) datetime

Return a datetime object constructed from an ISO date format. Valid format is YYYY-MM-DD[*HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]]

classmethod fromtimestamp(timestamp: float, tz: Optional[tzinfo] = None) datetime

Return the local date corresponding to the POSIX timestamp, such as is returned by time.time().

property hour: int

In range(24).

isoformat(sep: str = 'T', timespec: str = 'auto') str

Return a string representing the date and time in ISO8601 format.

property microsecond: int

In range (1000000)

property minute: int

In range (60)

property month: int

Between 1 and 12 inclusive.

classmethod now(timezone: Optional[tzinfo] = None) datetime

Return the current local date and time.

replace(year: Optional[int] = None, month: Optional[str] = None, day: Optional[str] = None, hour: Optional[str] = None, minute: Optional[str] = None, second: Optional[str] = None, microsecond: Optional[str] = None, tzinfo: bool = True, *, fold: Optional[int] = None) datetime

Return a datetime with the same attributes, except for those attributes given new values by whichever keyword arguments are specified.

property second: int

In range (60)

time() time

Return time object with same hour, minute, second, microsecond and fold. tzinfo is None. See also method timetz().

timestamp() float

Return POSIX timestamp as float

timetuple() struct_time

Return local time tuple compatible with time.localtime().

toordinal() int

Return the proleptic Gregorian ordinal of the date.

property tzinfo: Optional[tzinfo]

The object passed as the tzinfo argument to the datetime constructor, or None if none was passed.

classmethod utcfromtimestamp(timestamp: float) datetime

Return the UTC datetime corresponding to the POSIX timestamp, with tzinfo None

utcoffset() Optional[timedelta]

If tzinfo is None, returns None, else returns self.tzinfo.utcoffset(self), and raises an exception if the latter doesn’t return None or a timedelta object with magnitude less than one day.

weekday() int

Return the day of the week as an integer, where Monday is 0 and Sunday is 6.

property year: int

Between MINYEAR and MAXYEAR inclusive.

class adafruit_datetime.time(hour: int = 0, minute: int = 0, second: int = 0, microsecond: int = 0, tzinfo: Optional[tzinfo] = None, *, fold: int = 0)

A time object represents a (local) time of day, independent of any particular day, and subject to adjustment via a tzinfo object.

property fold: int

Fold.

classmethod fromisoformat(time_string: str) time

Return a time object constructed from an ISO date format. Valid format is HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]

property hour: int

In range(24).

isoformat(timespec: str = 'auto') str

Return a string representing the time in ISO 8601 format, one of: HH:MM:SS.ffffff, if microsecond is not 0

HH:MM:SS, if microsecond is 0

HH:MM:SS.ffffff+HH:MM[:SS[.ffffff]], if utcoffset() does not return None

HH:MM:SS+HH:MM[:SS[.ffffff]], if microsecond is 0 and utcoffset() does not return None

property microsecond: int

In range(1000000).

property minute: int

In range(60).

property second: int

In range(60).

property tzinfo: Optional[tzinfo]

The object passed as the tzinfo argument to the time constructor, or None if none was passed.

tzname() str

Return the timezone name.

Note that the name is 100% informational – there’s no requirement that it mean anything in particular. For example, “GMT”, “UTC”, “-500”, “-5:00”, “EDT”, “US/Eastern”, “America/New York” are all valid replies.

utcoffset() timedelta

Return the timezone offset in minutes east of UTC (negative west of UTC).

class adafruit_datetime.timedelta(days: int = 0, seconds: int = 0, microseconds: int = 0, milliseconds: int = 0, minutes: int = 0, hours: int = 0, weeks: int = 0)

A timedelta object represents a duration, the difference between two dates or times.

property days: int

Days, Between -999999999 and 999999999 inclusive

property microseconds: int

Microseconds, Between 0 and 999999 inclusive

property seconds: int

Seconds, Between 0 and 86399 inclusive

total_seconds() float

Return the total number of seconds contained in the duration.

class adafruit_datetime.timezone(offset: ~adafruit_datetime.timedelta, name: ~typing.Union[str, object] = <object object>)

The timezone class is a subclass of tzinfo, each instance of which represents a timezone defined by a fixed offset from UTC.

Objects of this class cannot be used to represent timezone information in the locations where different offsets are used in different days of the year or where historical changes have been made to civil time.

tzname(dt: Optional[datetime]) str

Return the time zone name corresponding to the datetime object dt, as a string.

utcoffset(dt: Optional[datetime]) timedelta

Return offset of local time from UTC, as a timedelta object that is positive east of UTC.

class adafruit_datetime.tzinfo

This is an abstract base class, meaning that this class should not be instantiated directly. Define a subclass of tzinfo to capture information about a particular time zone.

dst(dt: datetime) None

Return the DST setting correspinding to the datetime object dt, as a number.

DST usage is currently not implemented for this library.

fromutc(dt: datetime) datetime

datetime in UTC -> datetime in local time.

tzname(dt: datetime) str

Return the time zone name corresponding to the datetime object dt, as a string.

utcoffset(dt: datetime) timedelta

Return offset of local time from UTC, as a timedelta object that is positive east of UTC.