8 #include "ZoneProcessor.h"
13 MonthDay calcStartDayOfMonth(int16_t year, uint8_t month,
14 uint8_t onDayOfWeek, int8_t onDayOfMonth) {
15 if (onDayOfWeek == 0)
return {month, (uint8_t) onDayOfMonth};
17 if (onDayOfMonth >= 0) {
20 if (onDayOfMonth == 0) {
21 onDayOfMonth = daysInMonth - 6;
25 uint8_t dayOfWeekShift = (onDayOfWeek - limitDate.dayOfWeek() + 7) % 7;
26 uint8_t day = (uint8_t) (onDayOfMonth + dayOfWeekShift);
27 if (day > daysInMonth) {
34 onDayOfMonth = -onDayOfMonth;
36 int8_t dayOfWeekShift = (limitDate.dayOfWeek() - onDayOfWeek + 7) % 7;
37 int8_t day = onDayOfMonth - dayOfWeekShift;
42 day += daysInPrevMonth;
44 return {month, (uint8_t) day};
91 void createAbbreviation(
95 uint32_t deltaSeconds,
96 const char* letterString) {
99 if (strchr(format,
'%') !=
nullptr) {
101 if (letterString ==
nullptr) {
102 strncpy(dest, format, destSize - 1);
103 dest[destSize - 1] =
'\0';
107 char letter[internal::kAbbrevSize];
109 strncpy(letter, letterString, internal::kAbbrevSize - 1);
110 letter[internal::kAbbrevSize - 1] =
'\0';
115 ace_common::copyReplaceString(dest, destSize, format,
'%', letter);
119 const char* slashPos = strchr(format,
'/');
120 if (slashPos !=
nullptr) {
121 if (deltaSeconds == 0) {
122 uint8_t headLength = (slashPos - format);
123 if (headLength >= destSize) headLength = destSize - 1;
124 memcpy(dest, format, headLength);
125 dest[headLength] =
'\0';
127 uint8_t tailLength = strlen(slashPos+1);
128 if (tailLength >= destSize) tailLength = destSize - 1;
129 memcpy(dest, slashPos+1, tailLength);
130 dest[tailLength] =
'\0';
134 strncpy(dest, format, destSize - 1);
135 dest[destSize - 1] =
'\0';
static LocalDate forComponents(int16_t year, uint8_t month, uint8_t day)
Factory method using separated year, month and day fields.
static uint8_t daysInMonth(int16_t year, uint8_t month)
Return the number of days in the given (year, month).