Content-Length: 467736 | pFad | http://github.com/DragonFlyBSD/DragonFlyBSD/commit/3ea318c6a5debb74a8ef8e61ff0d45babbfb50c2

B7 date(1): Add "-R" flag to use RFC 2822 date and time output format · DragonFlyBSD/DragonFlyBSD@3ea318c · GitHub
Skip to content

Commit 3ea318c

Browse files
rolinhFrançois Tigeot
authored and
François Tigeot
committed
date(1): Add "-R" flag to use RFC 2822 date and time output format
As stated in the man page, this is equivalent to use "%a, %d %b %Y %T %z" as the output format while LC_TIME is set to the "C" locale. This is compatible with date(1) from the GNU core utilities. Taken-from: FreeBSD While here, remove $DragonFly$ line from man page.
1 parent 4cdd475 commit 3ea318c

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

bin/date/date.1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@
3030
.\"
3131
.\" @(#)date.1 8.3 (Berkeley) 4/28/95
3232
.\" $FreeBSD: src/bin/date/date.1,v 1.72 2005/02/13 22:25:09 ru Exp $
33-
.\" $DragonFly: src/bin/date/date.1,v 1.4 2005/07/20 20:05:46 cpressey Exp $
3433
.\"
35-
.Dd August 9, 2004
34+
.Dd November 15, 2014
3635
.Dt DATE 1
3736
.Os
3837
.Sh NAME
3938
.Nm date
4039
.Nd display or set date and time
4140
.Sh SYNOPSIS
4241
.Nm
43-
.Op Fl ju
42+
.Op Fl jRu
4443
.Op Fl r Ar seconds
4544
.Oo
4645
.Fl v
@@ -52,7 +51,7 @@
5251
.Ar ...
5352
.Op Cm + Ns Ar output_fmt
5453
.Nm
55-
.Op Fl jnu
54+
.Op Fl jnRu
5655
.Sm off
5756
.Op Oo Oo Oo Oo Ar cc Oc Ar yy Oc Ar mm Oc Ar dd Oc Ar HH
5857
.Ar MM Op Ar .ss
@@ -130,6 +129,16 @@ The
130129
.Fl n
131130
option suppresses this behavior and causes the time to be set only on the
132131
current machine.
132+
.It Fl R
133+
Use RFC 2822 date and time output format. This is equivalent to use
134+
.Dq Li %a, %d %b %Y \&%T %z
135+
as
136+
.Ar output_fmt
137+
while
138+
.Ev LC_TIME
139+
is set to the
140+
.Dq C
141+
locale.
133142
.It Fl r Ar seconds
134143
Print the date and time represented by
135144
.Ar seconds ,

bin/date/date.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ static void setthetime(const char *, const char *, int, int);
5858
static void badformat(void);
5959
static void usage(void);
6060

61+
static const char *rfc2822_format ="%a, %d %b %Y %T %z";
62+
6163
int
6264
main(int argc, char **argv)
6365
{
6466
struct timezone tz;
6567
int ch, rflag;
66-
int jflag, nflag;
68+
int jflag, nflag, Rflag;
6769
const char *format;
6870
char buf[1024];
6971
char *endptr, *fmt;
@@ -78,9 +80,9 @@ main(int argc, char **argv)
7880
setlocale(LC_TIME, "");
7981
tz.tz_dsttime = tz.tz_minuteswest = 0;
8082
rflag = 0;
81-
jflag = nflag = 0;
83+
jflag = nflag = Rflag = 0;
8284
set_timezone = 0;
83-
while ((ch = getopt(argc, argv, "d:f:jnr:t:uv:")) != -1)
85+
while ((ch = getopt(argc, argv, "d:f:jnRr:t:uv:")) != -1)
8486
switch(ch) {
8587
case 'd': /* daylight savings time */
8688
tz.tz_dsttime = strtol(optarg, &endptr, 10) ? 1 : 0;
@@ -97,6 +99,9 @@ main(int argc, char **argv)
9799
case 'n': /* don't set network */
98100
nflag = 1;
99101
break;
102+
case 'R':
103+
Rflag = 1; /*RFC 2822 datetime format */
104+
break;
100105
case 'r': /* user specified seconds */
101106
rflag = 1;
102107
tval = strtoll(optarg, &tmp, 0);
@@ -135,6 +140,9 @@ main(int argc, char **argv)
135140

136141
format = "%+";
137142

143+
if (Rflag)
144+
format = rfc2822_format;
145+
138146
/* allow the operands in any order */
139147
if (*argv && **argv == '+') {
140148
format = *argv + 1;
@@ -159,6 +167,15 @@ main(int argc, char **argv)
159167
usage();
160168
}
161169
vary_destroy(v);
170+
171+
if (format == rfc2822_format) {
172+
/*
173+
* When using RFC 2822 datetime format, don't honor the
174+
* locale.
175+
*/
176+
setlocale(LC_TIME, "C");
177+
}
178+
162179
strftime(buf, sizeof(buf), format, &lt);
163180
printf("%s\n", buf);
164181
if (fflush(stdout) != 0)
@@ -289,7 +306,7 @@ static void
289306
usage(void)
290307
{
291308
fprintf(stderr, "%s\n%s\n",
292-
"usage: date [-jnu] [-d dst] [-r seconds] [-t west] "
309+
"usage: date [-jnRu] [-d dst] [-r seconds] [-t west] "
293310
"[-v[+|-]val[ymwdHMS]] ... ",
294311
" "
295312
"[-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]");

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/DragonFlyBSD/DragonFlyBSD/commit/3ea318c6a5debb74a8ef8e61ff0d45babbfb50c2

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy