This doesn't take account of the time of day at which the change occurs.
The approach I'd use is to write a program on a PC which (for my own locale) calculated the time of the start and end of DST for each year of interest. The times would be in seconds since the MicroPython epoch. The output of the script would be a Python dict indexed by year and containing tuples of form (dst_start, dst_end) - (numbers below are arbitrary).
Code: Select all
dst = {2018:(12345, 67890), 2019:(88888, 99999),}
def ltime():
t = utime.time()
start, end = dst[utime.localtime(t)[0]
return t if t < start or t > end else t + 3600
The same thing could be done with a file if the dict was regarded as being excessively big.
In either case the calculation is done once, offline on a PC, minimising the work to be done at runtime.