Module Name: src Committed By: kim Date: Wed May 31 16:01:53 UTC 2023
Modified Files: src/bin/date: date.1 date.c Log Message: Add -R option for displaying time in RFC 5322 format, similar to GNU date. To generate a diff of this commit: cvs rdiff -u -r1.51 -r1.52 src/bin/date/date.1 cvs rdiff -u -r1.63 -r1.64 src/bin/date/date.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/date/date.1 diff -u src/bin/date/date.1:1.51 src/bin/date/date.1:1.52 --- src/bin/date/date.1:1.51 Sat Oct 22 20:11:43 2022 +++ src/bin/date/date.1 Wed May 31 16:01:53 2023 @@ -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 Index: src/bin/date/date.c diff -u src/bin/date/date.c:1.63 src/bin/date/date.c:1.64 --- src/bin/date/date.c:1.63 Sat Oct 22 20:11:43 2022 +++ src/bin/date/date.c Wed May 31 16:01:53 2023 @@ -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/ #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";