* Copyright (c) 1985, 1987, 1988, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char copyright
[] =
"@(#) Copyright (c) 1985, 1987, 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)date.c 8.1 (Berkeley) 5/31/93";
static void setthetime
__P((char *));
static void badformat
__P((void));
static void usage
__P((void));
int logwtmp
__P((char *, char *, char *));
tz
.tz_dsttime
= tz
.tz_minuteswest
= 0;
while ((ch
= getopt(argc
, argv
, "d:nr:ut:")) != EOF
)
case 'd': /* daylight savings time */
tz
.tz_dsttime
= atoi(optarg
) ? 1 : 0;
case 'n': /* don't set network */
case 'r': /* user specified seconds */
case 'u': /* do everything in GMT */
(void)setenv("TZ", "GMT0", 1);
case 't': /* minutes west of GMT */
/* error check; don't allow "PST" */
tz
.tz_minuteswest
= atoi(optarg
);
* If -d or -t, set the timezone or daylight savings time; this
* doesn't belong here, there kernel should not know about either.
if ((tz
.tz_minuteswest
|| tz
.tz_dsttime
) &&
if (!rflag
&& time(&tval
) == -1)
format
= "%a %b %e %H:%M:%S %Z %Y\n";
/* allow the operands in any order */
if (*argv
&& **argv
== '+') {
if (*argv
&& **argv
== '+')
(void)strftime(buf
, sizeof(buf
), format
, localtime(&tval
));
#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
for (t
= p
, dot
= NULL
; *t
; ++t
) {
if (*t
== '.' && dot
== NULL
) {
if (dot
!= NULL
) { /* .ss */
if (lt
->tm_year
< 69) /* hack for 2000 ;-} */
--lt
->tm_mon
; /* time struct is 0 - 11 */
/* convert broken-down time to GMT clock time */
if ((tval
= mktime(lt
)) == -1)
if (nflag
|| netsettime(tval
)) {
logwtmp("|", "date", "");
if (settimeofday(&tv
, NULL
)) {
perror("date: settimeofday");
logwtmp("{", "date", "");
if ((p
= getlogin()) == NULL
)
syslog(LOG_AUTH
| LOG_NOTICE
, "date set by %s", p
);
warnx("illegal time format");
"usage: date [-nu] [-d dst] [-r seconds] [-t west] [+format]\n");
(void)fprintf(stderr
, " [yy[mm[dd[hh]]]]mm[.ss]]\n");