experimental.clocks.clock_source

Interface for interacting with realtime clock hardware.

For consistency, we always assume that the external clock source is synchronized with UTC. This means your I2C clock should be set to UTC time, not local time. If you set your I2C clock to local time some scripts may behave incorrectly.

The Raspberry Pi Pico (and official variants like the Pico W, Pico 2, etc…) does NOT include a realtime clock. All RTC implementations rely on some external reference time, e.g. - external hardware (e.g. an I2C-supported external clock module) - a wireless connection and an accessible NTP server

The external clock source must implement the ExternalClockSource class

class experimental.clocks.clock_source.ExternalClockSource

A generic class representing any external, canonical clock source.

Any network- or I2C-based external time source should inherit from this class and implement the relevant functions.

The implemented clock source must provide the time and date in UTC, 24-hour time.

check_valid_datetime(datetime)

Check if a datetime contains valid values.

Raises

ValueError – if any field is out of range

Parameters

datetime – The datetime tuple to validate

datetime()

Get the current UTC time as a tuple.

see: https://docs.micropython.org/en/latest/library/time.html#time.localtime

Returns

a tuple of the form (0-year, 1-month, 2-day, 3-hour, 4-minutes, 5-seconds, 6-weekday, 7-yearday)

is_leap_year(datetime)

Determine if the datetime’s year is a leap year or not.

Returns

True if the datetime is a leap year, otherwise False

month_length(datetime)

Get the numer of days in the month.

This takes leap-years into consideration

Returns

The number of days in the datetime’s month

set_datetime(datetime)

Set the clock’s current UTC time.

If the clock does not support setting (e.g. it’s an NTP source we can only read from) your sub-class should implement this method anyway and simply pass.

see: https://docs.micropython.org/en/latest/library/time.html#time.localtime

Parameters

datetime – A tuple of the form (0-year, 1-month, 2-day, 3-hour, 4-minutes, 5-seconds, 6-weekday, 7-yearday)

year_length(datetime)

Determine the number of days in the datetime’s year.

Returns

The number of days in the year, taking leap years into account