AceTime  0.1
Date and time classes for Arduino that supports the TZ DAtabase, and a system clock synchronized from an NTP server or an RTC chip.
local_date_mutation.h
1 #ifndef ACE_TIME_LOCAL_DATE_MUTATION_H
2 #define ACE_TIME_LOCAL_DATE_MUTATION_H
3 
4 #include <stdint.h>
5 #include "LocalDate.h"
6 
7 namespace ace_time {
8 namespace local_date_mutation {
9 
11 inline void incrementOneDay(LocalDate& ld) {
12  uint8_t day = ld.day() + 1;
13  if (day <= LocalDate::daysInMonth(ld.year(), ld.month())) {
14  ld.day(day);
15  return;
16  }
17 
18  ld.day(1);
19  uint8_t month = ld.month() + 1;
20  if (month <= 12) {
21  ld.month(month);
22  return;
23  }
24 
25  ld.month(1);
26  ld.yearTiny(ld.yearTiny() + 1);
27 }
28 
30 inline void decrementOneDay(LocalDate& ld) {
31  uint8_t day = ld.day() - 1;
32  if (day > 0) {
33  ld.day(day);
34  return;
35  }
36 
37  if (ld.month() == 1) {
38  ld.day(31);
39  ld.month(12);
40  ld.yearTiny(ld.yearTiny() - 1);
41  return;
42  }
43 
44  uint8_t newMonth = ld.month() - 1;
45  ld.day(LocalDate::daysInMonth(ld.year(), newMonth));
46  ld.month(newMonth);
47 }
48 
49 }
50 }
51 
52 #endif
static uint8_t daysInMonth(int16_t year, uint8_t month)
Return the number of days in the current month.
Definition: LocalDate.h:194