summaryrefslogtreecommitdiff
path: root/sys/src/cmd/upas/common
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2020-09-26 11:20:42 -0700
committerOri Bernstein <ori@eigenstate.org>2020-09-26 11:20:42 -0700
commitd9f9e10e7b3ad61342ec1d9b034dd17f8452ccbc (patch)
tree3a0b155a8b2273cfe41110fe0a15ce50d6eb1e4f /sys/src/cmd/upas/common
parent9afa5550f7497f84fb157ba07ff94301dbe06bcc (diff)
upas: convert to tmdate, change timezone format
Complete the conversion of upas to remove ctime, use the new date library, and print time zones in +hhmm format, instead of NNN format. This may affect code that expects specific names for timezones. Fix that code.
Diffstat (limited to 'sys/src/cmd/upas/common')
-rw-r--r--sys/src/cmd/upas/common/common.h1
-rw-r--r--sys/src/cmd/upas/common/folder.c20
-rw-r--r--sys/src/cmd/upas/common/libsys.c13
-rw-r--r--sys/src/cmd/upas/common/sys.h2
4 files changed, 19 insertions, 17 deletions
diff --git a/sys/src/cmd/upas/common/common.h b/sys/src/cmd/upas/common/common.h
index 3353f8103..9748b94fe 100644
--- a/sys/src/cmd/upas/common/common.h
+++ b/sys/src/cmd/upas/common/common.h
@@ -20,6 +20,7 @@ enum{
Fstored = 1<<6, /* S */
Nflags = 7,
};
+#define Timefmt "WW MMM _D hh:mm:ss ?Z YYYY"
/*
* flag.c
diff --git a/sys/src/cmd/upas/common/folder.c b/sys/src/cmd/upas/common/folder.c
index 0098ea67f..f16e2212c 100644
--- a/sys/src/cmd/upas/common/folder.c
+++ b/sys/src/cmd/upas/common/folder.c
@@ -1,7 +1,5 @@
#include "common.h"
-#define Ctimefmt "WW MMM _D hh:mm:ss ?Z YYYY"
-
enum{
Mbox = 1,
Mdir,
@@ -186,22 +184,24 @@ mboxesc(Biobuf *in, Biobuf *out, int type)
int
appendfolder(Biobuf *b, char *addr, int fd)
{
- char *s, *t;
- int r;
+ char *s;
+ int r, n;
Biobuf bin;
Folder *f;
+ Tzone *tz;
Tm tm;
f = getfolder(b);
Bseek(f->out, 0, 2);
Binit(&bin, fd, OREAD);
s = Brdstr(&bin, '\n', 0);
- if(s == nil || strncmp(s, "From ", 5) != 0)
- Bprint(f->out, "From %s %.28s\n", addr, ctime(f->t));
- else if(strncmp(s, "From ", 5) == 0
- && (t = strchr(s + 5, ' ')) != nil
- && tmparse(&tm, Ctimefmt, t + 1, nil, nil) != nil)
- f->t = tm2sec(&tm);
+ n = strlen(s);
+ if(!s || strncmp(s, "From ", 5) != 0){
+ tz = tzload("local");
+ tmtime(&tm, f->t, tz);
+ Bprint(f->out, "From %s %τ\n", addr, tmfmt(&tm, Timefmt));
+ }else if(n > 5 && tmparse(&tm, Timefmt, s + 5, nil, nil) != nil)
+ f->t = tmnorm(&tm);
if(s)
Bwrite(f->out, s, strlen(s));
free(s);
diff --git a/sys/src/cmd/upas/common/libsys.c b/sys/src/cmd/upas/common/libsys.c
index 969c2ff67..392d3ff40 100644
--- a/sys/src/cmd/upas/common/libsys.c
+++ b/sys/src/cmd/upas/common/libsys.c
@@ -5,14 +5,15 @@
/*
* return the date
*/
-char*
-thedate(void)
+Tmfmt
+thedate(Tm *tm)
{
- static char now[64];
+ Tzone *tz;
- strcpy(now, ctime(time(0)));
- now[28] = 0;
- return now;
+ /* if the local time is screwed, just do gmt */
+ tz = tzload("local");
+ tmnow(tm, tz);
+ return tmfmt(tm, Timefmt);
}
/*
diff --git a/sys/src/cmd/upas/common/sys.h b/sys/src/cmd/upas/common/sys.h
index a860df15f..06de24f36 100644
--- a/sys/src/cmd/upas/common/sys.h
+++ b/sys/src/cmd/upas/common/sys.h
@@ -35,7 +35,7 @@ char *alt_sysname_read(void);
char *domainname_read(void);
char **sysnames_read(void);
char *getlog(void);
-char *thedate(void);
+Tmfmt thedate(Tm*);
Biobuf *sysopen(char*, char*, ulong);
int sysopentty(void);
int sysclose(Biobuf*);