AceTime  2.1.0
Date and time classes for Arduino that support timezones from the TZ Database.
LocalDate.cpp
1 /*
2  * MIT License
3  * Copyright (c) 2018 Brian T. Park
4  */
5 
6 #include "LocalDate.h"
7 
8 namespace ace_time {
9 
10 // Offsets used to calculate the day of the week of a particular (year, month,
11 // day). The element represents the number of days that the first of month of
12 // the given index was shifted by the cummulative days from the previous months.
13 // To determine the "day of the week", we must normalize the resulting "day of
14 // the week" modulo 7.
15 //
16 // January is index 0, but we also use a modified year, where the year starts in
17 // March to make leap years easier to handle, so the shift for March=3 is 0.
18 //
19 // For example:
20 // * atc_days_of_week[3] is 3 because April (index=3) 1st is shifted by 3
21 // days because March has 31 days (28 + 3).
22 // * atc_days_of_week[4] is 5 because May (index=4) 1st is shifted by 2
23 // additional days from April, because April has 30 days (28 + 2).
24 const uint8_t LocalDate::sDayOfWeek[12] = {
25  5 /*Jan=31*/,
26  1 /*Feb=28*/,
27  0 /*Mar=31, start of "year"*/,
28  3 /*Apr=30*/,
29  5 /*May=31*/,
30  1 /*Jun=30*/,
31  3 /*Jul=31*/,
32  6 /*Aug=31*/,
33  2 /*Sep=30*/,
34  4 /*Oct=31*/,
35  0 /*Nov=30*/,
36  2 /*Dec=31*/,
37 };
38 
39 // Using 0=Jan offset.
40 const uint8_t LocalDate::sDaysInMonth[12] = {
41  31 /*Jan=31*/,
42  28 /*Feb=28*/,
43  31 /*Mar=31*/,
44  30 /*Apr=30*/,
45  31 /*May=31*/,
46  30 /*Jun=30*/,
47  31 /*Jul=31*/,
48  31 /*Aug=31*/,
49  30 /*Sep=30*/,
50  31 /*Oct=31*/,
51  30 /*Nov=30*/,
52  31 /*Dec=31*/,
53 };
54 
55 }