util: add literal operators for duration types

Change-Id: I007fa61c80e535c6e4b12e85a32eeeee62fecc3c
Refs: #4468
diff --git a/src/interest.hpp b/src/interest.hpp
index 15a1501..b1c3769 100644
--- a/src/interest.hpp
+++ b/src/interest.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -35,7 +35,7 @@
 /** @var const unspecified_duration_type DEFAULT_INTEREST_LIFETIME;
  *  @brief default value for InterestLifetime
  */
-const time::milliseconds DEFAULT_INTEREST_LIFETIME = time::milliseconds(4000);
+const time::milliseconds DEFAULT_INTEREST_LIFETIME = 4_s;
 
 /** @brief represents an Interest packet
  */
diff --git a/src/mgmt/dispatcher.cpp b/src/mgmt/dispatcher.cpp
index 3220864..70661c1 100644
--- a/src/mgmt/dispatcher.cpp
+++ b/src/mgmt/dispatcher.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -28,7 +28,7 @@
 namespace ndn {
 namespace mgmt {
 
-const time::milliseconds DEFAULT_FRESHNESS_PERIOD = time::milliseconds(1000);
+const time::milliseconds DEFAULT_FRESHNESS_PERIOD = 1_s;
 
 Authorization
 makeAcceptAllAuthorization()
diff --git a/src/mgmt/status-dataset-context.cpp b/src/mgmt/status-dataset-context.cpp
index dbf6774..2abbaa7 100644
--- a/src/mgmt/status-dataset-context.cpp
+++ b/src/mgmt/status-dataset-context.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -24,7 +24,7 @@
 namespace ndn {
 namespace mgmt {
 
-const time::milliseconds DEFAULT_STATUS_DATASET_FRESHNESS_PERIOD = time::milliseconds(1000);
+const time::milliseconds DEFAULT_STATUS_DATASET_FRESHNESS_PERIOD = 1_s;
 
 const Name&
 StatusDatasetContext::getPrefix() const
@@ -113,7 +113,6 @@
   }
 
   m_state = State::FINALIZED;
-
   m_nackSender(resp);
 }
 
diff --git a/src/net/detail/network-monitor-impl-osx.cpp b/src/net/detail/network-monitor-impl-osx.cpp
index ddd4119..7af5337 100644
--- a/src/net/detail/network-monitor-impl-osx.cpp
+++ b/src/net/detail/network-monitor-impl-osx.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -187,7 +187,7 @@
 NetworkMonitorImplOsx::scheduleCfLoop()
 {
   // poll each second for new events
-  m_cfLoopEvent = m_scheduler.scheduleEvent(time::seconds(1), [this] {
+  m_cfLoopEvent = m_scheduler.scheduleEvent(1_s, [this] {
     // this should dispatch ready events and exit
     CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
     scheduleCfLoop();
diff --git a/src/net/dns.hpp b/src/net/dns.hpp
index 5e22a84..961e5bd 100644
--- a/src/net/dns.hpp
+++ b/src/net/dns.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -94,7 +94,7 @@
              const ErrorCallback& onError,
              boost::asio::io_service& ioService,
              const AddressSelector& addressSelector = AnyAddress(),
-             time::nanoseconds timeout = time::seconds(4));
+             time::nanoseconds timeout = 4_s);
 
 /** \brief Synchronously resolve host
  *
diff --git a/src/security/command-interest-signer.cpp b/src/security/command-interest-signer.cpp
index 3704a7e..70e80a1 100644
--- a/src/security/command-interest-signer.cpp
+++ b/src/security/command-interest-signer.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -35,7 +35,7 @@
 {
   time::milliseconds timestamp = time::toUnixTimestamp(time::system_clock::now());
   if (timestamp <= m_lastUsedTimestamp) {
-    timestamp = m_lastUsedTimestamp + time::milliseconds(1);
+    timestamp = m_lastUsedTimestamp + 1_ms;
   }
   m_lastUsedTimestamp = timestamp;
 
diff --git a/src/security/v2/certificate-cache.cpp b/src/security/v2/certificate-cache.cpp
index be2b084..9726b7e 100644
--- a/src/security/v2/certificate-cache.cpp
+++ b/src/security/v2/certificate-cache.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -28,11 +28,10 @@
 
 NDN_LOG_INIT(ndn.security.v2.CertificateCache);
 
-const time::nanoseconds&
+time::nanoseconds
 CertificateCache::getDefaultLifetime()
 {
-  static time::nanoseconds lifetime = time::seconds(3600);
-  return lifetime;
+  return 1_h;
 }
 
 CertificateCache::CertificateCache(const time::nanoseconds& maxLifetime)
diff --git a/src/security/v2/certificate-cache.hpp b/src/security/v2/certificate-cache.hpp
index a5109a8..53157b4 100644
--- a/src/security/v2/certificate-cache.hpp
+++ b/src/security/v2/certificate-cache.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -118,7 +118,7 @@
   refresh();
 
 public:
-  static const time::nanoseconds&
+  static time::nanoseconds
   getDefaultLifetime();
 
 private:
diff --git a/src/security/v2/certificate-storage.cpp b/src/security/v2/certificate-storage.cpp
index d1638d9..a4d482e 100644
--- a/src/security/v2/certificate-storage.cpp
+++ b/src/security/v2/certificate-storage.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -26,8 +26,8 @@
 namespace v2 {
 
 CertificateStorage::CertificateStorage()
-  : m_verifiedCertCache(time::hours(1))
-  , m_unverifiedCertCache(time::minutes(5))
+  : m_verifiedCertCache(1_h)
+  , m_unverifiedCertCache(5_min)
 {
 }
 
diff --git a/src/security/v2/key-chain.cpp b/src/security/v2/key-chain.cpp
index 9f496a1..348f214 100644
--- a/src/security/v2/key-chain.cpp
+++ b/src/security/v2/key-chain.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -549,7 +549,7 @@
 
   // set metainfo
   certificate.setContentType(tlv::ContentType_Key);
-  certificate.setFreshnessPeriod(time::hours(1));
+  certificate.setFreshnessPeriod(1_h);
 
   // set content
   certificate.setContent(key.getPublicKey().data(), key.getPublicKey().size());
@@ -559,7 +559,7 @@
   // Note time::system_clock::max() or other NotAfter date results in incorrect encoded value
   // because of overflow during conversion to boost::posix_time::ptime (bug #3915).
   signatureInfo.setValidityPeriod(ValidityPeriod(time::system_clock::TimePoint(),
-                                                 time::system_clock::now() + time::days(20 * 365)));
+                                                 time::system_clock::now() + 20 * 365_days));
 
   sign(certificate, SigningInfo(key).setSignatureInfo(signatureInfo));
 
diff --git a/src/security/v2/validation-policy-command-interest.hpp b/src/security/v2/validation-policy-command-interest.hpp
index 96a9012..84a7be8 100644
--- a/src/security/v2/validation-policy-command-interest.hpp
+++ b/src/security/v2/validation-policy-command-interest.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -62,7 +62,7 @@
      *  Setting this option to 0 or negative causes the validator to require exactly same
      *  timestamp as the system clock, which most likely rejects all command Interests.
      */
-    time::nanoseconds gracePeriod = time::seconds(120);
+    time::nanoseconds gracePeriod = 2_min;
 
     /** \brief max number of distinct public keys of which to record the last timestamp
      *
@@ -88,7 +88,7 @@
      *  Setting this option to 0 or negative makes last timestamp records expire immediately
      *  and causes every command Interest to be processed as initial.
      */
-    time::nanoseconds recordLifetime = time::hours(1);
+    time::nanoseconds recordLifetime = 1_h;
   };
 
   /** \brief constructor
@@ -157,5 +157,4 @@
 } // namespace security
 } // namespace ndn
 
-
 #endif // NDN_SECURITY_V2_VALIDATION_POLICY_COMMAND_INTEREST_HPP
diff --git a/src/security/v2/validation-policy-config.cpp b/src/security/v2/validation-policy-config.cpp
index c41a47f..0f0bb84 100644
--- a/src/security/v2/validation-policy-config.cpp
+++ b/src/security/v2/validation-policy-config.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -241,11 +241,11 @@
 
   switch (unit) {
     case 'h':
-      return time::duration_cast<time::nanoseconds>(time::hours(refreshPeriod));
+      return time::hours(refreshPeriod);
     case 'm':
-      return time::duration_cast<time::nanoseconds>(time::minutes(refreshPeriod));
+      return time::minutes(refreshPeriod);
     case 's':
-      return time::duration_cast<time::nanoseconds>(time::seconds(refreshPeriod));
+      return time::seconds(refreshPeriod);
     default:
       BOOST_THROW_EXCEPTION(Error(std::string("Wrong time unit: ") + unit));
   }
@@ -254,7 +254,7 @@
 time::nanoseconds
 ValidationPolicyConfig::getDefaultRefreshPeriod()
 {
-  return time::duration_cast<time::nanoseconds>(time::seconds(3600));
+  return 1_h;
 }
 
 void
diff --git a/src/security/validity-period.cpp b/src/security/validity-period.cpp
index c30497b..0cd4555 100644
--- a/src/security/validity-period.cpp
+++ b/src/security/validity-period.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -40,7 +40,7 @@
 using boost::chrono::time_point_cast;
 
 ValidityPeriod::ValidityPeriod()
-  : ValidityPeriod(time::system_clock::TimePoint() + time::nanoseconds(1),
+  : ValidityPeriod(time::system_clock::TimePoint() + 1_ns,
                    time::system_clock::TimePoint())
 {
 }
diff --git a/src/util/notification-stream.hpp b/src/util/notification-stream.hpp
index 1c7887e..5dcf25a 100644
--- a/src/util/notification-stream.hpp
+++ b/src/util/notification-stream.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017 Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018 Regents of the University of California,
  *                         Arizona Board of Regents,
  *                         Colorado State University,
  *                         University Pierre & Marie Curie, Sorbonne University,
@@ -28,11 +28,10 @@
 #ifndef NDN_UTIL_NOTIFICATION_STREAM_HPP
 #define NDN_UTIL_NOTIFICATION_STREAM_HPP
 
-#include "../name.hpp"
-#include "../face.hpp"
-#include "../security/v2/key-chain.hpp"
-
 #include "concepts.hpp"
+#include "../face.hpp"
+#include "../name.hpp"
+#include "../security/v2/key-chain.hpp"
 
 namespace ndn {
 namespace util {
@@ -65,7 +64,7 @@
 
     shared_ptr<Data> data = make_shared<Data>(dataName);
     data->setContent(notification.wireEncode());
-    data->setFreshnessPeriod(time::seconds(1));
+    data->setFreshnessPeriod(1_s);
 
     m_keyChain.sign(*data);
     m_face.put(*data);
diff --git a/src/util/notification-subscriber.hpp b/src/util/notification-subscriber.hpp
index be36d31..2791ff5 100644
--- a/src/util/notification-subscriber.hpp
+++ b/src/util/notification-subscriber.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017 Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018 Regents of the University of California,
  *                         Arizona Board of Regents,
  *                         Colorado State University,
  *                         University Pierre & Marie Curie, Sorbonne University,
@@ -157,7 +157,7 @@
    *        User should add one or more handlers to onNotification, and invoke .start().
    */
   NotificationSubscriber(Face& face, const Name& prefix,
-                         time::milliseconds interestLifetime = time::seconds(60))
+                         time::milliseconds interestLifetime = 1_min)
     : NotificationSubscriberBase(face, prefix, interestLifetime)
   {
   }
diff --git a/src/util/segment-fetcher.hpp b/src/util/segment-fetcher.hpp
index cc9725a..cec29b7 100644
--- a/src/util/segment-fetcher.hpp
+++ b/src/util/segment-fetcher.hpp
@@ -93,7 +93,7 @@
  *     }
  *
  *     ...
- *     SegmentFetcher::fetch(face, Interest("/data/prefix", time::seconds(1000)),
+ *     SegmentFetcher::fetch(face, Interest("/data/prefix", 30_s),
  *                           validator,
  *                           bind(&afterFetchComplete, this, _1),
  *                           bind(&afterFetchError, this, _1, _2));
diff --git a/src/util/time.hpp b/src/util/time.hpp
index 29274a5..cf497af 100644
--- a/src/util/time.hpp
+++ b/src/util/time.hpp
@@ -53,6 +53,114 @@
   return d >= d.zero() ? d : -d;
 }
 
+} // namespace time
+
+inline namespace literals {
+inline namespace time_literals {
+
+constexpr time::days
+operator "" _day(unsigned long long days)
+{
+  return time::days{days};
+}
+
+constexpr time::duration<long double, time::days::period>
+operator "" _day(long double days)
+{
+  return time::duration<long double, time::days::period>{days};
+}
+
+constexpr time::days
+operator "" _days(unsigned long long days)
+{
+  return time::days{days};
+}
+
+constexpr time::duration<long double, time::days::period>
+operator "" _days(long double days)
+{
+  return time::duration<long double, time::days::period>{days};
+}
+
+constexpr time::hours
+operator "" _h(unsigned long long hrs)
+{
+  return time::hours{hrs};
+}
+
+constexpr time::duration<long double, time::hours::period>
+operator "" _h(long double hrs)
+{
+  return time::duration<long double, time::hours::period>{hrs};
+}
+
+constexpr time::minutes
+operator "" _min(unsigned long long mins)
+{
+  return time::minutes{mins};
+}
+
+constexpr time::duration<long double, time::minutes::period>
+operator "" _min(long double mins)
+{
+  return time::duration<long double, time::minutes::period>{mins};
+}
+
+constexpr time::seconds
+operator "" _s(unsigned long long secs)
+{
+  return time::seconds{secs};
+}
+
+constexpr time::duration<long double, time::seconds::period>
+operator "" _s(long double secs)
+{
+  return time::duration<long double, time::seconds::period>{secs};
+}
+
+constexpr time::milliseconds
+operator "" _ms(unsigned long long msecs)
+{
+  return time::milliseconds{msecs};
+}
+
+constexpr time::duration<long double, time::milliseconds::period>
+operator "" _ms(long double msecs)
+{
+  return time::duration<long double, time::milliseconds::period>{msecs};
+}
+
+constexpr time::microseconds
+operator "" _us(unsigned long long usecs)
+{
+  return time::microseconds{usecs};
+}
+
+constexpr time::duration<long double, time::microseconds::period>
+operator "" _us(long double usecs)
+{
+  return time::duration<long double, time::microseconds::period>{usecs};
+}
+
+constexpr time::nanoseconds
+operator "" _ns(unsigned long long nsecs)
+{
+  return time::nanoseconds{nsecs};
+}
+
+constexpr time::duration<long double, time::nanoseconds::period>
+operator "" _ns(long double nsecs)
+{
+  return time::duration<long double, time::nanoseconds::period>{nsecs};
+}
+
+} // inline namespace time_literals
+} // inline namespace literals
+
+namespace time {
+
+using namespace literals::time_literals;
+
 /**
  * \brief System clock
  *