Jeff Thompson | 9ae4d78 | 2013-10-17 10:25:54 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NDN_TIME_H |
| 8 | #define NDN_TIME_H |
| 9 | |
Yingdi Yu | 61ec272 | 2014-01-20 14:22:32 -0800 | [diff] [blame^] | 10 | #include <ndn-cpp-dev/c/common.h> |
Jeff Thompson | ea94620 | 2013-10-18 14:35:32 -0700 | [diff] [blame] | 11 | #include "../errors.h" |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 12 | |
Jeff Thompson | 9ae4d78 | 2013-10-17 10:25:54 -0700 | [diff] [blame] | 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | |
| 17 | /** |
| 18 | * Use gettimeofday to return the current time in milliseconds. |
| 19 | * @return The current time in milliseconds since 1/1/1970, including fractions of a millisecond according to timeval.tv_usec. |
| 20 | */ |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 21 | ndn_MillisecondsSince1970 |
Jeff Thompson | 9ae4d78 | 2013-10-17 10:25:54 -0700 | [diff] [blame] | 22 | ndn_getNowMilliseconds(); |
| 23 | |
Jeff Thompson | 5a6ce83 | 2013-10-18 11:54:35 -0700 | [diff] [blame] | 24 | /** |
Jeff Thompson | fdaaa58 | 2013-10-18 13:05:10 -0700 | [diff] [blame] | 25 | * Convert the time from milliseconds to an ISO time string, for example "20131018T184138.423355". |
Jeff Thompson | 5a6ce83 | 2013-10-18 11:54:35 -0700 | [diff] [blame] | 26 | * @param milliseconds The time in milliseconds since 1/1/1970, including fractions of a millisecond. |
| 27 | * @param isoString A buffer of at least 23 bytes to receive the null-terminated ISO time string. |
Jeff Thompson | ea94620 | 2013-10-18 14:35:32 -0700 | [diff] [blame] | 28 | * @return 0 for success, else an error code including if we don't have necessary standard library support. |
Jeff Thompson | 5a6ce83 | 2013-10-18 11:54:35 -0700 | [diff] [blame] | 29 | */ |
Jeff Thompson | ea94620 | 2013-10-18 14:35:32 -0700 | [diff] [blame] | 30 | ndn_Error |
| 31 | ndn_toIsoString(ndn_MillisecondsSince1970 milliseconds, char *isoString); |
Jeff Thompson | 5a6ce83 | 2013-10-18 11:54:35 -0700 | [diff] [blame] | 32 | |
Jeff Thompson | fdaaa58 | 2013-10-18 13:05:10 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Parse the ISO time string and return the time in milliseconds. |
| 35 | * @param isoString The ISO time string, for example "20131018T184138.423355". |
Jeff Thompson | ea94620 | 2013-10-18 14:35:32 -0700 | [diff] [blame] | 36 | * @param milliseconds Return the time in milliseconds since 1/1/1970, including fractions of a millisecond. |
| 37 | * @return 0 for success, else an error code including if we don't have necessary standard library support. |
Jeff Thompson | fdaaa58 | 2013-10-18 13:05:10 -0700 | [diff] [blame] | 38 | */ |
Jeff Thompson | ea94620 | 2013-10-18 14:35:32 -0700 | [diff] [blame] | 39 | ndn_Error |
| 40 | ndn_fromIsoString(const char* isoString, ndn_MillisecondsSince1970 *milliseconds); |
Jeff Thompson | fdaaa58 | 2013-10-18 13:05:10 -0700 | [diff] [blame] | 41 | |
Jeff Thompson | 9ae4d78 | 2013-10-17 10:25:54 -0700 | [diff] [blame] | 42 | #ifdef __cplusplus |
| 43 | } |
| 44 | #endif |
| 45 | |
| 46 | #endif |