blob: 90482d9cd4e8b19377650306bd50dbd29a105b98 [file] [log] [blame]
Alexander Afanasyeve2e3ca52014-01-03 13:59:07 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_TIME_HPP
9#define NDN_TIME_HPP
10
11#include <stdexcept>
Alexander Afanasyev54467af2014-01-06 15:45:32 -080012#include "../c/util/time.h"
Alexander Afanasyeve2e3ca52014-01-03 13:59:07 -080013
14namespace ndn {
15
16/**
17 * Convert to the ISO string representation of the time.
18 * @param time Milliseconds since 1/1/1970.
19 * @return The ISO string.
20 */
21inline std::string
22toIsoString(const MillisecondsSince1970& time)
23{
24 char isoString[25];
25 ndn_Error error;
26 if ((error = ndn_toIsoString(time, isoString)))
27 throw std::runtime_error(ndn_getErrorString(error));
28
29 return isoString;
30}
31
32/**
33 * Convert from the ISO string representation to the internal time format.
34 * @param isoString The ISO time formatted string.
35 * @return The time in milliseconds since 1/1/1970.
36 */
37inline MillisecondsSince1970
38fromIsoString(const std::string& isoString)
39{
40 MillisecondsSince1970 milliseconds;
41 ndn_Error error;
42 if ((error = ndn_fromIsoString(isoString.c_str(), &milliseconds)))
43 throw std::runtime_error(ndn_getErrorString(error));
44
45 return milliseconds;
46}
47
48} // namespace ndn
49
50#endif // NDN_TIME_HPP