8 #include "ZoneProcessor.h"
9 #include "common/DateConv.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};
48 void createAbbreviation(
54 const char* letterString) {
57 if (*format ==
'\0') {
58 int32_t totalSeconds = stdSeconds + dstSeconds;
59 uint32_t secs = (totalSeconds >= 0) ? totalSeconds : -totalSeconds;
60 ace_common::PrintStr<kAbbrevSize> buf;
62 secondsToHms(secs, &hh, &mm, &ss);
63 buf.print((totalSeconds >= 0) ?
'+' :
'-');
64 ace_common::printPad2To(buf, hh,
'0');
65 if (mm != 0 || ss != 0) {
66 ace_common::printPad2To(buf, mm,
'0');
69 ace_common::printPad2To(buf, ss,
'0');
71 strncpy(dest, buf.cstr(), kAbbrevSize);
72 dest[destSize - 1] =
'\0';
75 }
else if (strchr(format,
'%') !=
nullptr) {
77 if (letterString ==
nullptr) {
78 strncpy(dest, format, destSize - 1);
79 dest[destSize - 1] =
'\0';
85 strncpy(letter, letterString, kAbbrevSize - 1);
91 ace_common::copyReplaceString(dest, destSize, format,
'%', letter);
94 const char* slashPos = strchr(format,
'/');
95 if (slashPos !=
nullptr) {
96 if (dstSeconds == 0) {
97 uint8_t headLength = (slashPos - format);
98 if (headLength >= destSize) headLength = destSize - 1;
99 memcpy(dest, format, headLength);
100 dest[headLength] =
'\0';
102 uint8_t tailLength = strlen(slashPos+1);
103 if (tailLength >= destSize) tailLength = destSize - 1;
104 memcpy(dest, slashPos+1, tailLength);
105 dest[tailLength] =
'\0';
109 strncpy(dest, format, destSize - 1);
110 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).
const uint8_t kAbbrevSize
Size of the c-string buffer needed to hold a time zone abbreviation.