AceTime 2.4.0 Date and time classes for Arduino that support timezones from the TZ Database.

local_date_mutation.h
1 /*
2 * MIT License
3 * Copyright (c) 2018 Brian T. Park
4 */
5
6 #ifndef ACE_TIME_LOCAL_DATE_MUTATION_H
7 #define ACE_TIME_LOCAL_DATE_MUTATION_H
8
9 #include <stdint.h>
10 #include "LocalDate.h"
11
12 namespace ace_time {
13 namespace local_date_mutation {
14
19 inline void incrementOneDay(LocalDate& ld) {
20 uint8_t day = ld.day() + 1;
21 uint8_t month = ld.month();
22 int16_t year = ld.year();
23
24 if (day > LocalDate::daysInMonth(ld.year(), month)) {
25 day = 1;
26 month++;
27 if (month > 12) {
28 month = 1;
29 year++;
30 }
31 }
32 ld.day(day);
33 ld.month(month);
34 ld.year(year);
35 }
36
41 inline void decrementOneDay(LocalDate& ld) {
42 uint8_t day = ld.day() - 1;
43 uint8_t month = ld.month();
44 int16_t year = ld.year();
45
46 if (day == 0) {
47 if (month == 1) {
48 day = 31;
49 month = 12;
50 year--;
51 } else {
52 month--;
53 day = LocalDate::daysInMonth(ld.year(), month);
54 }
55 }
56 ld.day(day);
57 ld.month(month);
58 ld.year(year);
59 }
60
61 }
62 }
63
64 #endif
ace_time::LocalDate::daysInMonth
static uint8_t daysInMonth(int16_t year, uint8_t month)
Return the number of days in the given (year, month).
Definition: LocalDate.h:133