diff options
author | Piotrek Zadroga <piotrek@isc.org> | 2024-02-22 09:41:28 +0100 |
---|---|---|
committer | Piotrek Zadroga <piotrek@isc.org> | 2024-03-20 16:17:29 +0100 |
commit | 38ab31a5784b294d4ec6738ab6ed175baa14b574 (patch) | |
tree | d5d8cc86fc2a956ed49db5ab57c54d3a096049f4 /src | |
parent | [#3249] hammer fix (diff) | |
download | kea-38ab31a5784b294d4ec6738ab6ed175baa14b574.tar.xz kea-38ab31a5784b294d4ec6738ab6ed175baa14b574.zip |
[#3212] refactor time utils
Step 1: remove from lib/utils
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/d2/tests/d2_queue_mgr_unittests.cc | 1 | ||||
-rw-r--r-- | src/bin/d2/tests/d2_update_mgr_unittests.cc | 1 | ||||
-rw-r--r-- | src/lib/dhcp_ddns/ncr_msg.h | 1 | ||||
-rw-r--r-- | src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc | 1 | ||||
-rw-r--r-- | src/lib/dhcp_ddns/tests/ncr_unittests.cc | 1 | ||||
-rw-r--r-- | src/lib/dns/tests/message_unittest.cc | 1 | ||||
-rw-r--r-- | src/lib/dns/tests/rdata_rrsig_unittest.cc | 1 | ||||
-rw-r--r-- | src/lib/dns/tests/rdata_tkey_unittest.cc | 1 | ||||
-rw-r--r-- | src/lib/util/Makefile.am | 2 | ||||
-rw-r--r-- | src/lib/util/tests/Makefile.am | 1 | ||||
-rw-r--r-- | src/lib/util/tests/time_utilities_unittest.cc | 155 | ||||
-rw-r--r-- | src/lib/util/time_utilities.cc | 203 | ||||
-rw-r--r-- | src/lib/util/time_utilities.h | 165 |
13 files changed, 0 insertions, 534 deletions
diff --git a/src/bin/d2/tests/d2_queue_mgr_unittests.cc b/src/bin/d2/tests/d2_queue_mgr_unittests.cc index 5da5fe040f..003ca03551 100644 --- a/src/bin/d2/tests/d2_queue_mgr_unittests.cc +++ b/src/bin/d2/tests/d2_queue_mgr_unittests.cc @@ -11,7 +11,6 @@ #include <d2/d2_queue_mgr.h> #include <d2srv/testutils/stats_test_utils.h> #include <dhcp_ddns/ncr_udp.h> -#include <util/time_utilities.h> #include <gtest/gtest.h> #include <algorithm> diff --git a/src/bin/d2/tests/d2_update_mgr_unittests.cc b/src/bin/d2/tests/d2_update_mgr_unittests.cc index df8de60e28..6ffd315525 100644 --- a/src/bin/d2/tests/d2_update_mgr_unittests.cc +++ b/src/bin/d2/tests/d2_update_mgr_unittests.cc @@ -14,7 +14,6 @@ #include <d2/simple_add.h> #include <d2/simple_remove.h> #include <process/testutils/d_test_stubs.h> -#include <util/time_utilities.h> #include <gtest/gtest.h> #include <algorithm> diff --git a/src/lib/dhcp_ddns/ncr_msg.h b/src/lib/dhcp_ddns/ncr_msg.h index 7c332d5366..148f87a510 100644 --- a/src/lib/dhcp_ddns/ncr_msg.h +++ b/src/lib/dhcp_ddns/ncr_msg.h @@ -18,7 +18,6 @@ #include <dns/name.h> #include <exceptions/exceptions.h> #include <util/buffer.h> -#include <util/time_utilities.h> #include <time.h> #include <string> diff --git a/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc b/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc index 84036533ce..84c8bde45b 100644 --- a/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc +++ b/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc @@ -12,7 +12,6 @@ #include <dhcp_ddns/ncr_io.h> #include <dhcp_ddns/ncr_udp.h> #include <util/multi_threading_mgr.h> -#include <util/time_utilities.h> #include <test_utils.h> #include <boost/asio/ip/udp.hpp> diff --git a/src/lib/dhcp_ddns/tests/ncr_unittests.cc b/src/lib/dhcp_ddns/tests/ncr_unittests.cc index 695f3b76ff..ef77521d75 100644 --- a/src/lib/dhcp_ddns/tests/ncr_unittests.cc +++ b/src/lib/dhcp_ddns/tests/ncr_unittests.cc @@ -9,7 +9,6 @@ #include <dhcp_ddns/ncr_io.h> #include <dhcp/duid.h> #include <dhcp/hwaddr.h> -#include <util/time_utilities.h> #include <testutils/gtest_utils.h> #include <gtest/gtest.h> diff --git a/src/lib/dns/tests/message_unittest.cc b/src/lib/dns/tests/message_unittest.cc index c2e4617b0b..41afe70546 100644 --- a/src/lib/dns/tests/message_unittest.cc +++ b/src/lib/dns/tests/message_unittest.cc @@ -13,7 +13,6 @@ #include <exceptions/exceptions.h> #include <util/buffer.h> -#include <util/time_utilities.h> #include <util/unittests/testdata.h> #include <util/unittests/textdata.h> diff --git a/src/lib/dns/tests/rdata_rrsig_unittest.cc b/src/lib/dns/tests/rdata_rrsig_unittest.cc index 06f8b187a3..2f69e035ba 100644 --- a/src/lib/dns/tests/rdata_rrsig_unittest.cc +++ b/src/lib/dns/tests/rdata_rrsig_unittest.cc @@ -9,7 +9,6 @@ #include <exceptions/exceptions.h> #include <util/buffer.h> -#include <util/time_utilities.h> #include <dns/messagerenderer.h> #include <dns/rdata.h> #include <dns/rdataclass.h> diff --git a/src/lib/dns/tests/rdata_tkey_unittest.cc b/src/lib/dns/tests/rdata_tkey_unittest.cc index 08a91a1326..59d6b3bc2e 100644 --- a/src/lib/dns/tests/rdata_tkey_unittest.cc +++ b/src/lib/dns/tests/rdata_tkey_unittest.cc @@ -11,7 +11,6 @@ #include <exceptions/exceptions.h> #include <util/buffer.h> -#include <util/time_utilities.h> #include <dns/exceptions.h> #include <dns/messagerenderer.h> #include <dns/rdata.h> diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am index 04f722fd8b..8413086355 100644 --- a/src/lib/util/Makefile.am +++ b/src/lib/util/Makefile.am @@ -34,7 +34,6 @@ libkea_util_la_SOURCES += stopwatch.cc stopwatch.h libkea_util_la_SOURCES += stopwatch_impl.cc stopwatch_impl.h libkea_util_la_SOURCES += strutil.h strutil.cc libkea_util_la_SOURCES += thread_pool.h -libkea_util_la_SOURCES += time_utilities.h time_utilities.cc libkea_util_la_SOURCES += triplet.h libkea_util_la_SOURCES += unlock_guard.h libkea_util_la_SOURCES += versioned_csv_file.h versioned_csv_file.cc @@ -80,7 +79,6 @@ libkea_util_include_HEADERS = \ stopwatch_impl.h \ strutil.h \ thread_pool.h \ - time_utilities.h \ triplet.h \ unlock_guard.h \ versioned_csv_file.h \ diff --git a/src/lib/util/tests/Makefile.am b/src/lib/util/tests/Makefile.am index cea80c19a1..6a107a5910 100644 --- a/src/lib/util/tests/Makefile.am +++ b/src/lib/util/tests/Makefile.am @@ -45,7 +45,6 @@ run_unittests_SOURCES += staged_value_unittest.cc run_unittests_SOURCES += state_model_unittest.cc run_unittests_SOURCES += strutil_unittest.cc run_unittests_SOURCES += thread_pool_unittest.cc -run_unittests_SOURCES += time_utilities_unittest.cc run_unittests_SOURCES += triplet_unittest.cc run_unittests_SOURCES += range_utilities_unittest.cc run_unittests_SOURCES += readwrite_mutex_unittest.cc diff --git a/src/lib/util/tests/time_utilities_unittest.cc b/src/lib/util/tests/time_utilities_unittest.cc deleted file mode 100644 index 1637a7a19e..0000000000 --- a/src/lib/util/tests/time_utilities_unittest.cc +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (C) 2010-2015 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#include <config.h> - -#include <string> - -#include <time.h> - -#include <util/time_utilities.h> - -#include <gtest/gtest.h> - -using namespace std; -using namespace isc::util; - -// See time_utilities.cc -namespace isc { -namespace util { -namespace detail { -extern int64_t (*gettimeFunction)(); -} -} -} - -namespace { - -class DNSSECTimeTest : public ::testing::Test { -protected: - ~DNSSECTimeTest() { - detail::gettimeFunction = NULL; - } -}; - -TEST_F(DNSSECTimeTest, fromText) { - // In most cases (in practice) the 32-bit and 64-bit versions should - // behave identically, so we'll mainly test the 32-bit version, which - // will be more commonly used in actual code (because many of the wire - // format time field are 32-bit). The subtle cases where these two - // return different values will be tested at the end of this test case. - - // These are bogus and should be rejected - EXPECT_THROW(timeFromText32("2011 101120000"), InvalidTime); - EXPECT_THROW(timeFromText32("201101011200-0"), InvalidTime); - - // Short length (or "decimal integer" version of representation; - // it's valid per RFC4034, but is not supported in this implementation) - EXPECT_THROW(timeFromText32("20100223"), InvalidTime); - - // Leap year checks - EXPECT_THROW(timeFromText32("20110229120000"), InvalidTime); - EXPECT_THROW(timeFromText32("21000229120000"), InvalidTime); - EXPECT_NO_THROW(timeFromText32("20000229120000")); - EXPECT_NO_THROW(timeFromText32("20120229120000")); - - // unusual case: this implementation allows SS=60 for "leap seconds" - EXPECT_NO_THROW(timeFromText32("20110101120060")); - - // Out of range parameters - EXPECT_THROW(timeFromText32("19100223214617"), InvalidTime); // YY<1970 - EXPECT_THROW(timeFromText32("20110001120000"), InvalidTime); // MM=00 - EXPECT_THROW(timeFromText32("20111301120000"), InvalidTime); // MM=13 - EXPECT_THROW(timeFromText32("20110100120000"), InvalidTime); // DD=00 - EXPECT_THROW(timeFromText32("20110132120000"), InvalidTime); // DD=32 - EXPECT_THROW(timeFromText32("20110431120000"), InvalidTime); // 'Apr31' - EXPECT_THROW(timeFromText32("20110101250000"), InvalidTime); // HH=25 - EXPECT_THROW(timeFromText32("20110101126000"), InvalidTime); // mm=60 - EXPECT_THROW(timeFromText32("20110101120061"), InvalidTime); // SS=61 - - // Feb 7, 06:28:15 UTC 2106 is the possible maximum time that can be - // represented as an unsigned 32bit integer without overflow. - EXPECT_EQ(4294967295LU, timeFromText32("21060207062815")); - - // After that, timeFromText32() should start returning the second count - // modulo 2^32. - EXPECT_EQ(0, timeFromText32("21060207062816")); - EXPECT_EQ(10, timeFromText32("21060207062826")); - - // On the other hand, the 64-bit version should return monotonically - // increasing counters. - EXPECT_EQ(4294967296LL, timeFromText64("21060207062816")); - EXPECT_EQ(4294967306LL, timeFromText64("21060207062826")); -} - -// This helper templated function tells timeToText32 a faked current time. -// The template parameter is that faked time in the form of int64_t seconds -// since epoch. -template <int64_t NOW> -int64_t -testGetTime() { - return (NOW); -} - -// Seconds since epoch for the year 10K eve. Commonly used in some tests -// below. -const uint64_t YEAR10K_EVE = 253402300799LL; - -TEST_F(DNSSECTimeTest, toText) { - // Check a basic case with the default (normal) gettimeFunction - // based on the "real current time". - // Note: this will fail after year 2078, but at that point we won't use - // this program anyway:-) - EXPECT_EQ("20100311233000", timeToText32(1268350200)); - - // Set the current time to: Feb 18 09:04:14 UTC 2012 (an arbitrary choice - // in the range of the first half of uint32 since epoch). - detail::gettimeFunction = testGetTime<1329555854LL>; - - // Test the "year 2038" problem. - // Check the result of toText() for "INT_MIN" in int32_t. It's in the - // 68-year range from the faked current time, so the result should be - // in year 2038, instead of 1901. - EXPECT_EQ("20380119031408", timeToText64(0x80000000L)); - EXPECT_EQ("20380119031408", timeToText32(0x80000000L)); - - // A controversial case: what should we do with "-1"? It's out of range - // in future, but according to RFC time before epoch doesn't seem to be - // considered "in-range" either. Our toText() implementation handles - // this range as a special case and always treats them as future time - // until year 2038. This won't be a real issue in practice, though, - // since such too large values won't be used in actual deployment by then. - EXPECT_EQ("21060207062815", timeToText32(0xffffffffL)); - - // After the singular point of year 2038, the first half of uint32 can - // point to a future time. - // Set the current time to: Apr 1 00:00:00 UTC 2038: - detail::gettimeFunction = testGetTime<2153692800LL>; - // then time "10" is Feb 7 06:28:26 UTC 2106 - EXPECT_EQ("21060207062826", timeToText32(10)); - // in 64-bit, it's 2^32 + 10 - EXPECT_EQ("21060207062826", timeToText64(0x10000000aLL)); - - // After year 2106, the upper half of uint32 can point to past time - // (as it should). - detail::gettimeFunction = testGetTime<0x10000000aLL>; - EXPECT_EQ("21060207062815", timeToText32(0xffffffffL)); - - // Try very large time value. Actually it's the possible farthest time - // that can be represented in the form of YYYYMMDDHHmmSS. - EXPECT_EQ("99991231235959", timeToText64(YEAR10K_EVE)); - detail::gettimeFunction = testGetTime<YEAR10K_EVE - 10>; - EXPECT_EQ("99991231235959", timeToText32(4294197631LU)); -} - -TEST_F(DNSSECTimeTest, overflow) { - // Jan 1, Year 10,000. - EXPECT_THROW(timeToText64(253402300800LL), InvalidTime); - detail::gettimeFunction = testGetTime<YEAR10K_EVE - 10>; - EXPECT_THROW(timeToText32(4294197632LU), InvalidTime); -} - -} diff --git a/src/lib/util/time_utilities.cc b/src/lib/util/time_utilities.cc deleted file mode 100644 index 5da1db757e..0000000000 --- a/src/lib/util/time_utilities.cc +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (C) 2010-2016 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#include <config.h> - -#include <stdint.h> - -#include <sys/time.h> - -#include <string> -#include <iomanip> -#include <iostream> -#include <sstream> - -#include <stdio.h> -#include <time.h> - -#include <exceptions/exceptions.h> - -#include <util/time_utilities.h> - -using namespace std; - -namespace { -int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - -inline bool -isLeap(const int y) { - return ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0); -} - -unsigned int -yearSecs(const int year) { - return ((isLeap(year) ? 366 : 365 ) * 86400); -} - -unsigned int -monthSecs(const int month, const int year) { - return ((days[month] + ((month == 1 && isLeap(year)) ? 1 : 0 )) * 86400); -} -} - -namespace isc { -namespace util { - -string -timeToText64(uint64_t value) { - struct tm tm; - unsigned int secs; - - // We cannot rely on gmtime() because time_t may not be of 64 bit - // integer. The following conversion logic is borrowed from BIND 9. - tm.tm_year = 70; - while ((secs = yearSecs(tm.tm_year + 1900)) <= value) { - value -= secs; - ++tm.tm_year; - if (tm.tm_year + 1900 > 9999) { - isc_throw(InvalidTime, - "Time value out of range (year > 9999): " << - tm.tm_year + 1900); - } - } - tm.tm_mon = 0; - while ((secs = monthSecs(tm.tm_mon, tm.tm_year + 1900)) <= value) { - value -= secs; - tm.tm_mon++; - } - tm.tm_mday = 1; - while (86400 <= value) { - value -= 86400; - ++tm.tm_mday; - } - tm.tm_hour = 0; - while (3600 <= value) { - value -= 3600; - ++tm.tm_hour; - } - tm.tm_min = 0; - while (60 <= value) { - value -= 60; - ++tm.tm_min; - } - tm.tm_sec = value; // now t < 60, so this substitution is safe. - - ostringstream oss; - oss << setfill('0') - << setw(4) << tm.tm_year + 1900 - << setw(2) << tm.tm_mon + 1 - << setw(2) << tm.tm_mday - << setw(2) << tm.tm_hour - << setw(2) << tm.tm_min - << setw(2) << tm.tm_sec; - return (oss.str()); -} - -// timeToText32() below uses the current system time. To test it with -// unusual current time values we introduce the following function pointer; -// when it's non NULL, we call it to get the (normally faked) current time. -// Otherwise we use the standard gettimeofday(2). This hook is specifically -// intended for testing purposes, so, even if it's visible outside of this -// library, it's not even declared in a header file. -namespace detail { -int64_t (*gettimeFunction)() = NULL; - -int64_t -gettimeWrapper() { - if (gettimeFunction != NULL) { - return (gettimeFunction()); - } - - struct timeval now; - gettimeofday(&now, NULL); - - return (static_cast<int64_t>(now.tv_sec)); -} -} - -string -timeToText32(const uint32_t value) { - // We first adjust the time to the closest epoch based on the current time. - // Note that the following variables must be signed in order to handle - // time until year 2038 correctly. - const int64_t start = detail::gettimeWrapper() - 0x7fffffff; - int64_t base = 0; - int64_t t; - while ((t = (base + value)) < start) { - base += 0x100000000LL; - } - - // Then convert it to text. - return (timeToText64(t)); -} - -namespace { -const size_t DATE_LEN = 14; // YYYYMMDDHHmmSS - -inline uint64_t ull(const int c) { return (static_cast<uint64_t>(c)); } - -inline void -checkRange(const unsigned min, const unsigned max, const unsigned value, - const string& valname) -{ - if ((value >= min) && (value <= max)) { - return; - } - isc_throw(InvalidTime, "Invalid " << valname << " value: " << value); -} -} - -uint64_t -timeFromText64(const string& time_txt) { - // Confirm the source only consists digits. sscanf() allows some - // minor exceptions. - for (string::size_type i = 0; i < time_txt.length(); ++i) { - if (!isdigit(time_txt.at(i))) { - isc_throw(InvalidTime, "Couldn't convert non-numeric time value: " - << time_txt); - } - } - - unsigned year, month, day, hour, minute, second; - if (time_txt.length() != DATE_LEN || - sscanf(time_txt.c_str(), "%4u%2u%2u%2u%2u%2u", - &year, &month, &day, &hour, &minute, &second) != 6) - { - isc_throw(InvalidTime, "Couldn't convert time value: " << time_txt); - } - - checkRange(1970, 9999, year, "year"); - checkRange(1, 12, month, "month"); - checkRange(1, days[month - 1] + ((month == 2 && isLeap(year)) ? 1 : 0), - day, "day"); - checkRange(0, 23, hour, "hour"); - checkRange(0, 59, minute, "minute"); - checkRange(0, 60, second, "second"); // 60 == leap second. - - uint64_t timeval = second + (ull(60) * minute) + (ull(3600) * hour) + - ((day - 1) * ull(86400)); - for (unsigned m = 0; m < (month - 1); ++m) { - timeval += days[m] * ull(86400); - } - if (isLeap(year) && month > 2) { - timeval += ull(86400); - } - for (unsigned y = 1970; y < year; ++y) { - timeval += ((isLeap(y) ? 366 : 365) * ull(86400)); - } - - return (timeval); -} - -uint32_t -timeFromText32(const string& time_txt) { - // The implicit conversion from uint64_t to uint32_t should just work here, - // because we only need to drop higher 32 bits. - return (timeFromText64(time_txt)); -} - -} -} diff --git a/src/lib/util/time_utilities.h b/src/lib/util/time_utilities.h deleted file mode 100644 index 226a632dd0..0000000000 --- a/src/lib/util/time_utilities.h +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright (C) 2009-2015 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef TIME_UTILITIES_H -#define TIME_UTILITIES_H 1 - -#include <string> - -#include <sys/types.h> -#include <stdint.h> - -#include <exceptions/exceptions.h> - -// -// Note: this helper module isn't specific to the DNS protocol per se. -// We should probably move this to somewhere else, possibly in some common -// utility area. -// - -namespace isc { -namespace util { - -/// -/// \brief A standard DNS (or ISC) module exception that is thrown if -/// a time conversion function encounters bad input -/// -class InvalidTime : public Exception { -public: - InvalidTime(const char* file, size_t line, const char* what) : - isc::Exception(file, line, what) {} -}; - -namespace detail { -/// Return the current time in seconds -/// -/// This function returns the "current" time in seconds from epoch -/// (00:00:00 January 1, 1970) as a 64-bit signed integer. The return -/// value can represent a point of time before epoch as a negative number. -/// -/// This function is provided to help test time conscious implementations -/// such as DNSSEC and TSIG signatures. It is difficult to test them with -/// an unusual or a specifically chosen "current" via system-provided -/// library functions to get time. This function acts as a straightforward -/// wrapper of such a library function, but provides test code with a hook -/// to return an arbitrary time value: if \c isc::util::detail::gettimeFunction -/// is set to a pointer of function that returns 64-bit signed integer, -/// \c gettimeWrapper() calls that function instead of the system library. -/// -/// This hook variable is specifically intended for testing purposes, so, -/// even if it's visible outside of this library, it's not even declared in a -/// header file. -/// -/// If the implementation doesn't need to be tested with faked current time, -/// it should simply use the system supplied library function instead of -/// this one. -int64_t gettimeWrapper(); -} - -/// -/// \name DNSSEC time conversion functions. -/// -/// These functions convert between times represented in seconds (in integer) -/// since epoch and those in the textual form used in the RRSIG records. -/// For integers we provide both 32-bit and 64-bit versions. -/// The RRSIG expiration and inception fields are both 32-bit unsigned -/// integers, so 32-bit versions would be more useful for protocol operations. -/// However, with 32-bit integers we need to take into account wrap-around -/// points and compare values using the serial number arithmetic as specified -/// in RFC4034, which would be more error prone. We therefore provide 64-bit -/// versions, too. -/// -/// The timezone is always UTC for these functions. -//@{ -/// Convert textual DNSSEC time to integer, 64-bit version. -/// -/// The textual form must only consist of digits and be in the form of -/// YYYYMMDDHHmmSS, where: -/// - YYYY must be between 1970 and 9999 -/// - MM must be between 01 and 12 -/// - DD must be between 01 and 31 and must be a valid day for the month -/// represented in 'MM'. For example, if MM is 04, DD cannot be 31. -/// DD can be 29 when MM is 02 only when YYYY is a leap year. -/// - HH must be between 00 and 23 -/// - mm must be between 00 and 59 -/// - SS must be between 00 and 60 -/// -/// For all fields the range includes the begin and end values. Note that -/// 60 is allowed for 'SS', intending a leap second, although in real operation -/// it's unlikely to be specified. -/// -/// If the given text is valid, this function converts it to an unsigned -/// 64-bit number of seconds since epoch (1 January 1970 00:00:00) and returns -/// the converted value. 64 bits are sufficient to represent all possible -/// values for the valid format uniquely, so there is no overflow. -/// -/// \note RFC4034 also defines the textual form of an unsigned decimal integer -/// for the corresponding time in seconds. This function doesn't support -/// this form, and if given it throws an exception of class \c InvalidTime. -/// -/// \exception InvalidTime The given textual representation is invalid. -/// -/// \param time_txt Textual time in the form of YYYYMMDDHHmmSS -/// \return Seconds since epoch corresponding to \c time_txt -uint64_t -timeFromText64(const std::string& time_txt); - -/// Convert textual DNSSEC time to integer, 32-bit version. -/// -/// This version is the same as \c timeFromText64() except that the return -/// value is wrapped around to an unsigned 32-bit integer, simply dropping -/// the upper 32 bits. -uint32_t -timeFromText32(const std::string& time_txt); - -/// Convert integral DNSSEC time to textual form, 64-bit version. -/// -/// This function takes an integer that would be seconds since epoch and -/// converts it in the form of YYYYMMDDHHmmSS. For example, if \c value is -/// 0, it returns "19700101000000". If the value corresponds to a point -/// of time on and after year 10,000, which cannot be represented in the -/// YYYY... form, an exception of class \c InvalidTime will be thrown. -/// -/// \exception InvalidTime The given time specifies on or after year 10,000. -/// \exception Other A standard exception, if resource allocation for the -/// returned text fails. -/// -/// \param value Seconds since epoch to be converted. -/// \return Textual representation of \c value in the form of YYYYMMDDHHmmSS. -std::string -timeToText64(uint64_t value); - -/// Convert integral DNSSEC time to textual form, 32-bit version. -/// -/// This version is the same as \c timeToText64(), but the time value -/// is expected to be the lower 32 bits of the full 64-bit value. -/// These two will be different on and after a certain point of time -/// in year 2106, so this function internally resolves the ambiguity -/// using the current system time at the time of function call; -/// it first identifies the range of [N*2^32 - 2^31, N*2^32 + 2^31) -/// that contains the current time, and interprets \c value in the context -/// of that range. It then applies the same process as \c timeToText64(). -/// -/// There is one important exception in this processing, however. -/// Until 19 Jan 2038 03:14:08 (2^31 seconds since epoch), this range -/// would contain time before epoch. In order to ensure the returned -/// value is also a valid input to \c timeFromText, this function uses -/// a special range [0, 2^32) until that time. As a result, all upper -/// half of the 32-bit values are treated as a future time. For example, -/// 2^32-1 (the highest value in 32-bit unsigned integers) will be converted -/// to "21060207062815", instead of "19691231235959". -std::string -timeToText32(const uint32_t value); - -//@} -} -} - -#endif // TIME_UTILITIES_H - -// Local Variables: -// mode: c++ -// End: |