Add RFC2822 (email style) formatted dates to to date(1).
This commit is contained in:
parent
0cb4115b82
commit
8cbe3772c4
2 changed files with 35 additions and 3 deletions
|
@ -30,6 +30,9 @@ Report the date as ISO-8601 without time and timezone suffix.
|
||||||
.TP
|
.TP
|
||||||
.B -t
|
.B -t
|
||||||
Report the date as ISO-8601 with time and timezone suffix.
|
Report the date as ISO-8601 with time and timezone suffix.
|
||||||
|
.TP
|
||||||
|
.B -m
|
||||||
|
Report the date as an email compatible (RFC2822) time stamp.
|
||||||
.PP
|
.PP
|
||||||
The conversion from Greenwich Mean Time to local time depends on the
|
The conversion from Greenwich Mean Time to local time depends on the
|
||||||
.B $timezone
|
.B $timezone
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
|
||||||
int uflg, nflg, iflg, tflg;
|
static char *day[] = {
|
||||||
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
|
||||||
|
};
|
||||||
|
|
||||||
|
static char *mon[] = {
|
||||||
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
|
||||||
|
"Aug", "Sep", "Oct", "Nov", "Dec"
|
||||||
|
};
|
||||||
|
|
||||||
|
int uflg, nflg, iflg, tflg, mflg;
|
||||||
|
|
||||||
char*
|
char*
|
||||||
isodate(Tm *t)
|
isodate(Tm *t)
|
||||||
|
@ -38,6 +47,23 @@ isotime(Tm *t)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
mailtime(Tm *t)
|
||||||
|
{
|
||||||
|
static char c[64];
|
||||||
|
char *sgn;
|
||||||
|
int off;
|
||||||
|
|
||||||
|
sgn = "+";
|
||||||
|
if(t->tzoff < 0)
|
||||||
|
sgn = "";
|
||||||
|
off = (t->tzoff/3600)*100 + (t->tzoff/60)%60;
|
||||||
|
snprint(c, sizeof(c), "%s, %.2d %s %.4d %.2d:%.2d:%.2d %s%.4d",
|
||||||
|
day[t->wday], t->mday, mon[t->mon], t->year + 1900,
|
||||||
|
t->hour, t->min, t->sec, sgn, off);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -48,7 +74,8 @@ main(int argc, char *argv[])
|
||||||
case 'u': uflg = 1; break;
|
case 'u': uflg = 1; break;
|
||||||
case 't': tflg = 1; /* implies -i */
|
case 't': tflg = 1; /* implies -i */
|
||||||
case 'i': iflg = 1; break;
|
case 'i': iflg = 1; break;
|
||||||
default: fprint(2, "usage: date [-itun] [seconds]\n"); exits("usage");
|
case 'm': mflg = 1; break;
|
||||||
|
default: fprint(2, "usage: date [-itunm] [seconds]\n"); exits("usage");
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
||||||
if(argc == 1)
|
if(argc == 1)
|
||||||
|
@ -65,7 +92,9 @@ main(int argc, char *argv[])
|
||||||
print("%s\n", isotime(tm));
|
print("%s\n", isotime(tm));
|
||||||
else
|
else
|
||||||
print("%s\n", isodate(tm));
|
print("%s\n", isodate(tm));
|
||||||
} else
|
} else if(mflg)
|
||||||
|
print("%s\n", mailtime(tm));
|
||||||
|
else
|
||||||
print("%s", asctime(tm));
|
print("%s", asctime(tm));
|
||||||
}
|
}
|
||||||
exits(0);
|
exits(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue