rtc — Real Time Clock

The rtc module provides support for a Real Time Clock. You can access and manage the RTC using rtc.RTC. It also backs the time.time() and time.localtime() functions using the onboard RTC if present.

Classes

rtc.set_time_source(rtc)

Sets the RTC time source used by time.localtime(). The default is rtc.RTC, but it’s useful to use this to override the time source for testing purposes. For example:

import rtc
import time

class RTC(object):
    @property
    def datetime(self):
        return time.struct_time((2018, 3, 17, 21, 1, 47, 0, 0, 0))

r = RTC()
rtc.set_time_source(r)