all: Refactoring work with time using boost::chrono

Now the library has two clocks: time::steady_clock and
time::system_clock, following (boost|std)::chrono.  In addition to
standard now() method, the library contains several helpers to convert
to/from UnixTimestamp (microsecond resolution) and IsoString (optional
microsecond resolution).  The IsoString conversions use
boost::posix_time routines, since boost::chrono supports extended IO
support only starting boost version 1.52 (Boost Chrono V2).

This commit breaks compatibility with previous API.  All time-related
Data/Interest calls must explicitly use time units to specify
FreshnessPeriod/InterestLifetime.

Brief usage/conversion guide:

- creation of time units does not support double/float types.  If
  necessary to create time unit from double, ``ndn::duration<double>`` (for
  seconds) needs to be used instead.  In some cases, this would also
  require ``ndn::duration_cast``, if the target is not ``ndn::nanoseconds``.
- ndn::getNow, ndn::ndn_getNowMilliseconds, ndn::time::now are all
  removed in favor of the now() method in a specific clock:

    * time::system_clock::now();
    * time::steady_clock::now();

- When necessary to convert system_clock::TimePoint to unix timestamp,
  ``time::toUnixTimestamp`` can be used.  This method return number of
  milliseconds since UNIX epoch as ``ndn::time::milliseconds`` type.
  Use count() method to obtain number as an integral value.

Change-Id: Icd688bc6766e008d60c3d2888173627874526e47
Refs: #1152
diff --git a/tests/util/test-io.cpp b/tests/util/test-io.cpp
index acbdc38..1e8b0bd 100644
--- a/tests/util/test-io.cpp
+++ b/tests/util/test-io.cpp
@@ -16,7 +16,9 @@
 {
   KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keychain;
 
-  Name identity("/TestIO/Basic/" + boost::lexical_cast<std::string>(time::now()));
+  Name identity("/TestIO/Basic");
+  identity.appendVersion();
+
   Name certName;
   BOOST_REQUIRE_NO_THROW(certName = keychain.createIdentity(identity));
   shared_ptr<IdentityCertificate> idCert;
diff --git a/tests/util/test-scheduler.cpp b/tests/util/test-scheduler.cpp
index 957ad98..66417da 100644
--- a/tests/util/test-scheduler.cpp
+++ b/tests/util/test-scheduler.cpp
@@ -21,7 +21,7 @@
     , count4(0)
   {
   }
-    
+
   void
   event1()
   {
@@ -47,7 +47,7 @@
   {
     ++count4;
   }
-  
+
   int count1;
   int count2;
   int count3;
@@ -56,22 +56,22 @@
 
 BOOST_FIXTURE_TEST_CASE(Events, SchedulerFixture)
 {
-  boost::asio::io_service io; 
+  boost::asio::io_service io;
 
   Scheduler scheduler(io);
-  scheduler.scheduleEvent(time::seconds(0.5), bind(&SchedulerFixture::event1, this));
-  
-  EventId i = scheduler.scheduleEvent(time::seconds(1.0), bind(&SchedulerFixture::event2, this));
+  scheduler.scheduleEvent(time::milliseconds(500), bind(&SchedulerFixture::event1, this));
+
+  EventId i = scheduler.scheduleEvent(time::seconds(1), bind(&SchedulerFixture::event2, this));
   scheduler.cancelEvent(i);
 
-  scheduler.scheduleEvent(time::seconds(0.25), bind(&SchedulerFixture::event3, this));
+  scheduler.scheduleEvent(time::milliseconds(250), bind(&SchedulerFixture::event3, this));
 
-  i = scheduler.scheduleEvent(time::seconds(0.05), bind(&SchedulerFixture::event2, this));
+  i = scheduler.scheduleEvent(time::milliseconds(50), bind(&SchedulerFixture::event2, this));
   scheduler.cancelEvent(i);
 
-  i = scheduler.schedulePeriodicEvent(time::seconds(1.5), time::seconds(0.5), bind(&SchedulerFixture::event4, this));
+  i = scheduler.schedulePeriodicEvent(time::milliseconds(1500), time::milliseconds(500), bind(&SchedulerFixture::event4, this));
   scheduler.scheduleEvent(time::seconds(4), bind(&Scheduler::cancelEvent, &scheduler, i));
-  
+
   io.run();
 
   BOOST_CHECK_EQUAL(count1, 1);
@@ -82,9 +82,9 @@
 
 BOOST_AUTO_TEST_CASE(CancelEmptyEvent)
 {
-  boost::asio::io_service io; 
+  boost::asio::io_service io;
   Scheduler scheduler(io);
-  
+
   EventId i;
   scheduler.cancelEvent(i);
 }
@@ -109,7 +109,7 @@
 
 BOOST_FIXTURE_TEST_CASE(SelfCancel, SelfCancelFixture)
 {
-  m_selfEventId = m_scheduler.scheduleEvent(time::seconds(0.1),
+  m_selfEventId = m_scheduler.scheduleEvent(time::milliseconds(100),
                                             bind(&SelfCancelFixture::cancelSelf, this));
 
   BOOST_REQUIRE_NO_THROW(m_io.run());
@@ -126,8 +126,8 @@
   void
   reschedule()
   {
-    EventId eventId = m_scheduler.scheduleEvent(time::seconds(0.1),
-                                                  bind(&SelfRescheduleFixture::reschedule, this));
+    EventId eventId = m_scheduler.scheduleEvent(time::milliseconds(100),
+                                                bind(&SelfRescheduleFixture::reschedule, this));
     m_scheduler.cancelEvent(m_selfEventId);
     m_selfEventId = eventId;
 
@@ -141,11 +141,11 @@
   reschedule2()
   {
     m_scheduler.cancelEvent(m_selfEventId);
-    
-    
+
+
     if(m_count < 5)
       {
-        m_selfEventId = m_scheduler.scheduleEvent(time::seconds(0.1),
+        m_selfEventId = m_scheduler.scheduleEvent(time::milliseconds(100),
                                                   bind(&SelfRescheduleFixture::reschedule2, this));
         m_count++;
       }
@@ -156,23 +156,23 @@
   {
     m_count++;
   }
-  
+
   void
   reschedule3()
   {
     m_scheduler.cancelEvent(m_selfEventId);
-    
-    m_scheduler.scheduleEvent(time::seconds(0.1),
+
+    m_scheduler.scheduleEvent(time::milliseconds(100),
                               bind(&SelfRescheduleFixture::doNothing, this));
-    m_scheduler.scheduleEvent(time::seconds(0.1),
+    m_scheduler.scheduleEvent(time::milliseconds(100),
                               bind(&SelfRescheduleFixture::doNothing, this));
-    m_scheduler.scheduleEvent(time::seconds(0.1),
+    m_scheduler.scheduleEvent(time::milliseconds(100),
                               bind(&SelfRescheduleFixture::doNothing, this));
-    m_scheduler.scheduleEvent(time::seconds(0.1),
+    m_scheduler.scheduleEvent(time::milliseconds(100),
                               bind(&SelfRescheduleFixture::doNothing, this));
-    m_scheduler.scheduleEvent(time::seconds(0.1),
+    m_scheduler.scheduleEvent(time::milliseconds(100),
                               bind(&SelfRescheduleFixture::doNothing, this));
-    m_scheduler.scheduleEvent(time::seconds(0.1),
+    m_scheduler.scheduleEvent(time::milliseconds(100),
                               bind(&SelfRescheduleFixture::doNothing, this));
   }
 
@@ -180,7 +180,7 @@
   Scheduler m_scheduler;
   EventId m_selfEventId;
   int m_count;
-  
+
 };
 
 BOOST_FIXTURE_TEST_CASE(Reschedule, SelfRescheduleFixture)
diff --git a/tests/util/test-time.cpp b/tests/util/test-time.cpp
index be4cc77..6351bb1 100644
--- a/tests/util/test-time.cpp
+++ b/tests/util/test-time.cpp
@@ -11,15 +11,27 @@
 
 BOOST_AUTO_TEST_SUITE(TestTime)
 
-BOOST_AUTO_TEST_CASE (Simple)
+BOOST_AUTO_TEST_CASE (SystemClock)
 {
-  MillisecondsSince1970 value = getNowMilliseconds();
-  BOOST_CHECK_GT(value, 1390966967032);
+  time::system_clock::TimePoint value = time::system_clock::now();
+  time::system_clock::TimePoint referenceTime =
+    time::fromUnixTimestamp(time::milliseconds(1390966967032));
 
-  BOOST_CHECK_EQUAL(toIsoString(1390966967032), "20140129T034247.032000");
-  BOOST_CHECK_EQUAL(fromIsoString("20140129T034247.032000"), 1390966967032);
+  BOOST_CHECK_GT(value, referenceTime);
 
-  BOOST_CHECK_EQUAL(fromIsoString("20140129T034247.032000Z"), 1390966967032);
+  BOOST_CHECK_EQUAL(time::toIsoString(referenceTime), "20140129T034247.032000");
+  BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000"), referenceTime);
+
+  BOOST_CHECK_EQUAL(time::fromIsoString("20140129T034247.032000Z"), referenceTime);
+}
+
+BOOST_AUTO_TEST_CASE (SteadyClock)
+{
+  time::steady_clock::TimePoint oldValue = time::steady_clock::now();
+  usleep(100);
+  time::steady_clock::TimePoint newValue = time::steady_clock::now();
+
+  BOOST_CHECK_GT(newValue, oldValue);
 }
 
 BOOST_AUTO_TEST_SUITE_END()