DER encoding: implement DerGtime::fromIsoString.
diff --git a/ndn-cpp/c/util/time.c b/ndn-cpp/c/util/time.c
index 41047f8..7ffa517 100644
--- a/ndn-cpp/c/util/time.c
+++ b/ndn-cpp/c/util/time.c
@@ -34,3 +34,23 @@
sprintf(isoString, "%04d%02d%02dT%02d%02d%02d%s", 1900 + gmt->tm_year, gmt->tm_mon + 1, gmt->tm_mday,
gmt->tm_hour, gmt->tm_min, gmt->tm_sec, fraction);
}
+
+ndn_MillisecondsSince1970
+ndn_fromIsoString(const char* isoString)
+{
+ // Initialize time zone, etc.
+ time_t dummyTime = 0;
+ struct tm time = *gmtime(&dummyTime);
+
+ sscanf(isoString, "%4d%2d%2dT%2d%2d", &time.tm_year, &time.tm_mon, &time.tm_mday, &time.tm_hour, &time.tm_min);
+ // Skip the time past minutes and get the float seconds.
+ double seconds;
+ sscanf(isoString + (4 + 2 + 2 + 1 + 2 + 2), "%lf", &seconds);
+
+ // tm_year starts from 1900.
+ time.tm_year -= 1900;
+ // tm_mon starts from 0, not 1.
+ time.tm_mon -= 1;
+ time.tm_sec = 0;
+ return (timegm(&time) + seconds) * 1000.0;
+}
\ No newline at end of file
diff --git a/ndn-cpp/c/util/time.h b/ndn-cpp/c/util/time.h
index 454216e..b2414c7 100644
--- a/ndn-cpp/c/util/time.h
+++ b/ndn-cpp/c/util/time.h
@@ -21,13 +21,21 @@
ndn_getNowMilliseconds();
/**
- * Convert the time from milliseconds to ISO time, for example "20131018T184138.423355".
+ * Convert the time from milliseconds to an ISO time string, for example "20131018T184138.423355".
* @param milliseconds The time in milliseconds since 1/1/1970, including fractions of a millisecond.
* @param isoString A buffer of at least 23 bytes to receive the null-terminated ISO time string.
*/
void
ndn_toIsoString(ndn_MillisecondsSince1970 time, char *isoString);
+/**
+ * Parse the ISO time string and return the time in milliseconds.
+ * @param isoString The ISO time string, for example "20131018T184138.423355".
+ * @return The time in milliseconds since 1/1/1970, including fractions of a millisecond.
+ */
+ndn_MillisecondsSince1970
+ndn_fromIsoString(const char* isoString);
+
#ifdef __cplusplus
}
#endif