So far, I have the following code:
enum weekOfMonth : unsigned char {last, first, second, third, fourth};// 0-4
enum dayOfWeek : unsigned char {Sunday = 1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};// 1-7
enum monthOfYear : unsigned char {January = 1, February, March, April, May, June, July, August, September, October, November, December};// 1-12
struct localOffset {
unsigned int sign : 1;// 0-1
unsigned int hour : 4;// 0-15 use html forms validation to restrict to -12 to +14
unsigned int minute : 6;// 0-63 use html forms validation to restrict to 0-59
unsigned int driftSign : 1;
unsigned int second : 4;// 0-15 use html forms validation to restrict to -15 +15 allows a little drift in seconds
};
struct TimeZoneRule {
char tzrName[6];// according to https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations names are max 5 characters (plus NULL termination)
weekOfMonth tzrWeek : 3;// enumerated above
dayOfWeek tzrDay : 3;// enumerated above
monthOfYear tzrMonth : 4;// enumerated above
unsigned char tzrHour : 5;// 0-31 use html form validation to restrict to 0-23
localOffset tzrOffset;
};
struct TimeSettings {
unsigned char tsHourMode : 1;
unsigned char tsDSTMode : 1;
TimeZoneRule tzr1;
TimeZoneRule tzr2;
};
void setup() {
}
void loop() {
}
When I verify this code, I get the following warnings:
warning: 'TimeZoneRule::tzrWeek' is too small to hold all values of 'enum weekOfMonth'
warning: 'TimeZoneRule::tzrDay' is too small to hold all values of 'enum dayOfWeek'
warning: 'TimeZoneRule::tzrMonth' is too small to hold all values of 'enum monthOfYear'
I have counted and recounted, and my own thinking is that 3 bits should hold 8 values, enough for 5 weeks of the month, 3 bits also enough for 7 days of the week and 4 bits should hold 16 values, enough for 12 months of the year. What am I missing?