summaryrefslogtreecommitdiff
path: root/sys/src/libc
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2020-09-01 19:32:45 -0700
committerOri Bernstein <ori@eigenstate.org>2020-09-01 19:32:45 -0700
commitf444d6c3f21194d8a168133e04521f0a2503aa8b (patch)
treeb34cb77e8ad896c1ff3c977a4ab393991834d0fe /sys/src/libc
parente0278f69176765b408be4f29e6f3e5d39b928601 (diff)
tmparse: put in local timezone hack
Ctime is defined as printing a 3-character timezone name. The timezone name is ambiguous. For example, EST refers to both Australian and American eastern time. On top of that, we don't want to make the tzabbrev table exhaustive. So, we put in this hack: Before we consult the well known table of timezones, we check if the local time matches the timezone name. On top of that, tm2sec If you want unambiguous timezone parsing, use numeric timezone offsets (Z, ZZ formats).
Diffstat (limited to 'sys/src/libc')
-rw-r--r--sys/src/libc/port/date.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/sys/src/libc/port/date.c b/sys/src/libc/port/date.c
index 189bcb438..44ae15696 100644
--- a/sys/src/libc/port/date.c
+++ b/sys/src/libc/port/date.c
@@ -615,7 +615,7 @@ tmparse(Tm *tm, char *fmt, char *str, Tzone *tz, char **ep)
int depth, n, w, c0, zs, z0, z1, md, ampm, zoned, sloppy, tzo, ok;
vlong abs;
char *s, *p, *q;
- Tzone *zparsed;
+ Tzone *zparsed, *local;
Tzabbrev *a;
Tzoffpair *m;
@@ -774,6 +774,32 @@ tmparse(Tm *tm, char *fmt, char *str, Tzone *tz, char **ep)
switch(w){
case -1:
case 3:
+ /*
+ * Ugly Hack:
+ * Ctime is defined as printing a 3-character timezone
+ * name. The timezone name is ambiguous. For example,
+ * EST refers to both Australian and American eastern
+ * time. On top of that, we don't want to make the
+ * tzabbrev table exhaustive. So, we put in this hack:
+ *
+ * Before we consult the well known table of timezones,
+ * we check if the local time matches the timezone name.
+ *
+ * If you want unambiguous timezone parsing, use numeric
+ * timezone offsets (Z, ZZ formats).
+ */
+ if((local = tzload("local")) != nil){
+ if(cistrncmp(s, local->stname, strlen(local->stname)) == 0){
+ s += strlen(local->stname);
+ zparsed = local;
+ goto Zoneparsed;
+ }
+ if(cistrncmp(s, local->dlname, strlen(local->dlname)) == 0){
+ s += strlen(local->dlname);
+ zparsed = local;
+ goto Zoneparsed;
+ }
+ }
for(a = tzabbrev; a->abbr; a++){
n = strlen(a->abbr);
if(cistrncmp(s, a->abbr, n) == 0 && !isalpha(s[n]))