28 int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
32 return ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0);
36 yearSecs(
const int year) {
37 return ((isLeap(year) ? 366 : 365 ) * 86400);
41 monthSecs(
const int month,
const int year) {
42 return ((days[month] + ((month == 1 && isLeap(year)) ? 1 : 0 )) * 86400);
57 while ((secs = yearSecs(tm.tm_year + 1900)) <= value) {
60 if (tm.tm_year + 1900 > 9999) {
62 "Time value out of range (year > 9999): " <<
67 while ((secs = monthSecs(tm.tm_mon, tm.tm_year + 1900)) <= value) {
72 while (86400 <= value) {
77 while (3600 <= value) {
90 << setw(4) << tm.tm_year + 1900
91 << setw(2) << tm.tm_mon + 1
92 << setw(2) << tm.tm_mday
93 << setw(2) << tm.tm_hour
94 << setw(2) << tm.tm_min
95 << setw(2) << tm.tm_sec;
115 gettimeofday(&now, NULL);
117 return (static_cast<int64_t>(now.tv_sec));
129 while ((t = (base + value)) < start) {
130 base += 0x100000000LL;
138 const size_t DATE_LEN = 14;
140 inline uint64_t ull(
const int c) {
return (static_cast<uint64_t>(c)); }
143 checkRange(
const unsigned min,
const unsigned max,
const unsigned value,
144 const string& valname)
146 if ((value >= min) && (value <= max)) {
149 isc_throw(InvalidTime,
"Invalid " << valname <<
" value: " << value);
157 for (string::size_type i = 0; i < time_txt.length(); ++i) {
158 if (!isdigit(time_txt.at(i))) {
164 unsigned year, month, day, hour, minute, second;
165 if (time_txt.length() != DATE_LEN ||
166 sscanf(time_txt.c_str(),
"%4u%2u%2u%2u%2u%2u",
167 &year, &month, &day, &hour, &minute, &second) != 6)
172 checkRange(1970, 9999, year,
"year");
173 checkRange(1, 12, month,
"month");
174 checkRange(1, days[month - 1] + ((month == 2 && isLeap(year)) ? 1 : 0),
176 checkRange(0, 23, hour,
"hour");
177 checkRange(0, 59, minute,
"minute");
178 checkRange(0, 60, second,
"second");
180 uint64_t timeval = second + (ull(60) * minute) + (ull(3600) * hour) +
181 ((day - 1) * ull(86400));
182 for (
unsigned m = 0; m < (month - 1); ++m) {
183 timeval += days[m] * ull(86400);
185 if (isLeap(year) && month > 2) {
186 timeval += ull(86400);
188 for (
unsigned y = 1970; y < year; ++y) {
189 timeval += ((isLeap(y) ? 366 : 365) * ull(86400));
int64_t gettimeWrapper()
Return the current time in seconds.
A standard DNS (or ISC) module exception that is thrown if a time conversion function encounters bad ...
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
uint32_t timeFromText32(const string &time_txt)
Convert textual DNSSEC time to integer, 32-bit version.
Defines the logger used by the top-level component of kea-dhcp-ddns.
string timeToText64(uint64_t value)
Convert integral DNSSEC time to textual form, 64-bit version.
int64_t(* gettimeFunction)()