Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-9]: src/bin/date Pull up the following revisions, requested by ki...
details: https://anonhg.NetBSD.org/src/rev/2690de60f383
branches: netbsd-9
changeset: 376154:2690de60f383
user: martin <martin%NetBSD.org@localhost>
date: Sat Jun 03 15:27:13 2023 +0000
description:
Pull up the following revisions, requested by kim in ticket #1640:
bin/date/Makefile up to 1.16
bin/date/date.1 up to 1.54
bin/date/date.c up to 1.65
Add -R option for displaying time in RFC 5322 format, similar to GNU date.
Add -f option to set the time. From FreeBSD.
diffstat:
bin/date/Makefile | 9 ++++-
bin/date/date.1 | 83 +++++++++++++++++++++++++++++++++++++++---------------
bin/date/date.c | 75 +++++++++++++++++++++++++++++++++++++++++-------
3 files changed, 129 insertions(+), 38 deletions(-)
diffs (truncated from 401 to 300 lines):
diff -r d59f41648406 -r 2690de60f383 bin/date/Makefile
--- a/bin/date/Makefile Sat Jun 03 15:17:31 2023 +0000
+++ b/bin/date/Makefile Sat Jun 03 15:27:13 2023 +0000
@@ -1,10 +1,15 @@
-# $NetBSD: Makefile,v 1.15 2011/08/14 10:53:16 christos Exp $
+# $NetBSD: Makefile,v 1.15.46.1 2023/06/03 15:27:13 martin Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
+.include <bsd.init.mk>
+
PROG= date
-SRCS= date.c netdate.c
+SRCS= date.c
+.if !defined(HOSTPROG)
+SRCS+= netdate.c
DPADD+= ${LIBUTIL}
LDADD+= -lutil
+.endif
CPPFLAGS+=-I${.CURDIR}
COPTS.date.c = -Wno-format-nonliteral
diff -r d59f41648406 -r 2690de60f383 bin/date/date.1
--- a/bin/date/date.1 Sat Jun 03 15:17:31 2023 +0000
+++ b/bin/date/date.1 Sat Jun 03 15:27:13 2023 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: date.1,v 1.47 2018/01/27 18:59:38 wiz Exp $
+.\" $NetBSD: date.1,v 1.47.6.1 2023/06/03 15:27:13 martin 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 January 25, 2018
+.Dd May 31, 2023
.Dt DATE 1
.Os
.Sh NAME
@@ -40,19 +40,27 @@
.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
.Sm off
-.Oo Oo Oo Oo Oo Oo
+.Oo
+.Oo Oo Oo Oo Oo
.Ar CC Oc
.Ar yy Oc
.Ar mm Oc
.Ar dd Oc
-.Ar HH Oc Ar MM Oo
-.Li \&. Ar SS Oc Oc
+.Ar HH Oc
+.Ar MM
+.Op Cm \&. Ar SS
+.Oc
.Sm on
+.Nm
+.Op Fl ajnRu
+.Fl f Ar input_format
+.Ar new_date
+.Op Cm + Ns Ar format
.Sh DESCRIPTION
.Nm
displays the current date and time when invoked without arguments.
@@ -61,7 +69,7 @@ way or set the date.
Only the superuser may set the date.
.Pp
The options are as follows:
-.Bl -tag -width Ds
+.Bl -tag -width Fl
.It Fl a
Use
.Xr adjtime 2
@@ -76,6 +84,25 @@ actually changing the system clock.
(See
.Xr parsedate 3
for examples.)
+.It Fl f Ar input_fmt
+Use
+.Ar input_fmt
+as the format string to parse the
+.Ar new_date
+provided rather than using the default
+.Sm off
+.Oo Oo Oo Oo Oo
+.Ar CC Oc
+.Ar yy Oc
+.Ar mm Oc
+.Ar dd Oc
+.Ar HH Oc
+.Ar MM
+.Op Cm \&. Ar SS
+.Sm on
+format.
+Parsing is done using
+.Xr strptime 3 .
.It Fl j
Parse the provided canonical representation of date and time (described below)
and display the result without actually changing the system clock.
@@ -93,6 +120,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
@@ -109,12 +139,13 @@ The format string may contain any of the
in the
.Xr strftime 3
manual page, as well as any arbitrary text.
-A <newline> character is always output after the characters
+A
+.Aq newline
+character is always output after the characters
specified by the format string.
The format string for the default display is:
-.Bd -literal -offset indent
-%a %b %e %H:%M:%S %Z %Y
-.Ed
+.Pp
+.Dl %a %b %e %H:%M:%S %Z %Y
.Pp
If an operand does not have a leading plus sign, it is interpreted as
a value for setting the system's notion of the current date and time.
@@ -156,7 +187,7 @@ and years are handled automatically.
.Sh ENVIRONMENT
The following environment variables affect the execution of
.Nm :
-.Bl -tag -width iTZ
+.Bl -tag -width Ev
.It Ev TZ
The timezone to use when displaying dates.
See
@@ -164,13 +195,14 @@ See
for more information.
.El
.Sh FILES
-.Bl -tag -width /usr/share/zoneinfo/posixrules -compact
+.Bl -tag -width Pa -compact
.It Pa /etc/localtime
Symlink pointing to system's default timezone information file in
.Pa /usr/share/zoneinfo
directory.
-.It Pa /usr/lib/locale/<L>/LC_TIME
-Description of time locale <L>.
+.It Pa /usr/lib/locale/ Ns Ao Ar L Ac Ns Pa /LC_TIME
+Description of time locale
+.Aq Ar L .
.It Pa /usr/share/zoneinfo
Time zone information directory.
.It Pa /usr/share/zoneinfo/posixrules
@@ -189,9 +221,8 @@ is absent, UTC leap seconds are loaded f
.Pa /usr/share/zoneinfo/posixrules .
.Sh EXAMPLES
The command:
-.Bd -literal -offset indent
-date '+DATE: %m/%d/%y%nTIME: %H:%M:%S'
-.Ed
+.Pp
+.Dl date '+DATE: %m/%d/%y%nTIME: %H:%M:%S'
.Pp
will display:
.Bd -literal -offset indent
@@ -200,21 +231,25 @@ TIME: 13:36:16
.Ed
.Pp
The command:
-.Bd -literal -offset indent
-date 8506131627
-.Ed
+.Pp
+.Dl date 8506131627
.Pp
sets the date to
.Dq Li "June 13, 1985, 4:27 PM" .
.Pp
The command:
-.Bd -literal -offset indent
-date 1432
-.Ed
+.Pp
+.Dl date 1432
.Pp
sets the time to
.Li "2:32 PM" ,
without modifying the date.
+.Pp
+The command:
+.Pp
+.Dl date +%s
+.Pp
+prints the current time as seconds since the Epoch.
.Sh DIAGNOSTICS
Exit status is 0 on success, 1 if unable to set the date, and 2
if able to set the local date, but unable to set it globally.
diff -r d59f41648406 -r 2690de60f383 bin/date/date.c
--- a/bin/date/date.c Sat Jun 03 15:17:31 2023 +0000
+++ b/bin/date/date.c Sat Jun 03 15:27:13 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: date.c,v 1.61 2014/09/01 21:42:21 dholland Exp $ */
+/* $NetBSD: date.c,v 1.61.18.1 2023/06/03 15:27:13 martin Exp $ */
/*
* Copyright (c) 1985, 1987, 1988, 1993
@@ -29,6 +29,10 @@
* SUCH DAMAGE.
*/
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT(
@@ -40,7 +44,7 @@
#if 0
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: date.c,v 1.61 2014/09/01 21:42:21 dholland Exp $");
+__RCSID("$NetBSD: date.c,v 1.61.18.1 2023/06/03 15:27:13 martin Exp $");
#endif
#endif /* not lint */
@@ -60,11 +64,15 @@ static char sccsid[] = "@(#)date.c 8.2 (
#include <tzfile.h>
#include <unistd.h>
#include <util.h>
+#if !HAVE_NBTOOL_CONFIG_H
+#include <utmpx.h>
+#endif
#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);
static void setthetime(const char *);
@@ -83,13 +91,14 @@ main(int argc, char *argv[])
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "ad:jnr:u")) != -1) {
+ while ((ch = getopt(argc, argv, "ad:f:jnRr:u")) != -1) {
switch (ch) {
case 'a': /* adjust time slowly */
aflag = 1;
nflag = 1;
break;
case 'd':
+#ifndef HAVE_NBTOOL_CONFIG_H
rflag = 1;
tval = parsedate(optarg, NULL, NULL);
if (tval == -1) {
@@ -97,12 +106,22 @@ main(int argc, char *argv[])
"%s: Unrecognized date format", optarg);
}
break;
+#else
+ errx(EXIT_FAILURE,
+ "-d not supported in the tool version");
+#endif
+ case 'f':
+ fmt = optarg;
+ break;
case 'j': /* don't set time */
jflag = 1;
break;
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");
@@ -137,13 +156,17 @@ 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