Re: CVS commit: src/bin/date

2024-01-22 Thread Christos Zoulas
In article <19118.1705868...@jacaranda.noi.kre.to>,
Robert Elz   wrote:
>Date:Sun, 21 Jan 2024 18:16:28 - (UTC)
>From:chris...@astron.com (Christos Zoulas)
>Message-ID:  
>
>  | I think this is the yacc used by the build process, not the yacc
>  | to build tools with? I.e. will this yacc produce c files usable in
>  | the host compilation environment?
>
>I was also looking at that problem, but in a different direction.
>Rather than making -d work in the tools date (either by somehow
>making parsedate work - which really isn't worth the effort for
>this, or via your hack) but by using -j and specifying the date
>in canonincal form instead of parsedate random form.
>
>That is, it is trivial to make
>
>   date -j '+whatever format you like' 202401220314
>
>work (including in the tools date), provided you can convert the date
>string you're starting with into that canonical form - that takes make
>magic, a topic of which I am barely aware exists, let alone competant,
>so that was as far as I took it...

I should have thought of that, duh. This means adding 4 0's in the Makefile...

christos



Re: CVS commit: src/bin/date

2024-01-21 Thread Robert Elz
Date:Sun, 21 Jan 2024 18:16:28 - (UTC)
From:chris...@astron.com (Christos Zoulas)
Message-ID:  

  | I think this is the yacc used by the build process, not the yacc
  | to build tools with? I.e. will this yacc produce c files usable in
  | the host compilation environment?

I was also looking at that problem, but in a different direction.
Rather than making -d work in the tools date (either by somehow
making parsedate work - which really isn't worth the effort for
this, or via your hack) but by using -j and specifying the date
in canonincal form instead of parsedate random form.

That is, it is trivial to make

date -j '+whatever format you like' 202401220314

work (including in the tools date), provided you can convert the date
string you're starting with into that canonical form - that takes make
magic, a topic of which I am barely aware exists, let alone competant,
so that was as far as I took it...

kre


Re: CVS commit: src/bin/date

2024-01-21 Thread Roland Illig
Am 21.01.2024 um 19:16 schrieb Christos Zoulas:
> In article ,
> Valery Ushakov   wrote:
>> On Sun, Jan 21, 2024 at 11:55:56 -0500, Christos Zoulas wrote:
>>
>>> Consider providing parsedate(3) in libcompat, but then we'd need
>>> yacc...
>>
>> We already have yacc in tools - src/tools/yacc
>
> I think this is the yacc used by the build process, not the yacc
> to build tools with? I.e. will this yacc produce c files usable in
> the host compilation environment?

From my understanding, tools/yacc runs in the host environment and
target the same host environment, as its output is used by tools/lint1,
which runs in the host environment but targets the target environment.

Or might the output from tools/yacc even be platform-independent?

Roland



Re: CVS commit: src/bin/date

2024-01-21 Thread Christos Zoulas
In article ,
Valery Ushakov   wrote:
>On Sun, Jan 21, 2024 at 11:55:56 -0500, Christos Zoulas wrote:
>
>> Consider providing parsedate(3) in libcompat, but then we'd need
>> yacc...
>
>We already have yacc in tools - src/tools/yacc

I think this is the yacc used by the build process, not the yacc
to build tools with? I.e. will this yacc produce c files usable in
the host compilation environment?

christos



Re: CVS commit: src/bin/date

2024-01-21 Thread Valery Ushakov
On Sun, Jan 21, 2024 at 11:55:56 -0500, Christos Zoulas wrote:

> Consider providing parsedate(3) in libcompat, but then we'd need
> yacc...

We already have yacc in tools - src/tools/yacc

-uwe


CVS commit: src/bin/date

2024-01-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jan 21 16:55:56 UTC 2024

Modified Files:
src/bin/date: date.c

Log Message:
Handle -d %Y%m%d in the tools version. This is used in the release notes
Makefile.inc when BUILDID is specified. Consider providing parsedate(3)
in libcompat, but then we'd need yacc...


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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.c
diff -u src/bin/date/date.c:1.65 src/bin/date/date.c:1.66
--- src/bin/date/date.c:1.65	Wed May 31 13:56:54 2023
+++ src/bin/date/date.c	Sun Jan 21 11:55:56 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: date.c,v 1.65 2023/05/31 17:56:54 kim Exp $ */
+/* $NetBSD: date.c,v 1.66 2024/01/21 16:55:56 christos 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.65 2023/05/31 17:56:54 kim Exp $");
+__RCSID("$NetBSD: date.c,v 1.66 2024/01/21 16:55:56 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -98,8 +98,8 @@ main(int argc, char *argv[])
 			nflag = 1;
 			break;
 		case 'd':
-#ifndef HAVE_NBTOOL_CONFIG_H
 			rflag = 1;
+#ifndef HAVE_NBTOOL_CONFIG_H
 			tval = parsedate(optarg, NULL, NULL);
 			if (tval == -1) {
 errx(EXIT_FAILURE,
@@ -107,6 +107,19 @@ main(int argc, char *argv[])
 			}
 			break;
 #else
+			/* handle MMDD, or fail */
+			{
+struct tm tm;
+char *p;
+memset(, 0, sizeof(tm));
+p = strptime(optarg, "%Y%m%d", );
+if (*p == '\0'
+&& tm.tm_year >= 0 && tm.tm_year < 1000
+&& tm.tm_mon >= 0 && tm.tm_mon <= 11
+&& tm.tm_mday >= 1 && tm.tm_mday <= 31
+&& (tval = mktime()) != -1)
+	break;
+			}
 			errx(EXIT_FAILURE,
 			"-d not supported in the tool version");
 #endif



CVS commit: src/bin/date

2024-01-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jan 21 16:55:56 UTC 2024

Modified Files:
src/bin/date: date.c

Log Message:
Handle -d %Y%m%d in the tools version. This is used in the release notes
Makefile.inc when BUILDID is specified. Consider providing parsedate(3)
in libcompat, but then we'd need yacc...


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/bin/date/date.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/date

2023-05-31 Thread Valery Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed May 31 18:04:00 UTC 2023

Modified Files:
src/bin/date: date.1

Log Message:
date(1): sync two [CC]yy]mm]dd]HH]MM[.SS] instances

The markup was the same (modulo Li vs Cm for the dot before the
seconds), but use the same source markup grouping/layout in both to
make this fact more obvious.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/bin/date/date.1

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.53 src/bin/date/date.1:1.54
--- src/bin/date/date.1:1.53	Wed May 31 17:52:02 2023
+++ src/bin/date/date.1	Wed May 31 18:04:00 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: date.1,v 1.53 2023/05/31 17:52:02 uwe Exp $
+.\"	$NetBSD: date.1,v 1.54 2023/05/31 18:04:00 uwe Exp $
 .\"
 .\" Copyright (c) 1980, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -45,13 +45,16 @@
 .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
@@ -93,8 +96,9 @@ provided rather than using the default
 .Ar yy Oc
 .Ar mm Oc
 .Ar dd Oc
-.Ar HH
-.Oc Ar MM Op Cm \&. Ar SS
+.Ar HH Oc
+.Ar MM
+.Op Cm \&. Ar SS
 .Sm on
 format.
 Parsing is done using



CVS commit: src/bin/date

2023-05-31 Thread Valery Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed May 31 18:04:00 UTC 2023

Modified Files:
src/bin/date: date.1

Log Message:
date(1): sync two [CC]yy]mm]dd]HH]MM[.SS] instances

The markup was the same (modulo Li vs Cm for the dot before the
seconds), but use the same source markup grouping/layout in both to
make this fact more obvious.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/bin/date/date.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/date

2023-05-31 Thread Kimmo Suominen
Module Name:src
Committed By:   kim
Date:   Wed May 31 17:56:54 UTC 2023

Modified Files:
src/bin/date: date.c

Log Message:
Add -R to usage


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/bin/date/date.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/date

2023-05-31 Thread Kimmo Suominen
Module Name:src
Committed By:   kim
Date:   Wed May 31 17:56:54 UTC 2023

Modified Files:
src/bin/date: date.c

Log Message:
Add -R to usage


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 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.c
diff -u src/bin/date/date.c:1.64 src/bin/date/date.c:1.65
--- src/bin/date/date.c:1.64	Wed May 31 16:01:53 2023
+++ src/bin/date/date.c	Wed May 31 17:56:54 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: date.c,v 1.64 2023/05/31 16:01:53 kim Exp $ */
+/* $NetBSD: date.c,v 1.65 2023/05/31 17:56:54 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.64 2023/05/31 16:01:53 kim Exp $");
+__RCSID("$NetBSD: date.c,v 1.65 2023/05/31 17:56:54 kim Exp $");
 #endif
 #endif /* not lint */
 
@@ -404,11 +404,11 @@ static void
 usage(void)
 {
 	(void)fprintf(stderr,
-	"Usage: %s [-ajnu] [-d date] [-r seconds] [+format]",
+	"Usage: %s [-ajnRu] [-d date] [-r seconds] [+format]",
 	getprogname());
 	(void)fprintf(stderr, " [[CC]yy]mm]dd]HH]MM[.SS]]\n");
 	(void)fprintf(stderr,
-	"   %s [-ajnu] -f input_format new_date [+format]\n",
+	"   %s [-ajnRu] -f input_format new_date [+format]\n",
 	getprogname());
 	exit(EXIT_FAILURE);
 	/* NOTREACHED */



CVS commit: src/bin/date

2023-05-31 Thread Valery Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed May 31 17:52:02 UTC 2023

Modified Files:
src/bin/date: date.1

Log Message:
date(1): minor markup fixes


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/bin/date/date.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/date

2023-05-31 Thread Valery Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed May 31 17:52:02 UTC 2023

Modified Files:
src/bin/date: date.1

Log Message:
date(1): minor markup fixes


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/bin/date/date.1

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.52 src/bin/date/date.1:1.53
--- src/bin/date/date.1:1.52	Wed May 31 16:01:53 2023
+++ src/bin/date/date.1	Wed May 31 17:52:02 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: date.1,v 1.52 2023/05/31 16:01:53 kim Exp $
+.\"	$NetBSD: date.1,v 1.53 2023/05/31 17:52:02 uwe Exp $
 .\"
 .\" Copyright (c) 1980, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -56,7 +56,7 @@
 .Nm
 .Op Fl ajnRu
 .Fl f Ar input_format
-new_date
+.Ar new_date
 .Op Cm + Ns Ar format
 .Sh DESCRIPTION
 .Nm
@@ -66,7 +66,7 @@ way or set the date.
 Only the superuser may set the date.
 .Pp
 The options are as follows:
-.Bl -tag -width 12n
+.Bl -tag -width Fl
 .It Fl a
 Use
 .Xr adjtime 2
@@ -89,7 +89,7 @@ as the format string to parse the
 provided rather than using the default
 .Sm off
 .Oo Oo Oo Oo Oo
-.Ar cc Oc
+.Ar CC Oc
 .Ar yy Oc
 .Ar mm Oc
 .Ar dd Oc
@@ -135,7 +135,9 @@ The format string may contain any of the
 in the
 .Xr strftime 3
 manual page, as well as any arbitrary text.
-A  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:
 .Pp
@@ -181,7 +183,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
@@ -189,13 +191,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//LC_TIME
-Description of time locale .
+.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



CVS commit: src/bin/date

2023-05-31 Thread Kimmo Suominen
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, ": 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";
 



CVS commit: src/bin/date

2023-05-31 Thread Kimmo Suominen
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.



CVS commit: src/bin/date

2022-10-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 22 20:11:43 UTC 2022

Modified Files:
src/bin/date: date.1 date.c

Log Message:
Add -f option to set the time. From FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/bin/date/date.1
cvs rdiff -u -r1.62 -r1.63 src/bin/date/date.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/date

2022-10-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 22 20:11:43 UTC 2022

Modified Files:
src/bin/date: date.1 date.c

Log Message:
Add -f option to set the time. From FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/bin/date/date.1
cvs rdiff -u -r1.62 -r1.63 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.50 src/bin/date/date.1:1.51
--- src/bin/date/date.1:1.50	Tue May 10 05:07:57 2022
+++ src/bin/date/date.1	Sat Oct 22 16:11:43 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: date.1,v 1.50 2022/05/10 09:07:57 uwe Exp $
+.\"	$NetBSD: date.1,v 1.51 2022/10/22 20:11:43 christos 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 May 10, 2022
+.Dd October 22, 2022
 .Dt DATE 1
 .Os
 .Sh NAME
@@ -53,6 +53,11 @@
 .Ar HH Oc Ar MM Oo
 .Li \&. Ar SS Oc Oc
 .Sm on
+.Nm
+.Op Fl ajnu
+.Fl f Ar input_format
+new_date
+.Op Cm + Ns Ar format
 .Sh DESCRIPTION
 .Nm
 displays the current date and time when invoked without arguments.
@@ -76,6 +81,24 @@ 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.

Index: src/bin/date/date.c
diff -u src/bin/date/date.c:1.62 src/bin/date/date.c:1.63
--- src/bin/date/date.c:1.62	Wed May 26 16:19:51 2021
+++ src/bin/date/date.c	Sat Oct 22 16:11:43 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: date.c,v 1.62 2021/05/26 20:19:51 christos Exp $ */
+/* $NetBSD: date.c,v 1.63 2022/10/22 20:11:43 christos 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.62 2021/05/26 20:19:51 christos Exp $");
+__RCSID("$NetBSD: date.c,v 1.63 2022/10/22 20:11:43 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -64,11 +64,15 @@ __RCSID("$NetBSD: date.c,v 1.62 2021/05/
 #include 
 #include 
 #include 
+#if !HAVE_NBTOOL_CONFIG_H
+#include 
+#endif
 
 #include "extern.h"
 
 static time_t tval;
 static int aflag, jflag, rflag, nflag;
+static char *fmt;
 
 __dead static void badcanotime(const char *, const char *, size_t);
 static void setthetime(const char *);
@@ -87,7 +91,7 @@ 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:jnr:u")) != -1) {
 		switch (ch) {
 		case 'a':		/* adjust time slowly */
 			aflag = 1;
@@ -106,6 +110,9 @@ main(int argc, char *argv[])
 			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;
@@ -152,7 +159,8 @@ main(int argc, char *argv[])
 	if (*argv) {
 		setthetime(*argv);
 		++argv;
-	}
+	} else if (fmt)
+		usage();
 
 	if (*argv && **argv == '+')
 		format = *argv;
@@ -195,6 +203,22 @@ setthetime(const char *p)
 	size_t len;
 	int yearset;
 
+	if ((lt = localtime()) == NULL)
+		err(EXIT_FAILURE, "%lld: localtime", (long long)tval);
+
+	lt->tm_isdst = -1;			/* Divine correct DST */
+
+	if (fmt) {
+		t = strptime(p, fmt, lt);
+		if (t == NULL) {
+			warnx("Failed conversion of ``%s''"
+			" using format ``%s''\n", p, fmt);
+		} else if (*t != '\0')
+			warnx("Ignoring %zu extraneous"
+" characters in date string (%s)",
+strlen(t), t);
+		goto setit;
+	}
 	for (t = p, dot = NULL; *t; ++t) {
 		if (*t == '.') {
 			if (dot == NULL) {
@@ -207,10 +231,6 @@ setthetime(const char *p)
 		}
 	}
 
-	if ((lt = localtime()) == NULL)
-		err(EXIT_FAILURE, "%lld: localtime", (long long)tval);
-
-	lt->tm_isdst = -1;			/* Divine correct DST */
 
 	if (dot != NULL) {			/* .ss */
 		len = strlen(dot);
@@ -325,11 +345,11 @@ setthetime(const char *p)
 		badcanotime("Not enough digits", p, strlen(p) - len);
 	}
 	}
-
+setit:
 	/* convert broken-down time to UTC clock time */
 	if ((new_time = mktime(lt)) == -1) {
 		/* Can this actually happen? */
-		err(EXIT_FAILURE, "%s: mktime", op);
+		err(EXIT_FAILURE, "mktime");
 	}
 
 	/* if jflag is set, don't actually change the time, just return */
@@ -340,6 +360,12 @@ setthetime(const char *p)
 
 	/* set the time */
 #ifndef HAVE_NBTOOL_CONFIG_H
+	struct utmpx utx;
+	memset(, 0, sizeof(utx));
+	utx.ut_type = OLD_TIME;
+	(void)gettimeofday(_tv, NULL);
+	

CVS commit: src/bin/date

2022-05-10 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue May 10 09:07:57 UTC 2022

Modified Files:
src/bin/date: date.1

Log Message:
date(1): Use .Dl for one-liners.  Same output is generated.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/bin/date/date.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/date

2022-05-10 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue May 10 09:07:57 UTC 2022

Modified Files:
src/bin/date: date.1

Log Message:
date(1): Use .Dl for one-liners.  Same output is generated.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/bin/date/date.1

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.49 src/bin/date/date.1:1.50
--- src/bin/date/date.1:1.49	Tue May 10 09:00:39 2022
+++ src/bin/date/date.1	Tue May 10 09:07:57 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: date.1,v 1.49 2022/05/10 09:00:39 uwe Exp $
+.\"	$NetBSD: date.1,v 1.50 2022/05/10 09:07:57 uwe Exp $
 .\"
 .\" Copyright (c) 1980, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -112,9 +112,8 @@ manual page, as well as any arbitrary te
 A  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.
@@ -189,9 +188,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,26 +198,23 @@ 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:
-.Bd -literal -offset indent
-date +%s
-.Ed
+.Pp
+.Dl date +%s
 .Pp
 prints the current time as seconds since the Epoch.
 .Sh DIAGNOSTICS



CVS commit: src/bin/date

2022-05-10 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue May 10 09:00:39 UTC 2022

Modified Files:
src/bin/date: date.1

Log Message:
date(1): Fix the offset in previous.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/bin/date/date.1

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.48 src/bin/date/date.1:1.49
--- src/bin/date/date.1:1.48	Tue May 10 05:37:33 2022
+++ src/bin/date/date.1	Tue May 10 09:00:39 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: date.1,v 1.48 2022/05/10 05:37:33 wiz Exp $
+.\"	$NetBSD: date.1,v 1.49 2022/05/10 09:00:39 uwe Exp $
 .\"
 .\" Copyright (c) 1980, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -217,7 +217,7 @@ sets the time to
 without modifying the date.
 .Pp
 The command:
-.Bd -literal -offset -indent
+.Bd -literal -offset indent
 date +%s
 .Ed
 .Pp



CVS commit: src/bin/date

2022-05-10 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue May 10 09:00:39 UTC 2022

Modified Files:
src/bin/date: date.1

Log Message:
date(1): Fix the offset in previous.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/bin/date/date.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/date

2022-05-09 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue May 10 05:37:33 UTC 2022

Modified Files:
src/bin/date: date.1

Log Message:
date(1): add example for how to get seconds since the Epoch output


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/bin/date/date.1

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.47 src/bin/date/date.1:1.48
--- src/bin/date/date.1:1.47	Sat Jan 27 18:59:38 2018
+++ src/bin/date/date.1	Tue May 10 05:37:33 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: date.1,v 1.47 2018/01/27 18:59:38 wiz Exp $
+.\"	$NetBSD: date.1,v 1.48 2022/05/10 05:37:33 wiz 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 10, 2022
 .Dt DATE 1
 .Os
 .Sh NAME
@@ -61,7 +61,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 12n
 .It Fl a
 Use
 .Xr adjtime 2
@@ -215,6 +215,13 @@ date 1432
 sets the time to
 .Li "2:32 PM" ,
 without modifying the date.
+.Pp
+The command:
+.Bd -literal -offset -indent
+date +%s
+.Ed
+.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.



CVS commit: src/bin/date

2022-05-09 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue May 10 05:37:33 UTC 2022

Modified Files:
src/bin/date: date.1

Log Message:
date(1): add example for how to get seconds since the Epoch output


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/bin/date/date.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/date

2010-02-04 Thread Jeremy C. Reed
Module Name:src
Committed By:   reed
Date:   Thu Feb  4 19:25:22 UTC 2010

Modified Files:
src/bin/date: date.1

Log Message:
For the -d option, refer to parsedate(3) for examples.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/bin/date/date.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/date

2010-02-04 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Feb  4 22:56:11 UTC 2010

Modified Files:
src/bin/date: date.1

Log Message:
Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/bin/date/date.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.