CVS commit: src/bin/date
Module Name:src Committed By: kre Date: Tue Sep 17 15:25:39 UTC 2024 Modified Files: src/bin/date: date.1 date.c Log Message: date(1) says: STANDARDS The date utility is expected to be compatible with IEEE Std 1003.2 (“POSIX.2”). yet the format used for the date string arg is: [[CC]yy]mm]dd]HH]MM[.SS]] whereas POSIX demands mmddHHMM[[CC]yy] Why anyone would ever want to use that archaic form is incomprehensible to me, yet, that is what is required. Implement support for the POSIX format if POSIXLY_CORRECT is set in the environment (in the full date(1) build only) in a rather crude way that relies upon the user getting the format correct. Tools builds are unaffected - setting the time is not supported there. (It could be made to work, half setting the time, using -j, is possible in tools builds, but pointless, and this cheap implementation uses strptime() which is not necessarily available to a tools build.) Mention this (very briefly) in the man page. To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/bin/date/date.1 cvs rdiff -u -r1.69 -r1.70 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.56 src/bin/date/date.1:1.57 --- src/bin/date/date.1:1.56 Tue Sep 17 14:56:48 2024 +++ src/bin/date/date.1 Tue Sep 17 15:25:39 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: date.1,v 1.56 2024/09/17 14:56:48 kre Exp $ +.\" $NetBSD: date.1,v 1.57 2024/09/17 15:25:39 kre Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -310,6 +310,15 @@ option can be omitted to parse the time or the second could be replaced by .Fl U to show the parsed time in the local timezone. +.Pp +Either of the commands: +.Pp +.Dl date -u -d 1970-01-01T00:00:00 -U +%c +.Dl date -r 0 +%c +.Pp +print the local time of the +.Ux +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. @@ -350,6 +359,13 @@ The .Nm utility is expected to be compatible with .St -p1003.2 . +However, achieving true compatability requires running +.Nm +with the environment variable +.Ev POSIXLY_CORRECT +set, in order to parse the time string in the +archaic format POSIX demands, rather than the +more rational version described above. .Sh HISTORY A .Nm Index: src/bin/date/date.c diff -u src/bin/date/date.c:1.69 src/bin/date/date.c:1.70 --- src/bin/date/date.c:1.69 Tue Sep 17 14:56:48 2024 +++ src/bin/date/date.c Tue Sep 17 15:25:39 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: date.c,v 1.69 2024/09/17 14:56:48 kre Exp $ */ +/* $NetBSD: date.c,v 1.70 2024/09/17 15:25:39 kre 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.69 2024/09/17 14:56:48 kre Exp $"); +__RCSID("$NetBSD: date.c,v 1.70 2024/09/17 15:25:39 kre Exp $"); #endif #endif /* not lint */ @@ -373,6 +373,23 @@ setthetime(const char *p) strlen(t), t); goto setit; } + if (getenv("POSIXLY_CORRECT") != NULL) { + int yrdigs; + const char * const e = "Bad POSIX format date ``%s''"; + + t = strptime(p, "%m%d%H%M", lt); + if (t == NULL) + errx(EXIT_FAILURE, e, p); + if (*t != '\0') { + yrdigs = strspn(t, "0123456789"); + if (yrdigs != 2 && yrdigs != 4) +errx(EXIT_FAILURE, e, p); + t = strptime(t, yrdigs == 2 ? "%y" : "%Y", lt); + if (t == NULL || *t != '\0') +errx(EXIT_FAILURE, e, p); + } + goto setit; + } #endif for (t = p, dot = NULL; *t; ++t) { if (*t == '.') {
CVS commit: src/bin/date
Module Name:src Committed By: kre Date: Tue Sep 17 15:25:39 UTC 2024 Modified Files: src/bin/date: date.1 date.c Log Message: date(1) says: STANDARDS The date utility is expected to be compatible with IEEE Std 1003.2 (“POSIX.2”). yet the format used for the date string arg is: [[CC]yy]mm]dd]HH]MM[.SS]] whereas POSIX demands mmddHHMM[[CC]yy] Why anyone would ever want to use that archaic form is incomprehensible to me, yet, that is what is required. Implement support for the POSIX format if POSIXLY_CORRECT is set in the environment (in the full date(1) build only) in a rather crude way that relies upon the user getting the format correct. Tools builds are unaffected - setting the time is not supported there. (It could be made to work, half setting the time, using -j, is possible in tools builds, but pointless, and this cheap implementation uses strptime() which is not necessarily available to a tools build.) Mention this (very briefly) in the man page. To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 src/bin/date/date.1 cvs rdiff -u -r1.69 -r1.70 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
Module Name:src Committed By: kre Date: Tue Sep 17 14:56:48 UTC 2024 Modified Files: src/bin/date: date.1 date.c Log Message: Add -U and -z options to date(1). -U allows the (internal) TZ setting to be returned to what it was when date started running. -z zone sets TZ to be "zone" unless that is an empty string, in which case it causes TZ to be removed from the environment. These can be used together to manipulate TZ around parsing of a -d arg, to allow its parsing to be done in a different zone than the one used for output, and all unrelated to the initial TZ setting (or system default). Note that these new options only appear in the first synopsis form in both the man page and usage(), as -d also appears only there, and these options make little sense without also using -d. This is a very simple change which amounts to no more that a few setenv() and unsetenv() calls. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/bin/date/date.1 cvs rdiff -u -r1.68 -r1.69 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
Module Name:src Committed By: kre Date: Tue Sep 17 14:56:48 UTC 2024 Modified Files: src/bin/date: date.1 date.c Log Message: Add -U and -z options to date(1). -U allows the (internal) TZ setting to be returned to what it was when date started running. -z zone sets TZ to be "zone" unless that is an empty string, in which case it causes TZ to be removed from the environment. These can be used together to manipulate TZ around parsing of a -d arg, to allow its parsing to be done in a different zone than the one used for output, and all unrelated to the initial TZ setting (or system default). Note that these new options only appear in the first synopsis form in both the man page and usage(), as -d also appears only there, and these options make little sense without also using -d. This is a very simple change which amounts to no more that a few setenv() and unsetenv() calls. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/bin/date/date.1 cvs rdiff -u -r1.68 -r1.69 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.55 src/bin/date/date.1:1.56 --- src/bin/date/date.1:1.55 Tue Sep 17 10:08:38 2024 +++ src/bin/date/date.1 Tue Sep 17 14:56:48 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: date.1,v 1.55 2024/09/17 10:08:38 kre Exp $ +.\" $NetBSD: date.1,v 1.56 2024/09/17 14:56:48 kre Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -40,9 +40,10 @@ .Nd display or set date and time .Sh SYNOPSIS .Nm -.Op Fl ajnRu +.Op Fl ajnRUu .Op Fl d Ar date .Op Fl r Ar seconds +.Op Fl z Ar zone .Op Cm + Ns Ar format .Sm off .Oo @@ -127,14 +128,35 @@ specification in RFC 5322 (Internet Mess Print out the date and time that is .Ar seconds from the Epoch. +.It Fl U +Reset the timezone used by +.Nm +to that which existed when it was invoked. +This is only useful after an earlier +.Fl u +or +.Fl z +option. .It Fl u Display or set the date in UTC (universal) time. +.It Fl z Ar zone +Set the timezone to be used by +.Nm +to +.Ar zone . +If +.Ar zone +is an empty string, revert to the system's +default timezone (ignoring any setting of +.Ev TZ ) . .El .Pp Note the -.Fl d +.Fl d , +.Fl U , +.Fl u , and -.Fl u +.Fl z options are applied when encountered, hence specifying .Fl u before @@ -270,6 +292,24 @@ The command: .Dl date +%s .Pp prints the current time as seconds since the Epoch. +.Pp +The command: +.Pp +.Dl date -z America/Chicago -d 13:00 -z Asia/Tokyo +%H:%M +.Pp +indicates what the time will be in Tokyo when it is 13:00 +in Chicago. +Any +.Xr strftime 3 +string could be used for the output. +The first +.Fl z +option can be omitted to parse the time as specified by +.Ev TZ +.Pq usually the local timezone , +or the second could be replaced by +.Fl U +to show the parsed time in the local timezone. .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. Index: src/bin/date/date.c diff -u src/bin/date/date.c:1.68 src/bin/date/date.c:1.69 --- src/bin/date/date.c:1.68 Tue Sep 17 11:30:11 2024 +++ src/bin/date/date.c Tue Sep 17 14:56:48 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: date.c,v 1.68 2024/09/17 11:30:11 kre Exp $ */ +/* $NetBSD: date.c,v 1.69 2024/09/17 14:56:48 kre 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.68 2024/09/17 11:30:11 kre Exp $"); +__RCSID("$NetBSD: date.c,v 1.69 2024/09/17 14:56:48 kre Exp $"); #endif #endif /* not lint */ @@ -96,11 +96,14 @@ main(int argc, char *argv[]) int ch; long long val; struct tm *tm; + char *default_tz; setprogname(argv[0]); (void)setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "ad:f:jnRr:u")) != -1) { + default_tz = getenv("TZ"); + + while ((ch = getopt(argc, argv, "ad:f:jnRr:Uuz:")) != -1) { switch (ch) { case 'a': /* adjust time slowly */ aflag = 1; @@ -151,9 +154,21 @@ main(int argc, char *argv[]) rflag = 1; tval = (time_t)val; break; + case 'U': /* reset to default timezone */ + if (default_tz) +(void)setenv("TZ", default_tz, 1); + else +(void)unsetenv("TZ"); + break; case 'u': /* do everything in UTC */ (void)setenv("TZ", "UTC0", 1); break; + case 'z': + if (optarg[0] == '\0') +(void)unsetenv("TZ"); + else +(void)setenv("TZ", optarg, 1); + break; default: usage(); } @@ -538,9 +553,10 @@ static void usage(void) { (void)fprintf(stderr, - "Usage: %s [-ajnRu] [-d date] [-r seconds] [+format]", + "Usage: %s [-ajnRUu] [-d date] [-r seconds] [-z zone] [+format]", getprogname()); - (void)fprintf(stderr, " [[CC]yy]mm]dd]HH]MM[.SS]]\n"); + (void)fprintf(stderr, "\n\
CVS commit: src/bin/date
Module Name:src Committed By: kre Date: Tue Sep 17 11:30:11 UTC 2024 Modified Files: src/bin/date: date.c Log Message: PR lib/58674 (and I suspect, several others) Stop expecting strptime(3) in the tools build, it is an XSI function, and the tools builds do not set up the environment to expect XSI functions to be available. This means dropping support for the -f option in the tools date (which shouldn't matter, -f sets the format for the string used to set the time, which the tools date does not support), and open coding parsing for the -d option in the tools build. There should be no changes to the date(1) that is installed in /bin As a (minor) benefit, the tools -d support has become somewhat more flexible than the previous simple strptime() implementation allowed, and also does better error checking (no more Feb 30 etc). Note: no change to the usage message, if -f is passed to the tools date it will elicit a usage which says that -f is supported... (that's just laziness...) To generate a diff of this commit: cvs rdiff -u -r1.67 -r1.68 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
Module Name:src Committed By: kre Date: Tue Sep 17 11:30:11 UTC 2024 Modified Files: src/bin/date: date.c Log Message: PR lib/58674 (and I suspect, several others) Stop expecting strptime(3) in the tools build, it is an XSI function, and the tools builds do not set up the environment to expect XSI functions to be available. This means dropping support for the -f option in the tools date (which shouldn't matter, -f sets the format for the string used to set the time, which the tools date does not support), and open coding parsing for the -d option in the tools build. There should be no changes to the date(1) that is installed in /bin As a (minor) benefit, the tools -d support has become somewhat more flexible than the previous simple strptime() implementation allowed, and also does better error checking (no more Feb 30 etc). Note: no change to the usage message, if -f is passed to the tools date it will elicit a usage which says that -f is supported... (that's just laziness...) To generate a diff of this commit: cvs rdiff -u -r1.67 -r1.68 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.67 src/bin/date/date.c:1.68 --- src/bin/date/date.c:1.67 Tue Sep 17 09:55:38 2024 +++ src/bin/date/date.c Tue Sep 17 11:30:11 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: date.c,v 1.67 2024/09/17 09:55:38 kre Exp $ */ +/* $NetBSD: date.c,v 1.68 2024/09/17 11:30:11 kre 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.67 2024/09/17 09:55:38 kre Exp $"); +__RCSID("$NetBSD: date.c,v 1.68 2024/09/17 11:30:11 kre Exp $"); #endif #endif /* not lint */ @@ -72,12 +72,17 @@ __RCSID("$NetBSD: date.c,v 1.67 2024/09/ static time_t tval; 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 *); __dead static void usage(void); +#if HAVE_NBTOOL_CONFIG_H +static int parse_iso_datetime(time_t *, const char *); +#else +static char *fmt; +#endif + #if !defined(isleap) # define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) #endif @@ -103,33 +108,24 @@ main(int argc, char *argv[]) break; case 'd': rflag = 1; -#ifndef HAVE_NBTOOL_CONFIG_H +#ifdef HAVE_NBTOOL_CONFIG_H + if (parse_iso_datetime(&tval, optarg)) +break; + errx(EXIT_FAILURE, + "-d only supports ISO format in the tool version"); + break; +#else + errno = 0; tval = parsedate(optarg, NULL, NULL); - if (tval == -1) { + if (tval == -1 && errno != 0) { errx(EXIT_FAILURE, "%s: Unrecognized date format", optarg); } break; -#else - /* handle MMDD, or fail */ - { -struct tm tm; -char *p; -memset(&tm, 0, sizeof(tm)); -p = strptime(optarg, "%Y%m%d", &tm); -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(&tm)) != -1) - break; - } - errx(EXIT_FAILURE, - "-d not supported in the tool version"); -#endif case 'f': fmt = optarg; break; +#endif case 'j': /* don't set time */ jflag = 1; break; @@ -182,8 +178,11 @@ main(int argc, char *argv[]) if (*argv) { setthetime(*argv); ++argv; - } else if (fmt) +#ifndef HAVE_NBTOOL_CONFIG_H + } else if (fmt) { usage(); +#endif + } if (*argv && **argv == '+') format = *argv; @@ -216,6 +215,122 @@ badcanotime(const char *msg, const char #define ATOI2(s) ((s) += 2, ((s)[-2] - '0') * 10 + ((s)[-1] - '0')) +#if HAVE_NBTOOL_CONFIG_H + +inline static int +digitstring(const char *s, int len) +{ + while (--len > 0) { + if (!isdigit(*(unsigned char *)s)) + return 0; + s++; + } + return 1; +} + +static int +parse_iso_datetime(time_t * res, const char * string) +{ + struct tm tm; + time_t t; + + memset(&tm, 0, sizeof tm); + + if (!digitstring(string, 4)) + return 0; + tm.tm_year = ATOI2(string) * 100; + tm.tm_year += ATOI2(string); + tm.tm_year -= 1900; + + if (*string == '-') + string++; + + if (!digitstring(string, 2)) + return 0; + + tm.tm_mon = ATOI2(string); + if (tm.tm_mon < 1 || tm.tm_mon > 12) + return 0; + tm.tm_mon--; + + if (*string == '-') + string++; + + if (!digitstring(string, 2)) + return 0; + + tm.tm_mday = ATOI2(string); + if (tm.tm_mday < 1) + return 0; + switch (tm.tm_mon) { + case 0: case 2: case 4: case 6: case 7: case 9: case 11: + if (tm.tm_mday > 31) + return 0; + break; + case 3: case 5: case 8: case 10: + if (tm.tm_mday > 30) + return 0; + break; + case 1: + if (tm.tm_mday > 28 + isleap(tm.tm_year + 1900)) + return 0; + break; + default: + abort(); + } + + do { + if (*string == '
CVS commit: src/bin/date
Module Name:src Committed By: kre Date: Tue Sep 17 10:08:38 UTC 2024 Modified Files: src/bin/date: date.1 Log Message: Note that the order in which the -u and -d options are given matters. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 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
Module Name:src Committed By: kre Date: Tue Sep 17 10:08:38 UTC 2024 Modified Files: src/bin/date: date.1 Log Message: Note that the order in which the -u and -d options are given matters. To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 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.54 src/bin/date/date.1:1.55 --- src/bin/date/date.1:1.54 Wed May 31 18:04:00 2023 +++ src/bin/date/date.1 Tue Sep 17 10:08:38 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: date.1,v 1.54 2023/05/31 18:04:00 uwe Exp $ +.\" $NetBSD: date.1,v 1.55 2024/09/17 10:08:38 kre 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 31, 2023 +.Dd September 17, 2024 .Dt DATE 1 .Os .Sh NAME @@ -131,6 +131,26 @@ from the Epoch. Display or set the date in UTC (universal) time. .El .Pp +Note the +.Fl d +and +.Fl u +options are applied when encountered, hence specifying +.Fl u +before +.Fl d +will cause the +.Ar date +to be parsed as coordinated universal time, by default, +whereas if +.Fl u +is specified after +.Fl d +the +.Ar date +will be parsed using the default timezone, then +output will be generated in UTC. +.Pp An operand with a leading plus .Pq Cm + sign signals a user-defined format
CVS commit: src/bin/date
Module Name:src Committed By: kre Date: Tue Sep 17 09:55:38 UTC 2024 Modified Files: src/bin/date: date.c Log Message: isleap() is not a standard function/macro, so if none of the include files have defined a macro of that name, define it ourselves. To generate a diff of this commit: cvs rdiff -u -r1.66 -r1.67 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.66 src/bin/date/date.c:1.67 --- src/bin/date/date.c:1.66 Sun Jan 21 16:55:56 2024 +++ src/bin/date/date.c Tue Sep 17 09:55:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: date.c,v 1.66 2024/01/21 16:55:56 christos Exp $ */ +/* $NetBSD: date.c,v 1.67 2024/09/17 09:55:38 kre 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.66 2024/01/21 16:55:56 christos Exp $"); +__RCSID("$NetBSD: date.c,v 1.67 2024/09/17 09:55:38 kre Exp $"); #endif #endif /* not lint */ @@ -78,6 +78,10 @@ __dead static void badcanotime(const cha static void setthetime(const char *); __dead static void usage(void); +#if !defined(isleap) +# define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) +#endif + int main(int argc, char *argv[]) {
CVS commit: src/bin/date
Module Name:src Committed By: kre Date: Tue Sep 17 09:55:38 UTC 2024 Modified Files: src/bin/date: date.c Log Message: isleap() is not a standard function/macro, so if none of the include files have defined a macro of that name, define it ourselves. To generate a diff of this commit: cvs rdiff -u -r1.66 -r1.67 src/bin/date/date.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/bin/date
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
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
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
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
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
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(&tm, 0, sizeof(tm)); +p = strptime(optarg, "%Y%m%d", &tm); +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(&tm)) != -1) + break; + } errx(EXIT_FAILURE, "-d not supported in the tool version"); #endif
CVS commit: src/bin/date
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
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
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
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
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
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
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
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
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
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
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(&tval)) == 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(&tval)) == 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(&utx, 0, sizeof(utx)); + utx.ut_type = OLD_TIME; + (void)gettimeofday(&ut
CVS commit: src/bin/date
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
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
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
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
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
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
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.
CVS commit: src/bin/date
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.