# Simple code.py file to set the initial time on a PCF8523 RTC
# Change the if False to if True to set the time once, then change it back to False
# to run normally after that.

import time
import board
from adafruit_pcf8523.pcf8523 import PCF8523

days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")

i2c = board.I2C()
rtc_pcf = PCF8523(i2c)

if False:  # change to True if you want to set the time!
    #                     year, mon, date, hour, min, sec, wday, yday, isdst
    t = time.struct_time((2025, 12, 19, 9, 48, 0, 4, -1, -1))
    # you must set year, mon, date, hour, min, sec and weekday
    # yearday is not supported, isdst can be set but we don't do anything with it at this time
    print("Setting time to:", t)
    rtc.datetime = t
    print()

print("Current time:", rtc_pcf.datetime)
while True:
    now = rtc_pcf.datetime
    print(
        "{:04}-{:02}-{:02} {:02}:{:02}:{:02}".format(
            now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec
        )
    )
    time.sleep(1)