aboutsummaryrefslogtreecommitdiff
path: root/src/util/strings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/strings.c')
-rw-r--r--src/util/strings.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/util/strings.c b/src/util/strings.c
index db672da87..7be04ea82 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -355,6 +355,45 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
355 355
356 356
357enum GNUNET_GenericReturnValue 357enum GNUNET_GenericReturnValue
358GNUNET_STRINGS_rfc3339_time_to_absolute (const char *rfc3339_time,
359 struct GNUNET_TIME_Absolute *atime)
360{
361 struct tm tv;
362 time_t t;
363 const char *eos;
364
365 eos = &rfc3339_time[strlen (rfc3339_time)];
366 memset (&tv, 0, sizeof(tv));
367 /**
368 * FIXME: There are a lot more formats for RFC3339.
369 * Actually, we also may want https://www.w3.org/TR/xmlschema11-2/#dateTime
370 * at some point?
371 */
372 if ((eos != strptime (rfc3339_time, "%Y-%m-%dT%H:%M:%SZ", &tv)) &&
373 (eos != strptime (rfc3339_time, "%Y-%m-%dT%H:%M:%S%z", &tv)))
374 return GNUNET_SYSERR;
375 t = timegm (&tv);
376 atime->abs_value_us = (uint64_t) ((uint64_t) t * 1000LL * 1000LL);
377 return GNUNET_OK;
378}
379
380
381const char *
382GNUNET_STRINGS_absolute_time_to_rfc3339 (struct GNUNET_TIME_Absolute t)
383{
384 static GNUNET_THREAD_LOCAL char buf[255];
385 time_t tt;
386 struct tm *tp;
387
388 tt = t.abs_value_us / 1000LL / 1000LL;
389 tp = gmtime (&tt);
390 strftime (buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", tp);
391
392 return buf;
393}
394
395
396enum GNUNET_GenericReturnValue
358GNUNET_STRINGS_fancy_time_to_timestamp (const char *fancy_time, 397GNUNET_STRINGS_fancy_time_to_timestamp (const char *fancy_time,
359 struct GNUNET_TIME_Timestamp *atime) 398 struct GNUNET_TIME_Timestamp *atime)
360{ 399{