Removed redundant struct stime from util/time
This commit is contained in:
parent
a654022d32
commit
b914745b47
2 changed files with 9 additions and 26 deletions
|
@ -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
|
||||
|
|
25
util/time.c
25
util/time.c
|
@ -13,35 +13,24 @@
|
|||
#include <time.h>
|
||||
#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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue