Page MenuHomeFreeBSD

D40159.id122121.diff
No OneTemporary

D40159.id122121.diff

diff --git a/bin/date/date.1 b/bin/date/date.1
--- a/bin/date/date.1
+++ b/bin/date/date.1
@@ -32,7 +32,7 @@
.\" @(#)date.1 8.3 (Berkeley) 4/28/95
.\" $FreeBSD$
.\"
-.Dd April 13, 2023
+.Dd May 19, 2023
.Dt DATE 1
.Os
.Sh NAME
@@ -42,6 +42,7 @@
.\" Display time.
.Nm
.Op Fl nRu
+.Op Fl z Ar output_zone
.Op Fl I Ns Op Ar FMT
.Op Fl r Ar filename
.Op Fl r Ar seconds
@@ -56,6 +57,7 @@
.\" Set time with the default input format.
.Nm
.Op Fl jnRu
+.Op Fl z Ar output_zone
.Op Fl I Ns Op Ar FMT
.Oo
.Sm off
@@ -77,6 +79,7 @@
.\" Set time with the user-provided input format.
.Nm
.Op Fl jnRu
+.Op Fl z Ar output_zone
.Op Fl I Ns Op Ar FMT
.Oo
.Sm off
@@ -202,6 +205,14 @@
or the
.Ev TZ
environment variable.
+.It Fl z Ar output_zone
+Just before printing the time, change to the specified timezone;
+see the description of
+.Ev TZ
+below.
+This can be used with
+.Fl j
+to easily convert time specifications from one zone to another.
.It Xo
.Fl v
.Sm off
diff --git a/bin/date/date.c b/bin/date/date.c
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -95,7 +95,7 @@
bool Iflag, jflag, Rflag;
const char *format;
char buf[1024];
- char *fmt;
+ char *fmt, *outzone = NULL;
char *tmp;
struct vary *v;
const struct vary *badv;
@@ -108,7 +108,7 @@
(void) setlocale(LC_TIME, "");
rflag = 0;
Iflag = jflag = Rflag = 0;
- while ((ch = getopt(argc, argv, "f:I::jnRr:uv:")) != -1)
+ while ((ch = getopt(argc, argv, "f:I::jnRr:uv:z:")) != -1)
switch((char)ch) {
case 'f':
fmt = optarg;
@@ -152,6 +152,9 @@
case 'u': /* do everything in UTC */
(void)setenv("TZ", "UTC0", 1);
break;
+ case 'z':
+ outzone = optarg;
+ break;
case 'v':
v = vary_append(v, optarg);
break;
@@ -189,6 +192,8 @@
format = *argv + 1;
}
+ if (outzone != NULL && setenv("TZ", outzone, 1) != 0)
+ err(1, "setenv(TZ)");
lt = localtime(&tval);
if (lt == NULL)
errx(1, "invalid time");
@@ -211,6 +216,7 @@
*/
setlocale(LC_TIME, "C");
+
(void)strftime(buf, sizeof(buf), format, lt);
printdate(buf);
}
@@ -385,7 +391,7 @@
(void)fprintf(stderr, "%s\n%s\n%s\n",
"usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]",
" "
- "[-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]",
+ "[ -z output_zone ] [-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]",
" "
"[[[[[[cc]yy]mm]dd]HH]MM[.SS] | new_date] [+output_fmt]"
);

File Metadata

Mime Type
text/plain
Expires
Wed, Oct 2, 4:23 AM (21 h, 38 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
13296160
Default Alt Text
D40159.id122121.diff (2 KB)

Event Timeline