diff options
author | jmg <jmg@FreeBSD.org> | 1999-05-14 00:28:41 +0000 |
---|---|---|
committer | jmg <jmg@FreeBSD.org> | 1999-05-14 00:28:41 +0000 |
commit | 80ee25f43717db8a33c0838660bbcb5895d4c3f4 (patch) | |
tree | e90f2133a20b16a55faacf6975b9cfa7db0d46e6 /bin/date | |
parent | e33fdd052056c7d8859223f35e1f41a531c0952d (diff) | |
download | FreeBSD-src-80ee25f43717db8a33c0838660bbcb5895d4c3f4.zip FreeBSD-src-80ee25f43717db8a33c0838660bbcb5895d4c3f4.tar.gz |
the month and three days are up for -hackers and the 24hrs for -committers.
add a -j flag that tells date not to try to set the date. This allows you
to use date as a userland interface to strptime.
example:
TZ=GMT date -j -f "%a, %d %b %Y %T %Z" "Sun, 08 Nov 1998 02:22:20 GMT" +%s
which is the standard format for Last-modified headers in HTTP requests.
only one to respond: eivind
Diffstat (limited to 'bin/date')
-rw-r--r-- | bin/date/date.1 | 10 | ||||
-rw-r--r-- | bin/date/date.c | 44 |
2 files changed, 34 insertions, 20 deletions
diff --git a/bin/date/date.1 b/bin/date/date.1 index 271a684..8837787 100644 --- a/bin/date/date.1 +++ b/bin/date/date.1 @@ -33,7 +33,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)date.1 8.3 (Berkeley) 4/28/95 -.\" $Id: date.1,v 1.27 1999/03/09 09:38:53 brian Exp $ +.\" $Id: date.1,v 1.28 1999/05/08 10:19:59 kris Exp $ .\" .Dd November 17, 1993 .Dt DATE 1 @@ -43,7 +43,7 @@ .Nd display or set date and time .Sh SYNOPSIS .Nm date -.Op Fl nu +.Op Fl jnu .Op Fl d Ar dst .Op Fl r Ar seconds .Op Fl t Ar minutes_west @@ -77,6 +77,12 @@ the default .Ar [[[[yy]mm]dd]HH]MM[.ss] format. Parsing is done using .Xr strptime 3 . +.It Fl j +Do not try to set the date. This allows you to use the +.Fl f +flag in addition to the +.Cm + +option to convert one date format to another. .It Fl n The utility .Xr timed 8 diff --git a/bin/date/date.c b/bin/date/date.c index e116e3d..5749417 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -42,7 +42,7 @@ static char const copyright[] = static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95"; #endif static const char rcsid[] = - "$Id: date.c,v 1.26 1998/10/03 16:29:59 alex Exp $"; + "$Id: date.c,v 1.27 1999/03/09 09:38:54 brian Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -61,9 +61,9 @@ static const char rcsid[] = #include "vary.h" time_t tval; -int retval, nflag; +int retval; -static void setthetime __P((const char *, const char *)); +static void setthetime __P((const char *, const char *, int, int)); static void badformat __P((void)); static void usage __P((void)); @@ -78,6 +78,7 @@ main(argc, argv) extern char *optarg; struct timezone tz; int ch, rflag; + int jflag, nflag; char *format, buf[1024]; char *endptr, *fmt; int set_timezone; @@ -90,8 +91,9 @@ main(argc, argv) (void) setlocale(LC_TIME, ""); tz.tz_dsttime = tz.tz_minuteswest = 0; rflag = 0; + jflag = nflag = 0; set_timezone = 0; - while ((ch = getopt(argc, argv, "d:f:nr:t:uv:")) != -1) + while ((ch = getopt(argc, argv, "d:f:jnr:t:uv:")) != -1) switch((char)ch) { case 'd': /* daylight savings time */ tz.tz_dsttime = strtol(optarg, &endptr, 10) ? 1 : 0; @@ -102,6 +104,9 @@ main(argc, argv) case 'f': fmt = optarg; break; + case 'j': + jflag = 1; /* don't set time */ + break; case 'n': /* don't set network */ nflag = 1; break; @@ -147,7 +152,7 @@ main(argc, argv) } if (*argv) { - setthetime(fmt, *argv); + setthetime(fmt, *argv, jflag, nflag); ++argv; } else if (fmt != NULL) usage(); @@ -171,9 +176,10 @@ main(argc, argv) #define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2; void -setthetime(fmt, p) +setthetime(fmt, p, jflag, nflag) const char *fmt; register const char *p; + int jflag, nflag; { register struct tm *lt; struct timeval tv; @@ -251,19 +257,21 @@ setthetime(fmt, p) if ((tval = mktime(lt)) == -1) errx(1, "nonexistent time"); - /* set the time */ - if (nflag || netsettime(tval)) { - logwtmp("|", "date", ""); - tv.tv_sec = tval; - tv.tv_usec = 0; - if (settimeofday(&tv, (struct timezone *)NULL)) - err(1, "settimeofday (timeval)"); - logwtmp("{", "date", ""); - } + if (!jflag) { + /* set the time */ + if (nflag || netsettime(tval)) { + logwtmp("|", "date", ""); + tv.tv_sec = tval; + tv.tv_usec = 0; + if (settimeofday(&tv, (struct timezone *)NULL)) + err(1, "settimeofday (timeval)"); + logwtmp("{", "date", ""); + } - if ((p = getlogin()) == NULL) - p = "???"; - syslog(LOG_AUTH | LOG_NOTICE, "date set by %s", p); + if ((p = getlogin()) == NULL) + p = "???"; + syslog(LOG_AUTH | LOG_NOTICE, "date set by %s", p); + } } static void |