util: fix time::toIsoString with Boost 1.73.0
Change-Id: Id8d65db9020c3efefab0453c83e39e5e2771ce3a
diff --git a/ndn-cxx/util/time.cpp b/ndn-cxx/util/time.cpp
index 170cb78..3f4f9db 100644
--- a/ndn-cxx/util/time.cpp
+++ b/ndn-cxx/util/time.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2020 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -130,10 +130,8 @@
using BptResolution =
#if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
nanoseconds;
-#elif defined(BOOST_DATE_TIME_HAS_MICROSECONDS)
- microseconds;
#else
- milliseconds;
+ microseconds;
#endif
constexpr auto unitsPerHour = duration_cast<BptResolution>(1_h).count();
diff --git a/tests/unit/util/time.t.cpp b/tests/unit/util/time.t.cpp
index 3f5f531..92699a9 100644
--- a/tests/unit/util/time.t.cpp
+++ b/tests/unit/util/time.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2019 Regents of the University of California.
+ * Copyright (c) 2013-2020 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -36,29 +36,29 @@
BOOST_AUTO_TEST_CASE(SystemClock)
{
system_clock::TimePoint value = system_clock::now();
- system_clock::TimePoint referenceTime = fromUnixTimestamp(milliseconds(1390966967032LL));
+ system_clock::TimePoint referenceTime = fromUnixTimestamp(1390966967032_ms);
- BOOST_CHECK_GT(value, referenceTime);
+ BOOST_TEST(value > referenceTime);
BOOST_CHECK_EQUAL(toIsoString(referenceTime), "20140129T034247.032000");
BOOST_CHECK_EQUAL(toString(referenceTime), "2014-01-29 03:42:47");
- BOOST_CHECK_EQUAL(toString(referenceTime), "2014-01-29 03:42:47");
// Unfortunately, not all systems has lv_LV locale installed :(
// BOOST_CHECK_EQUAL(toString(referenceTime, "%Y. gada %d. %B", std::locale("lv_LV.UTF-8")),
// "2014. gada 29. Janvāris");
-
BOOST_CHECK_EQUAL(toString(referenceTime, "%Y -- %d -- %B", std::locale("C")),
"2014 -- 29 -- January");
- BOOST_CHECK_EQUAL(fromIsoString("20140129T034247.032000"), referenceTime);
- BOOST_CHECK_EQUAL(fromIsoString("20140129T034247.032000Z"), referenceTime);
- BOOST_CHECK_EQUAL(fromString("2014-01-29 03:42:47"), fromUnixTimestamp(1390966967_s));
+ BOOST_TEST(fromIsoString("20140129T034247.032000") == referenceTime);
+ BOOST_TEST(fromIsoString("20140129T034247.032000Z") == referenceTime);
+ BOOST_TEST(fromIsoString("20140129T034247") != referenceTime);
+ BOOST_TEST(fromIsoString("20140129T034247") == fromUnixTimestamp(1390966967_s));
+ BOOST_TEST(fromString("2014-01-29 03:42:47") != referenceTime);
+ BOOST_TEST(fromString("2014-01-29 03:42:47") == fromUnixTimestamp(1390966967_s));
// Unfortunately, not all systems has lv_LV locale installed :(
// BOOST_CHECK_EQUAL(fromString("2014. gada 29. Janvāris", "%Y. gada %d. %B", std::locale("lv_LV.UTF-8")),
// fromUnixTimestamp(1390953600_s));
-
BOOST_CHECK_EQUAL(fromString("2014 -- 29 -- January", "%Y -- %d -- %B", std::locale("C")),
fromUnixTimestamp(1390953600_s));
}
@@ -71,6 +71,19 @@
BOOST_CHECK_GT(newValue, oldValue);
}
+BOOST_AUTO_TEST_CASE(SecondsClock)
+{
+ using SecTimePoint = boost::chrono::time_point<system_clock, seconds>;
+ SecTimePoint tp;
+ tp += 1596592240_s;
+
+ BOOST_TEST(toIsoString(tp) == "20200805T015040");
+ BOOST_TEST(toString(tp) == "2020-08-05 01:50:40");
+ BOOST_TEST(fromIsoString("20200805T015040") == tp);
+ BOOST_TEST(fromIsoString("20200805T015040.123456") != tp);
+ BOOST_TEST(fromString("2020-08-05 01:50:40") == tp);
+}
+
BOOST_AUTO_TEST_CASE(Abs)
{
BOOST_CHECK_EQUAL(abs(nanoseconds(24422)), nanoseconds(24422));