2 * UCW Library -- A Parser of Time Intervals
4 * (c) 2012 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
13 #include <ucw/fastbuf.h>
16 timestamp_parser(char *c, void *ptr)
18 timestamp_t *ts = ptr;
21 char *err = cf_parse_double(c, &d);
25 return "Time too large";
27 *ts = (timestamp_t)(d*1000 + 0.5);
29 return "Non-zero time rounds down to zero milliseconds";
35 timestamp_dumper(struct fastbuf *fb, void *ptr)
37 timestamp_t *ts = ptr;
38 bprintf(fb, "%jd", (intmax_t) *ts);
41 struct cf_user_type timestamp_type = {
42 .size = sizeof(timestamp_t),
44 .parser = timestamp_parser,
45 .dumper = timestamp_dumper
56 while (fgets(line, sizeof(line), stdin))
58 char *nl = strchr(line, '\n');
62 char *err = timestamp_parser(line, &t);
66 printf("%jd\n", (intmax_t) t);