aboutsummaryrefslogtreecommitdiff
path: root/src/util/strings.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-08-11 21:21:56 +0000
committerChristian Grothoff <christian@grothoff.org>2013-08-11 21:21:56 +0000
commit3d7fefedc9ba60bd8e8448efe8b628446d958536 (patch)
tree61ce41a52cd6e7232cead77818ef265993b2427e /src/util/strings.c
parent4a0398474db197abed243a123fb971fbeeffab4b (diff)
downloadgnunet-3d7fefedc9ba60bd8e8448efe8b628446d958536.tar.gz
gnunet-3d7fefedc9ba60bd8e8448efe8b628446d958536.zip
changing time measurement from milliseconds to microseconds
Diffstat (limited to 'src/util/strings.c')
-rw-r--r--src/util/strings.c97
1 files changed, 54 insertions, 43 deletions
diff --git a/src/util/strings.c b/src/util/strings.c
index 8bbc904bc..da02a9c4f 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -1,10 +1,10 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2005, 2006 Christian Grothoff (and other contributing authors) 3 (C) 2005-2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
@@ -300,18 +300,19 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
300{ 300{
301 static const struct ConversionTable table[] = 301 static const struct ConversionTable table[] =
302 { 302 {
303 { "ms", 1}, 303 { "us", 1},
304 { "s", 1000}, 304 { "ms", 1000 },
305 { "\"", 1000}, 305 { "s", 1000 * 1000LL },
306 { "m", 60 * 1000}, 306 { "\"", 1000 * 1000LL },
307 { "min", 60 * 1000}, 307 { "m", 60 * 1000 * 1000LL},
308 { "minutes", 60 * 1000}, 308 { "min", 60 * 1000 * 1000LL},
309 { "'", 60 * 1000}, 309 { "minutes", 60 * 1000 * 1000LL},
310 { "h", 60 * 60 * 1000}, 310 { "'", 60 * 1000 * 1000LL},
311 { "d", 24 * 60 * 60 * 1000}, 311 { "h", 60 * 60 * 1000 * 1000LL},
312 { "day", 24 * 60 * 60 * 1000}, 312 { "d", 24 * 60 * 60 * 1000LL * 1000LL},
313 { "days", 24 * 60 * 60 * 1000}, 313 { "day", 24 * 60 * 60 * 1000LL * 1000LL},
314 { "a", 31536000000LL /* year */ }, 314 { "days", 24 * 60 * 60 * 1000LL * 1000LL},
315 { "a", 31536000000000LL /* year */ },
315 { NULL, 0} 316 { NULL, 0}
316 }; 317 };
317 int ret; 318 int ret;
@@ -325,7 +326,7 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time,
325 ret = convert_with_table (fancy_time, 326 ret = convert_with_table (fancy_time,
326 table, 327 table,
327 &val); 328 &val);
328 rtime->rel_value = (uint64_t) val; 329 rtime->rel_value_us = (uint64_t) val;
329 return ret; 330 return ret;
330} 331}
331 332
@@ -363,9 +364,9 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
363 (NULL == strptime (fancy_time, "%Y", &tv)) ) 364 (NULL == strptime (fancy_time, "%Y", &tv)) )
364 return GNUNET_SYSERR; 365 return GNUNET_SYSERR;
365 t = mktime (&tv); 366 t = mktime (&tv);
366 atime->abs_value = (uint64_t) ((uint64_t) t * 1000LL); 367 atime->abs_value_us = (uint64_t) ((uint64_t) t * 1000LL * 1000LL);
367#if LINUX 368#if LINUX
368 atime->abs_value -= 1000LL * timezone; 369 atime->abs_value_us -= 1000LL * 1000LL * timezone;
369#endif 370#endif
370 return GNUNET_OK; 371 return GNUNET_OK;
371} 372}
@@ -380,7 +381,10 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
380 * string is returned. 381 * string is returned.
381 */ 382 */
382char * 383char *
383GNUNET_STRINGS_conv (const char *input, size_t len, const char *input_charset, const char *output_charset) 384GNUNET_STRINGS_conv (const char *input,
385 size_t len,
386 const char *input_charset,
387 const char *output_charset)
384{ 388{
385 char *ret; 389 char *ret;
386 uint8_t *u8_string; 390 uint8_t *u8_string;
@@ -634,41 +638,48 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta,
634 int do_round) 638 int do_round)
635{ 639{
636 static char buf[128]; 640 static char buf[128];
637 const char *unit = _( /* time unit */ "ms"); 641 const char *unit = _( /* time unit */ "ยตs");
638 uint64_t dval = delta.rel_value; 642 uint64_t dval = delta.rel_value_us;
639 643
640 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value == delta.rel_value) 644 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == delta.rel_value_us)
641 return _("forever"); 645 return _("forever");
642 if (0 == delta.rel_value) 646 if (0 == delta.rel_value_us)
643 return _("0 ms"); 647 return _("0 ms");
644 if ( ( (GNUNET_YES == do_round) && 648 if ( ( (GNUNET_YES == do_round) &&
645 (dval > 5 * 1000) ) || 649 (dval > 5 * 1000) ) ||
646 (0 == (dval % 1000) )) 650 (0 == (dval % 1000) ))
647 { 651 {
648 dval = dval / 1000; 652 dval = dval / 1000;
649 unit = _( /* time unit */ "s"); 653 unit = _( /* time unit */ "ms");
650 if ( ( (GNUNET_YES == do_round) && 654 if ( ( (GNUNET_YES == do_round) &&
651 (dval > 5 * 60) ) || 655 (dval > 5 * 1000) ) ||
652 (0 == (dval % 60) ) ) 656 (0 == (dval % 1000) ))
653 { 657 {
654 dval = dval / 60; 658 dval = dval / 1000;
655 unit = _( /* time unit */ "m"); 659 unit = _( /* time unit */ "s");
656 if ( ( (GNUNET_YES == do_round) && 660 if ( ( (GNUNET_YES == do_round) &&
657 (dval > 5 * 60) ) || 661 (dval > 5 * 60) ) ||
658 (0 == (dval % 60) )) 662 (0 == (dval % 60) ) )
659 { 663 {
660 dval = dval / 60; 664 dval = dval / 60;
661 unit = _( /* time unit */ "h"); 665 unit = _( /* time unit */ "m");
662 if ( ( (GNUNET_YES == do_round) && 666 if ( ( (GNUNET_YES == do_round) &&
663 (dval > 5 * 24) ) || 667 (dval > 5 * 60) ) ||
664 (0 == (dval % 24)) ) 668 (0 == (dval % 60) ))
665 { 669 {
666 dval = dval / 24; 670 dval = dval / 60;
667 if (1 == dval) 671 unit = _( /* time unit */ "h");
668 unit = _( /* time unit */ "day"); 672 if ( ( (GNUNET_YES == do_round) &&
669 else 673 (dval > 5 * 24) ) ||
670 unit = _( /* time unit */ "days"); 674 (0 == (dval % 24)) )
671 } 675 {
676 dval = dval / 24;
677 if (1 == dval)
678 unit = _( /* time unit */ "day");
679 else
680 unit = _( /* time unit */ "days");
681 }
682 }
672 } 683 }
673 } 684 }
674 } 685 }
@@ -693,9 +704,9 @@ GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t)
693 time_t tt; 704 time_t tt;
694 struct tm *tp; 705 struct tm *tp;
695 706
696 if (t.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) 707 if (t.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
697 return _("end of time"); 708 return _("end of time");
698 tt = t.abs_value / 1000; 709 tt = t.abs_value_us / 1000LL / 1000LL;
699 tp = gmtime (&tt); 710 tp = gmtime (&tt);
700 strftime (buf, sizeof (buf), "%a %b %d %H:%M:%S %Y", tp); 711 strftime (buf, sizeof (buf), "%a %b %d %H:%M:%S %Y", tp);
701 return buf; 712 return buf;