8 #include "ZoneProcessor.h"
9 #include "common/DateConv.h"
14 MonthDay calcStartDayOfMonth(int16_t year, uint8_t month,
15 uint8_t onDayOfWeek, int8_t onDayOfMonth) {
16 if (onDayOfWeek == 0)
return {month, (uint8_t) onDayOfMonth};
18 if (onDayOfMonth >= 0) {
21 if (onDayOfMonth == 0) {
22 onDayOfMonth = daysInMonth - 6;
26 uint8_t dayOfWeekShift = (onDayOfWeek - limitDate.dayOfWeek() + 7) % 7;
27 uint8_t day = (uint8_t) (onDayOfMonth + dayOfWeekShift);
28 if (day > daysInMonth) {
35 onDayOfMonth = -onDayOfMonth;
37 int8_t dayOfWeekShift = (limitDate.dayOfWeek() - onDayOfWeek + 7) % 7;
38 int8_t day = onDayOfMonth - dayOfWeekShift;
43 day += daysInPrevMonth;
45 return {month, (uint8_t) day};
49 void createAbbreviation(
55 const char* letterString) {
58 if (*format ==
'\0') {
59 int32_t totalSeconds = stdSeconds + dstSeconds;
60 uint32_t secs = (totalSeconds >= 0) ? totalSeconds : -totalSeconds;
61 ace_common::PrintStr<internal::kAbbrevSize> buf;
63 secondsToHms(secs, &hh, &mm, &ss);
64 buf.print((totalSeconds >= 0) ?
'+' :
'-');
65 ace_common::printPad2To(buf, hh,
'0');
66 if (mm != 0 || ss != 0) {
67 ace_common::printPad2To(buf, mm,
'0');
70 ace_common::printPad2To(buf, ss,
'0');
72 strncpy(dest, buf.cstr(), internal::kAbbrevSize);
73 dest[destSize - 1] =
'\0';
76 }
else if (strchr(format,
'%') !=
nullptr) {
78 if (letterString ==
nullptr) {
79 strncpy(dest, format, destSize - 1);
80 dest[destSize - 1] =
'\0';
84 char letter[internal::kAbbrevSize];
86 strncpy(letter, letterString, internal::kAbbrevSize - 1);
87 letter[internal::kAbbrevSize - 1] =
'\0';
92 ace_common::copyReplaceString(dest, destSize, format,
'%', letter);
95 const char* slashPos = strchr(format,
'/');
96 if (slashPos !=
nullptr) {
97 if (dstSeconds == 0) {
98 uint8_t headLength = (slashPos - format);
99 if (headLength >= destSize) headLength = destSize - 1;
100 memcpy(dest, format, headLength);
101 dest[headLength] =
'\0';
103 uint8_t tailLength = strlen(slashPos+1);
104 if (tailLength >= destSize) tailLength = destSize - 1;
105 memcpy(dest, slashPos+1, tailLength);
106 dest[tailLength] =
'\0';
110 strncpy(dest, format, destSize - 1);
111 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).