summaryrefslogtreecommitdiff
path: root/sys/include/libc.h
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2020-06-14 09:33:32 -0700
committerOri Bernstein <ori@eigenstate.org>2020-06-14 09:33:32 -0700
commit8b3efcfc4e3b38eab3f0ff503e573c072ff890f5 (patch)
tree9956e2630657dc09a80e8ec97dfa07633fa865e7 /sys/include/libc.h
parentf380851ddb4598f6f0bca0a8d2db3ce8b36b7db7 (diff)
libc, seconds: new time and date apis (try 2)
Redo date handling in libc almost entirely. This allows handling dates and times from outside your timezones, fixes timezone loading in multithreaded applications, and allows parsing and formatting using custom format strings. As a test of the APIs, we replace the formatting code in seconds(1), shrinking it massively. The last commit missed a few removals, and made it unnecessarily hard to do an update.
Diffstat (limited to 'sys/include/libc.h')
-rw-r--r--sys/include/libc.h43
1 files changed, 33 insertions, 10 deletions
diff --git a/sys/include/libc.h b/sys/include/libc.h
index 7a2700539..820d684b2 100644
--- a/sys/include/libc.h
+++ b/sys/include/libc.h
@@ -314,22 +314,45 @@ extern double fmod(double, double);
/*
* Time-of-day
*/
+typedef struct Tzone Tzone;
+#pragma incomplete Tzone
+
typedef
struct Tm
{
- int sec;
- int min;
- int hour;
- int mday;
- int mon;
- int year;
- int wday;
- int yday;
- char zone[4];
- int tzoff;
+ vlong abs; /* seconds since Jan 1 1970, GMT */
+ int nsec; /* nseconds (range 0...1e9) */
+ int sec; /* seconds (range 0..60) */
+ int min; /* minutes (0..59) */
+ int hour; /* hours (0..23) */
+ int mday; /* day of the month (1..31) */
+ int mon; /* month of the year (0..11) */
+ int year; /* year A.D. */
+ int wday; /* day of week (0..6, Sunday = 0) */
+ int yday; /* day of year (0..365) */
+ char zone[16]; /* time zone name */
+ int tzoff; /* time zone delta from GMT */
+ Tzone *tz; /* time zone associated with this date */
} Tm;
+typedef
+struct Tmfmt {
+ char *fmt;
+ Tm *tm;
+} Tmfmt;
+
+#pragma varargck type "τ" Tmfmt
+
+extern Tzone* tmgetzone(char *name);
+extern Tm* tmnow(Tm*, Tzone*);
+extern Tm* tmtime(Tm*, vlong, Tzone*);
+extern Tm* tmtimens(Tm*, vlong, int, Tzone*);
+extern Tm* tmparse(Tm*, char*, char*, Tzone*);
+extern Tm* tmnorm(Tm*);
+extern Tmfmt tmfmt(Tm*, char*);
+extern void tmfmtinstall(void);
+
extern Tm* gmtime(long);
extern Tm* localtime(long);
extern char* asctime(Tm*);