summaryrefslogtreecommitdiff
path: root/sys/include
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2020-08-09 18:58:44 -0700
committerOri Bernstein <ori@eigenstate.org>2020-08-09 18:58:44 -0700
commit56e869ac7004a635a7d63596ee751275484f28c3 (patch)
tree6abb2068c51ed8d44b7abebe7f633952cedcb92e /sys/include
parent3ba1d83d2026ebac616ab17a2126df97c0a7a24c (diff)
libc: new date apis
The current date and time APIs on Plan 9 are not good. They're inflexible, non-threadsafe, and don't expose timezone information. This commit adds new time APIs that allow parsing arbitrary dates, work from multiple threads, and can handle timezones effectively.
Diffstat (limited to 'sys/include')
-rw-r--r--sys/include/libc.h42
1 files changed, 32 insertions, 10 deletions
diff --git a/sys/include/libc.h b/sys/include/libc.h
index 7a2700539..4eecd028f 100644
--- a/sys/include/libc.h
+++ b/sys/include/libc.h
@@ -314,22 +314,44 @@ 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;
+ 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* tzload(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*, char **ep);
+extern vlong tmnorm(Tm*);
+extern Tmfmt tmfmt(Tm*, char*);
+extern void tmfmtinstall(void);
+
extern Tm* gmtime(long);
extern Tm* localtime(long);
extern char* asctime(Tm*);