diff --git a/include/ipfs/util/time.h b/include/ipfs/util/time.h index 3d49f5c..b6eec48 100644 --- a/include/ipfs/util/time.h +++ b/include/ipfs/util/time.h @@ -1,12 +1,6 @@ #ifndef IPFS_TIME_H #define IPFS_TIME_H - struct stime { - time_t t; - struct timespec ts; - }; - - int get_gmttime(struct stime *st); - int ipfs_util_time_parse_RFC3339 (struct stime *st, char *s); - char *ipfs_util_time_format_RFC3339 (struct stime *st); + int ipfs_util_time_parse_RFC3339 (struct timespec *ts, char *s); + char *ipfs_util_time_format_RFC3339 (struct timespec *ts); #endif // IPFS_TIME_H diff --git a/util/time.c b/util/time.c index b438eb8..68707fe 100644 --- a/util/time.c +++ b/util/time.c @@ -13,35 +13,24 @@ #include #include "ipfs/util/time.h" -int get_gmttime(struct stime *st) { - if (!st) { - return 1; - } - if (!timespec_get(&st->ts, TIME_UTC) || - !time(&st->t)) { - return 2; - } - return 0; -} - -int ipfs_util_time_parse_RFC3339 (struct stime *st, char *s) +int ipfs_util_time_parse_RFC3339 (struct timespec *ts, char *s) { char *r; struct tm tm; - if (!st || !s || strlen(s) != 35) { + if (!ts || !s || strlen(s) != 35) { return 1; } r = strptime (s, "%Y-%m-%dT%H:%M:%S", &tm); if (!r || *r != '.') { return 2; } - st->t = mktime(&tm); - st->ts.tv_nsec = atoll(++r); + ts->tv_sec = mktime(&tm); + ts->tv_nsec = atoll(++r); return 0; } -char *ipfs_util_time_format_RFC3339 (struct stime *st) +char *ipfs_util_time_format_RFC3339 (struct timespec *ts) { char buf[31], *ret; @@ -50,8 +39,8 @@ char *ipfs_util_time_format_RFC3339 (struct stime *st) return NULL; } - if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.%%09dZ00:00", gmtime(&st->t)) != sizeof(buf)-1 || - snprintf(ret, 36, buf, st->ts.tv_nsec) != 35) { + if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.%%09dZ00:00", gmtime(&(ts->tv_sec))) != sizeof(buf)-1 || + snprintf(ret, 36, buf, ts->tv_nsec) != 35) { free (ret); return NULL; }