Removed redundant struct stime from util/time

This commit is contained in:
Jose Marcial Vieira Bisneto 2016-12-20 20:38:31 -03:00
parent a654022d32
commit b914745b47
2 changed files with 9 additions and 26 deletions

View file

@ -1,12 +1,6 @@
#ifndef IPFS_TIME_H #ifndef IPFS_TIME_H
#define IPFS_TIME_H #define IPFS_TIME_H
struct stime { int ipfs_util_time_parse_RFC3339 (struct timespec *ts, char *s);
time_t t; char *ipfs_util_time_format_RFC3339 (struct timespec *ts);
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);
#endif // IPFS_TIME_H #endif // IPFS_TIME_H

View file

@ -13,35 +13,24 @@
#include <time.h> #include <time.h>
#include "ipfs/util/time.h" #include "ipfs/util/time.h"
int get_gmttime(struct stime *st) { int ipfs_util_time_parse_RFC3339 (struct timespec *ts, char *s)
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)
{ {
char *r; char *r;
struct tm tm; struct tm tm;
if (!st || !s || strlen(s) != 35) { if (!ts || !s || strlen(s) != 35) {
return 1; return 1;
} }
r = strptime (s, "%Y-%m-%dT%H:%M:%S", &tm); r = strptime (s, "%Y-%m-%dT%H:%M:%S", &tm);
if (!r || *r != '.') { if (!r || *r != '.') {
return 2; return 2;
} }
st->t = mktime(&tm); ts->tv_sec = mktime(&tm);
st->ts.tv_nsec = atoll(++r); ts->tv_nsec = atoll(++r);
return 0; return 0;
} }
char *ipfs_util_time_format_RFC3339 (struct stime *st) char *ipfs_util_time_format_RFC3339 (struct timespec *ts)
{ {
char buf[31], *ret; char buf[31], *ret;
@ -50,8 +39,8 @@ char *ipfs_util_time_format_RFC3339 (struct stime *st)
return NULL; return NULL;
} }
if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.%%09dZ00:00", gmtime(&st->t)) != sizeof(buf)-1 || if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.%%09dZ00:00", gmtime(&(ts->tv_sec))) != sizeof(buf)-1 ||
snprintf(ret, 36, buf, st->ts.tv_nsec) != 35) { snprintf(ret, 36, buf, ts->tv_nsec) != 35) {
free (ret); free (ret);
return NULL; return NULL;
} }