AceTime  2.2.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 internal::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  sDaysToCurrentEpochFromConverterEpoch = daysFromConverterEpoch(year);
35  }
36 
41  static int32_t daysFromConverterEpoch(int16_t year) {
42  return ACE_TIME_EPOCH_CONVERTER::toEpochDays(year, 1, 1);
43  }
44 
50  return sDaysToCurrentEpochFromConverterEpoch;
51  }
52 
58  return ACE_TIME_EPOCH_CONVERTER::kDaysToConverterEpochFromUnixEpoch
59  + sDaysToCurrentEpochFromConverterEpoch;
60  }
61 
69  return daysToCurrentEpochFromUnixEpoch() * (int64_t) 86400;
70  }
71 
88  static int16_t epochValidYearLower() {
89  return currentEpochYear() - 50;
90  }
91 
108  static int16_t epochValidYearUpper() {
109  return currentEpochYear() + 50;
110  }
111 
112  private:
114  static int16_t sCurrentEpochYear;
115 
117  static int32_t sDaysToCurrentEpochFromConverterEpoch;
118 };
119 
120 }
121 
122 #endif
Utitliy functions for setting, retrieving, and converting the current epoch.
Definition: Epoch.h:24
static int32_t daysFromConverterEpoch(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
static int16_t epochValidYearLower()
The smallest year (inclusive) for which calculations involving the 32-bit epoch_seconds and time zone...
Definition: Epoch.h:88
static void currentEpochYear(int16_t year)
Set the current epoch year.
Definition: Epoch.h:32
static int16_t currentEpochYear()
Get the current epoch year.
Definition: Epoch.h:27
static int32_t daysToCurrentEpochFromConverterEpoch()
Number of days from the converter epoch (2000-01-01) to the current epoch.
Definition: Epoch.h:49
static int16_t epochValidYearUpper()
The largest year (exclusive) for which calculations involving the 32-bit epoch_seconds and time zone ...
Definition: Epoch.h:108
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:57
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:68