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

Epoch.h
1 /*
2 * MIT License
3 * Copyright (c) 2022 Brian T. Park
4 */
5
6 #ifndef ACE_TIME_EPOCH_H
7 #define ACE_TIME_EPOCH_H
8
9 #include <stdint.h>
10 #include "EpochConverterHinnant.h"
11
15 #define ACE_TIME_EPOCH_CONVERTER EpochConverterHinnant
16
17 namespace ace_time {
18
24 class Epoch {
25 public:
27 static int16_t currentEpochYear() {
28 return sCurrentEpochYear;
29 }
30
32 static void currentEpochYear(int16_t year) {
33 sCurrentEpochYear = year;
34 sDaysToCurrentEpochFromInternalEpoch = daysFromInternalEpoch(year);
35 }
36
41 static int32_t daysFromInternalEpoch(int16_t year) {
42 return ACE_TIME_EPOCH_CONVERTER::toEpochDays(year, 1, 1);
43 }
44
50 static int32_t daysToCurrentEpochFromInternalEpoch() {
51 return sDaysToCurrentEpochFromInternalEpoch;
52 }
53
58 static int32_t daysToCurrentEpochFromUnixEpoch() {
59 return ACE_TIME_EPOCH_CONVERTER::kDaysToInternalEpochFromUnixEpoch
60 + sDaysToCurrentEpochFromInternalEpoch;
61 }
62
69 static int64_t secondsToCurrentEpochFromUnixEpoch64() {
70 return daysToCurrentEpochFromUnixEpoch() * (int64_t) 86400;
71 }
72
89 static int16_t epochValidYearLower() {
90 return currentEpochYear() - 50;
91 }
92
109 static int16_t epochValidYearUpper() {
110 return currentEpochYear() + 50;
111 }
112
113 private:
115 static int16_t sCurrentEpochYear;
116
118 static int32_t sDaysToCurrentEpochFromInternalEpoch;
119 };
120
121 }
122
123 #endif
ace_time::Epoch
Utility functions for setting, retrieving, and converting the current epoch.
Definition: Epoch.h:24
ace_time::Epoch::daysToCurrentEpochFromInternalEpoch
static int32_t daysToCurrentEpochFromInternalEpoch()
Number of days from the internal epoch (2000-01-01) to the current epoch.
Definition: Epoch.h:50
ace_time::Epoch::epochValidYearLower
static int16_t epochValidYearLower()
The smallest year (inclusive) for which calculations involving the 32-bit epoch_seconds and time zone...
Definition: Epoch.h:89
ace_time::Epoch::currentEpochYear
static void currentEpochYear(int16_t year)
Set the current epoch year.
Definition: Epoch.h:32
ace_time::Epoch::currentEpochYear
static int16_t currentEpochYear()
Get the current epoch year.
Definition: Epoch.h:27
ace_time::Epoch::epochValidYearUpper
static int16_t epochValidYearUpper()
The largest year (exclusive) for which calculations involving the 32-bit epoch_seconds and time zone ...
Definition: Epoch.h:109
ace_time::Epoch::daysToCurrentEpochFromUnixEpoch
static int32_t daysToCurrentEpochFromUnixEpoch()
Return the number of days from the Unix epoch (1970-01-01T00:00:00) to the current epoch.
Definition: Epoch.h:58
ace_time::Epoch::daysFromInternalEpoch
static int32_t daysFromInternalEpoch(int16_t year)
Return number of days to the given {year}-01-01 from the converter epoch of 2000-01-01.
Definition: Epoch.h:41
ace_time::Epoch::secondsToCurrentEpochFromUnixEpoch64
static int64_t secondsToCurrentEpochFromUnixEpoch64()
Return the number of seconds from the Unix epoch (1970-01-01T00:00:00) to the current epoch.
Definition: Epoch.h:69