RTC: Handling days
The day has three separate representations: The day of the week (Monday to Sunday) exists in 2 different formats depending on use, and there is also day of the month (1st through 31st). The RTC handles these day of week and day of month quite separately, and makes no automatic connections between them. It does however know how many days there are in each month, and it knows about leap years.
Day Number (DN)
In the clock there is a day number (DN) that counts in the sequence 0-1-2-3-4-5-6-0 at midnight. The 7 values correspond to the 7 days of the week. Monday is day 0. DN is read out with the time and written separately.
In the EC1 the RTC hardware calculated Day Number from the date, so DN is read-only.
Day Mask (DM)
An event can be set to trigger at a set time of day on any combination of days of the week. Each event contains a Day Mask (DM). A day mask is a byte of data where bits 0 to 6 each correspond to one day. By manipulating the individual bits in a day mask you can determine which days of the week the event will activate on. A bit set (1, True) activates that day. Day masks are read and written as part of an event.
Day of month
Within the calendar function the day of month is updated each midnight and maintained correctly in terms of the number of days in the month. The day of month is read and written with the date.