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, month, day)

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

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

classmethod fromisoformat(date_string)

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

classmethod fromordinal(ordinal)

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

classmethod fromtimestamp(t)

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

isoformat()

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

isoweekday()

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

property month

Between 1 and 12 inclusive.

replace(year=None, month=None, day=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()

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()

Return the current local date.

toordinal()

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

weekday()

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

property year

Between MINYEAR and MAXYEAR inclusive.

class adafruit_datetime.datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=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, time, tzinfo=True)

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()

Return string representing the datetime.

date()

Return date object with same year, month and day.

property day

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

dst()

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

Fold.

classmethod fromisoformat(date_string)

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, tz=None)

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

property hour

In range(24).

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

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

property microsecond

In range (1000000)

property minute

In range (60)

property month

Between 1 and 12 inclusive.

classmethod now(timezone=None)

Return the current local date and time.

replace(year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, tzinfo=True, *, fold=None)

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

property second

In range (60)

time()

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

timestamp()

Return POSIX timestamp as float

timetuple()

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

toordinal()

Return the proleptic Gregorian ordinal of the date.

property tzinfo

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

classmethod utcfromtimestamp(timestamp)

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

utcoffset()

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()

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

property year

Between MINYEAR and MAXYEAR inclusive.

class adafruit_datetime.time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=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

Fold.

classmethod fromisoformat(time_string)

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

property hour

In range(24).

isoformat(timespec='auto')

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

In range(1000000).

property minute

In range(60).

property second

In range(60).

property tzinfo

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

tzname()

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()

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

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

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

property days

Days, Between -999999999 and 999999999 inclusive

property microseconds

Microseconds, Between 0 and 999999 inclusive

property seconds

Seconds, Between 0 and 86399 inclusive

total_seconds()

Return the total number of seconds contained in the duration.

class adafruit_datetime.timezone(offset, name=<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)

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

utcoffset(dt)

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.

fromutc(dt)

datetime in UTC -> datetime in local time.

tzname(dt)

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

utcoffset(dt)

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