summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorkim <kim@NetBSD.org>2023-05-31 16:01:53 +0000
committerkim <kim@NetBSD.org>2023-05-31 16:01:53 +0000
commit2f25acbd02098da437eb9567f85505ca97742459 (patch)
tree9880eb0414341521db2541ec92adac061a5110f0 /bin
parent6ae054f52c77e5b732c872269aaa9218fc4ea76a (diff)
Add -R option for displaying time in RFC 5322 format, similar to GNU date.
Diffstat (limited to 'bin')
-rw-r--r--bin/date/date.111
-rw-r--r--bin/date/date.c14
2 files changed, 17 insertions, 8 deletions
diff --git a/bin/date/date.1 b/bin/date/date.1
index 9758fe66e48..ceb28732a39 100644
--- a/bin/date/date.1
+++ b/bin/date/date.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: date.1,v 1.51 2022/10/22 20:11:43 christos Exp $
+.\" $NetBSD: date.1,v 1.52 2023/05/31 16:01:53 kim Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" @(#)date.1 8.3 (Berkeley) 4/28/95
.\"
-.Dd October 22, 2022
+.Dd May 31, 2023
.Dt DATE 1
.Os
.Sh NAME
@@ -40,7 +40,7 @@
.Nd display or set date and time
.Sh SYNOPSIS
.Nm
-.Op Fl ajnu
+.Op Fl ajnRu
.Op Fl d Ar date
.Op Fl r Ar seconds
.Op Cm + Ns Ar format
@@ -54,7 +54,7 @@
.Li \&. Ar SS Oc Oc
.Sm on
.Nm
-.Op Fl ajnu
+.Op Fl ajnRu
.Fl f Ar input_format
new_date
.Op Cm + Ns Ar format
@@ -116,6 +116,9 @@ The
option stops
.Nm
from setting the time for other than the current machine.
+.It Fl R
+Use a default display format that conforms to the date and time
+specification in RFC 5322 (Internet Message Format).
.It Fl r Ar seconds
Print out the date and time that is
.Ar seconds
diff --git a/bin/date/date.c b/bin/date/date.c
index b9598dd37ab..6d74d6ca56f 100644
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -1,4 +1,4 @@
-/* $NetBSD: date.c,v 1.63 2022/10/22 20:11:43 christos Exp $ */
+/* $NetBSD: date.c,v 1.64 2023/05/31 16:01:53 kim Exp $ */
/*
* Copyright (c) 1985, 1987, 1988, 1993
@@ -44,7 +44,7 @@ __COPYRIGHT(
#if 0
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: date.c,v 1.63 2022/10/22 20:11:43 christos Exp $");
+__RCSID("$NetBSD: date.c,v 1.64 2023/05/31 16:01:53 kim Exp $");
#endif
#endif /* not lint */
@@ -71,7 +71,7 @@ __RCSID("$NetBSD: date.c,v 1.63 2022/10/22 20:11:43 christos Exp $");
#include "extern.h"
static time_t tval;
-static int aflag, jflag, rflag, nflag;
+static int Rflag, aflag, jflag, rflag, nflag;
static char *fmt;
__dead static void badcanotime(const char *, const char *, size_t);
@@ -91,7 +91,7 @@ main(int argc, char *argv[])
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "ad:f:jnr:u")) != -1) {
+ while ((ch = getopt(argc, argv, "ad:f:jnRr:u")) != -1) {
switch (ch) {
case 'a': /* adjust time slowly */
aflag = 1;
@@ -119,6 +119,9 @@ main(int argc, char *argv[])
case 'n': /* don't set network */
nflag = 1;
break;
+ case 'R': /* RFC-5322 email format */
+ Rflag = 1;
+ break;
case 'r': /* user specified seconds */
if (optarg[0] == '\0') {
errx(EXIT_FAILURE, "<empty>: Invalid number");
@@ -153,6 +156,9 @@ main(int argc, char *argv[])
if (*argv && **argv == '+') {
format = *argv;
++argv;
+ } else if (Rflag) {
+ (void)setlocale(LC_TIME, "C");
+ format = "+%a, %-e %b %Y %H:%M:%S %z";
} else
format = "+%a %b %e %H:%M:%S %Z %Y";