Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/date Add -R option for displaying time in RFC 5322 forma...



details:   https://anonhg.NetBSD.org/src/rev/e1029a15ba76
branches:  trunk
changeset: 376082:e1029a15ba76
user:      kim <kim%NetBSD.org@localhost>
date:      Wed May 31 16:01:53 2023 +0000

description:
Add -R option for displaying time in RFC 5322 format, similar to GNU date.

diffstat:

 bin/date/date.1 |  11 +++++++----
 bin/date/date.c |  14 ++++++++++----
 2 files changed, 17 insertions(+), 8 deletions(-)

diffs (102 lines):

diff -r 8d77f76d1ca0 -r e1029a15ba76 bin/date/date.1
--- a/bin/date/date.1   Wed May 31 13:02:10 2023 +0000
+++ b/bin/date/date.1   Wed May 31 16:01:53 2023 +0000
@@ -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 -r 8d77f76d1ca0 -r e1029a15ba76 bin/date/date.c
--- a/bin/date/date.c   Wed May 31 13:02:10 2023 +0000
+++ b/bin/date/date.c   Wed May 31 16:01:53 2023 +0000
@@ -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 @@
 #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 @@ static char sccsid[] = "@(#)date.c    8.2 (
 #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";
 



Home | Main Index | Thread Index | Old Index