mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 08:48:29 +00:00
Use 64-bit years
This change makes strftime() go faster and makes it possible to format timestamps through the big bang to most of the stelliferous era. India has also been added as a timezone to most binaries. Since we were able to change the struct tm abi, this makes cosmopolitan libc superior, to just about everything else, when it comes to standing the test of time
This commit is contained in:
parent
2aebda7718
commit
cfc3a953ae
13 changed files with 542 additions and 482 deletions
|
@ -20,6 +20,7 @@
|
|||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/mem/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
|
@ -33,10 +34,11 @@
|
|||
|
||||
static char *xiso8601_impl(struct timespec *opt_ts, int sswidth) {
|
||||
char *p;
|
||||
int i, j, n;
|
||||
struct tm tm;
|
||||
struct timespec ts;
|
||||
int64_t sec, subsec;
|
||||
char timebuf[64], zonebuf[8];
|
||||
char buf[128], ibuf[21];
|
||||
if (opt_ts) {
|
||||
sec = opt_ts->tv_sec;
|
||||
subsec = opt_ts->tv_nsec;
|
||||
|
@ -56,10 +58,20 @@ static char *xiso8601_impl(struct timespec *opt_ts, int sswidth) {
|
|||
sswidth = 7; /* windows nt uses hectonanoseconds */
|
||||
}
|
||||
localtime_r(&sec, &tm);
|
||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%dT%H:%M:%S", &tm);
|
||||
strftime(zonebuf, sizeof(zonebuf), "%z", &tm);
|
||||
(asprintf)(&p, "%s.%0*ld%s", timebuf, sswidth, subsec, zonebuf);
|
||||
return p;
|
||||
i = strftime(buf, 64, "%Y-%m-%dT%H:%M:%S", &tm);
|
||||
p = FormatInt64(ibuf, subsec);
|
||||
for (n = sswidth - (p - ibuf); n > 0; --n) {
|
||||
if (i < sizeof(buf)) {
|
||||
buf[i++] = '0';
|
||||
}
|
||||
}
|
||||
for (j = 0; ibuf[j]; ++j) {
|
||||
if (i < sizeof(buf)) {
|
||||
buf[i++] = ibuf[j];
|
||||
}
|
||||
}
|
||||
strftime(buf + i, sizeof(buf) - i, "%z", &tm);
|
||||
return strdup(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue