summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Hartmeier <dhartmei@cvs.openbsd.org>2005-11-29 19:07:47 +0000
committerDaniel Hartmeier <dhartmei@cvs.openbsd.org>2005-11-29 19:07:47 +0000
commitf7d2f30f2f00b4e44b9052d09a18808a04b6445c (patch)
tree02873cb9be92b0c834a333b8a891015f6727cb8d /bin
parentfc0261a4cded622555e6afb4c66cd4dbbd0ef295 (diff)
add an option -j which suppresses setting the clock, but parses the date
argument. useful to convert string-to-epoch (with +%s) or just to check whether the argument is parsed correctly before really setting the clock. ok millert@, deraadt@
Diffstat (limited to 'bin')
-rw-r--r--bin/date/date.17
-rw-r--r--bin/date/date.c16
2 files changed, 16 insertions, 7 deletions
diff --git a/bin/date/date.1 b/bin/date/date.1
index 1c1a1d8ebc5..611a611f9b1 100644
--- a/bin/date/date.1
+++ b/bin/date/date.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: date.1,v 1.42 2005/11/07 19:20:05 jmc Exp $
+.\" $OpenBSD: date.1,v 1.43 2005/11/29 19:07:46 dhartmei Exp $
.\" $NetBSD: date.1,v 1.12 1996/03/12 04:32:37 phil Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
@@ -41,7 +41,7 @@
.Nd display or set date and time
.Sh SYNOPSIS
.Nm date
-.Op Fl anu
+.Op Fl ajnu
.Op Fl d Ar dst
.Op Fl r Ar seconds
.Op Fl t Ar minutes_west
@@ -81,6 +81,9 @@ to
.Xr gettimeofday 2
will return a non-zero value for
.Fa tz_dsttime .
+.It Fl j
+Parse the provided date and time and display the result without changing
+the clock.
.It Fl n
By default,
if the
diff --git a/bin/date/date.c b/bin/date/date.c
index 2eba14ae7c4..6384ff566a9 100644
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: date.c,v 1.26 2003/10/15 15:58:22 mpech Exp $ */
+/* $OpenBSD: date.c,v 1.27 2005/11/29 19:07:46 dhartmei Exp $ */
/* $NetBSD: date.c,v 1.11 1995/09/07 06:21:05 jtc Exp $ */
/*
@@ -40,7 +40,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
#else
-static char rcsid[] = "$OpenBSD: date.c,v 1.26 2003/10/15 15:58:22 mpech Exp $";
+static char rcsid[] = "$OpenBSD: date.c,v 1.27 2005/11/29 19:07:46 dhartmei Exp $";
#endif
#endif /* not lint */
@@ -65,7 +65,7 @@ static char rcsid[] = "$OpenBSD: date.c,v 1.26 2003/10/15 15:58:22 mpech Exp $";
extern char *__progname;
time_t tval;
-int retval, nflag;
+int retval, jflag, nflag;
int slidetime;
static void setthetime(char *);
@@ -83,7 +83,7 @@ main(int argc, char *argv[])
tz.tz_dsttime = tz.tz_minuteswest = 0;
rflag = 0;
- while ((ch = getopt(argc, argv, "ad:nr:ut:")) != -1)
+ while ((ch = getopt(argc, argv, "ad:jnr:ut:")) != -1)
switch((char)ch) {
case 'd': /* daylight saving time */
tz.tz_dsttime = atoi(optarg) ? 1 : 0;
@@ -91,6 +91,9 @@ main(int argc, char *argv[])
case 'a':
slidetime++;
break;
+ case 'j': /* don't set */
+ jflag = 1;
+ break;
case 'n': /* don't set network */
nflag = 1;
break;
@@ -227,6 +230,9 @@ setthetime(char *p)
if ((tval = mktime(lt)) < 0)
errx(1, "specified date is outside allowed range");
+ if (jflag)
+ return;
+
/* set the time */
if (nflag || netsettime(tval)) {
if (slidetime) {
@@ -265,7 +271,7 @@ static void
usage(void)
{
(void)fprintf(stderr,
- "usage: %s [-anu] [-d dst] [-r seconds] [-t west] [+format]\n",
+ "usage: %s [-ajnu] [-d dst] [-r seconds] [-t west] [+format]\n",
__progname);
(void)fprintf(stderr,
"%-*s[[[[[[cc]yy]mm]dd]HH]MM[.SS]]\n", strlen(__progname) + 8, "");