24int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
28 return ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0);
32yearSecs(
const int year) {
33 return ((isLeap(year) ? 366 : 365) * 86400);
37monthSecs(
const int month,
const int year) {
38 return ((days[month] + ((month == 1 && isLeap(year)) ? 1 : 0)) * 86400);
45constexpr size_t DATE_LEN = 14;
49 return (
static_cast<uint64_t
>(c));
53checkRange(
const unsigned min,
const unsigned max,
const unsigned value,
const string& valname) {
54 if ((value >= min) && (value <= max)) {
78 gettimeofday(&now, 0);
80 return (
static_cast<int64_t
>(now.tv_sec));
92 while ((secs = yearSecs(tm.tm_year + 1900)) <= value) {
95 if (tm.tm_year + 1900 > 9999) {
101 while ((secs = monthSecs(tm.tm_mon, tm.tm_year + 1900)) <= value) {
107 while (86400 <= value) {
113 while (3600 <= value) {
119 while (60 <= value) {
127 oss << setfill(
'0') << setw(4) << tm.tm_year + 1900 << setw(2) << tm.tm_mon + 1 << setw(2)
128 << tm.tm_mday << setw(2) << tm.tm_hour << setw(2) << tm.tm_min << setw(2) << tm.tm_sec;
140 while ((t = (base + value)) < start) {
141 base += 0x100000000LL;
152 for (string::size_type i = 0; i < time_txt.length(); ++i) {
153 if (!isdigit(time_txt.at(i))) {
158 unsigned year, month, day, hour, minute, second;
159 if (time_txt.length() != DATE_LEN || sscanf(time_txt.c_str(),
"%4u%2u%2u%2u%2u%2u", &year,
160 &month, &day, &hour, &minute, &second) != 6) {
164 checkRange(1970, 9999, year,
"year");
165 checkRange(1, 12, month,
"month");
166 checkRange(1, days[month - 1] + ((month == 2 && isLeap(year)) ? 1 : 0), day,
"day");
167 checkRange(0, 23, hour,
"hour");
168 checkRange(0, 59, minute,
"minute");
169 checkRange(0, 60, second,
"second");
171 uint64_t timeval = second + (ull(60) * minute) + (ull(3600) * hour) + ((day - 1) * ull(86400));
172 for (
unsigned m = 0; m < (month - 1); ++m) {
173 timeval += days[m] * ull(86400);
176 if (isLeap(year) && month > 2) {
177 timeval += ull(86400);
180 for (
unsigned y = 1970; y < year; ++y) {
181 timeval += ((isLeap(y) ? 366 : 365) * ull(86400));
A standard DNS (or ISC) module exception that is thrown if a time conversion function encounters bad ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
int64_t(* getTimeFunction)()=0
int64_t getTimeWrapper()
Return the current time in seconds.
uint32_t timeFromText32(const string &time_txt)
Convert textual DNSSEC time to integer, 32-bit version.
string timeToText64(uint64_t value)
Convert integral DNSSEC time to textual form, 64-bit version.
uint64_t timeFromText64(const string &time_txt)
Convert textual DNSSEC time to integer, 64-bit version.
string timeToText32(const uint32_t value)
Convert integral DNSSEC time to textual form, 32-bit version.
Defines the logger used by the top-level component of kea-lfc.