changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: Add RFC2822 (email style) formatted dates to to date(1).

changeset 7362: b2e82d7a1e5b
parent 7361: 1a4c0549d156
child 7363: 51d91ffdb9e8
child 7364: 4947baafd1f3
author: Ori Bernstein <ori@eigenstate.org'
date: Fri, 06 Sep 2019 08:25:21 -0700
files: sys/man/1/date sys/src/cmd/date.c
description: Add RFC2822 (email style) formatted dates to to date(1).
     1.1--- a/sys/man/1/date
     1.2+++ b/sys/man/1/date
     1.3@@ -30,6 +30,9 @@ Report the date as ISO-8601 without time
     1.4 .TP
     1.5 .B -t
     1.6 Report the date as ISO-8601 with time and timezone suffix.
     1.7+.TP
     1.8+.B -m
     1.9+Report the date as an email compatible (RFC2822) time stamp.
    1.10 .PP
    1.11 The conversion from Greenwich Mean Time to local time depends on the
    1.12 .B $timezone
     2.1--- a/sys/src/cmd/date.c
     2.2+++ b/sys/src/cmd/date.c
     2.3@@ -1,7 +1,16 @@
     2.4 #include <u.h>
     2.5 #include <libc.h>
     2.6 
     2.7-int uflg, nflg, iflg, tflg;
     2.8+static char *day[] = {
     2.9+	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
    2.10+};
    2.11+
    2.12+static char *mon[] = {
    2.13+	"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
    2.14+	"Aug", "Sep", "Oct", "Nov", "Dec"
    2.15+};
    2.16+
    2.17+int uflg, nflg, iflg, tflg, mflg;
    2.18 
    2.19 char*
    2.20 isodate(Tm *t)
    2.21@@ -38,6 +47,23 @@ isotime(Tm *t)
    2.22 	return d;
    2.23 }
    2.24 
    2.25+char *
    2.26+mailtime(Tm *t)
    2.27+{
    2.28+	static char c[64];
    2.29+	char *sgn;
    2.30+	int off;
    2.31+
    2.32+	sgn = "+";
    2.33+	if(t->tzoff < 0)
    2.34+		sgn = "";
    2.35+	off = (t->tzoff/3600)*100 + (t->tzoff/60)%60;
    2.36+	snprint(c, sizeof(c), "%s, %.2d %s %.4d %.2d:%.2d:%.2d %s%.4d",
    2.37+		day[t->wday], t->mday, mon[t->mon], t->year + 1900,
    2.38+		t->hour, t->min, t->sec, sgn, off);
    2.39+	return c;
    2.40+}
    2.41+
    2.42 void
    2.43 main(int argc, char *argv[])
    2.44 {
    2.45@@ -48,7 +74,8 @@ main(int argc, char *argv[])
    2.46 	case 'u':	uflg = 1; break;
    2.47 	case 't':	tflg = 1; /* implies -i */
    2.48 	case 'i':	iflg = 1; break;
    2.49-	default:	fprint(2, "usage: date [-itun] [seconds]\n"); exits("usage");
    2.50+	case 'm':	mflg = 1; break;
    2.51+	default:	fprint(2, "usage: date [-itunm] [seconds]\n"); exits("usage");
    2.52 	}ARGEND
    2.53 
    2.54 	if(argc == 1)
    2.55@@ -65,7 +92,9 @@ main(int argc, char *argv[])
    2.56 				print("%s\n", isotime(tm));
    2.57 			else
    2.58 				print("%s\n", isodate(tm));
    2.59-		} else
    2.60+		} else if(mflg)
    2.61+			print("%s\n", mailtime(tm));
    2.62+		else
    2.63 			print("%s", asctime(tm));
    2.64 	}
    2.65 	exits(0);