{ "ms", 1},
{ "s", 1000},
{ "\"", 1000},
+ { "m", 60 * 1000},
{ "min", 60 * 1000},
{ "minutes", 60 * 1000},
{ "'", 60 * 1000},
{ "h", 60 * 60 * 1000},
{ "d", 24 * 60 * 60 * 1000},
+ { "day", 24 * 60 * 60 * 1000},
+ { "days", 24 * 60 * 60 * 1000},
{ "a", 31536000000LL /* year */ },
{ NULL, 0}
};
int ret;
unsigned long long val;
+ if (0 == strcasecmp ("forever", fancy_time))
+ {
+ *rtime = GNUNET_TIME_UNIT_FOREVER_REL;
+ return GNUNET_OK;
+ }
ret = convert_with_table (fancy_time,
table,
&val);
struct tm tv;
time_t t;
+ if (0 == strcasecmp ("end of time", fancy_time))
+ {
+ *atime = GNUNET_TIME_UNIT_FOREVER_ABS;
+ return GNUNET_OK;
+ }
memset (&tv, 0, sizeof (tv));
- if ( (NULL == strptime (fancy_time, "%c", &tv)) &&
+ if ( (NULL == strptime (fancy_time, "%a %b %d %H:%M:%S %Y", &tv)) &&
+ (NULL == strptime (fancy_time, "%c", &tv)) &&
(NULL == strptime (fancy_time, "%Ec", &tv)) &&
(NULL == strptime (fancy_time, "%Y-%m-%d %H:%M:%S", &tv)) &&
(NULL == strptime (fancy_time, "%Y-%m-%d %H:%M", &tv)) &&
return GNUNET_SYSERR;
t = mktime (&tv);
atime->abs_value = (uint64_t) ((uint64_t) t * 1000LL);
+ atime->abs_value -= 1000LL * timezone;
return GNUNET_OK;
}
if (delta.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
return GNUNET_strdup (_("eternity"));
- if (dval > 5 * 1000)
+ if ( (dval > 5 * 1000) || (0 == (dval % 1000) ))
{
dval = dval / 1000;
unit = _( /* time unit */ "s");
- if (dval > 5 * 60)
+ if ( (dval > 5 * 60) || (0 == (dval % 60) ) )
{
dval = dval / 60;
unit = _( /* time unit */ "m");
- if (dval > 5 * 60)
+ if ( (dval > 5 * 60) || (0 == (dval % 60) ))
{
dval = dval / 60;
unit = _( /* time unit */ "h");
- if (dval > 5 * 24)
+ if ( (dval > 5 * 24) || (0 == (dval % 24)) )
{
dval = dval / 24;
- unit = _( /* time unit */ " days");
+ if (1 == dval)
+ unit = _( /* time unit */ "day");
+ else
+ unit = _( /* time unit */ "days");
}
}
}
/**
- * "man ctime_r", except for GNUnet time; also, unlike ctime, the
- * return value does not include the newline character.
+ * "asctime", except for GNUnet time.
*
* @param t time to convert
* @return absolute time in human-readable format
GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
{
time_t tt;
- char *ret;
+ struct tm *tp;
+ char buf[255];
if (t.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
return GNUNET_strdup (_("end of time"));
tt = t.abs_value / 1000;
-#ifdef ctime_r
- ret = ctime_r (&tt, GNUNET_malloc (32));
-#else
- ret = GNUNET_strdup (ctime (&tt));
-#endif
- ret[strlen (ret) - 1] = '\0';
- return ret;
+ tp = gmtime (&tt);
+ strftime (buf, sizeof (buf), "%a %b %d %H:%M:%S %Y", tp);
+ return GNUNET_strdup (buf);
}
char *r;
char *b;
struct GNUNET_TIME_Absolute at;
+ struct GNUNET_TIME_Absolute atx;
const char *hdir;
GNUNET_log_setup ("test_strings", "ERROR", NULL);
GNUNET_free (r);
b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII");
WANT ("TEST", b);
+
+ at = GNUNET_TIME_UNIT_FOREVER_ABS;
+ b = GNUNET_STRINGS_absolute_time_to_string (at);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_time_to_absolute (b, &atx));
+ GNUNET_assert (atx.abs_value == at.abs_value);
+ GNUNET_free (b);
+
#if ENABLE_NLS && HAVE_ICONV
GNUNET_log_skip (2, GNUNET_NO);
b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "unknown");