History log of /freebsd-current/bin/date/date.c
Revision Date Author Comments
# dafb424b 28-Apr-2024 Dag-Erling Smørgrav <des@FreeBSD.org>

date: Correctly check outcome of mktime().

X-MFC-With: 7b390cb63689
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44982


# 7b390cb6 26-Apr-2024 Mateusz Piotrowski <0mp@FreeBSD.org>

date: Fix tests by initializing timespec structure

The tests related to nanosecond support were failing on amd64 due to
uninitialized timespec structure.

Fixes: eeb04a736cb9 date: Add support for nanoseconds
Reviewed by: markj
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D44975


# eeb04a73 21-Apr-2024 Mateusz Piotrowski <0mp@FreeBSD.org>

date: Add support for nanoseconds

This patch introduces support for a conversion specification for
nanoseconds.

The format of %N is meant to be compatible with that of GNU date.

The nanoseconds conversion specification is implemented directly in
date(1) instead of libc (in strftime(3)) to avoid introducing
non-standard functions to libc at this time and modifying struct tm.

Apart from introducing the nanoseconds conversion specification, this
patch brings the following changes:

- The "ns" format for ISO 8061 dates is now unlocked. E.g., date -Ins
prints:
2024-04-22T12:20:28,763742224+02:00
- The -r flag when fed a file is now aware of the nanosecond part of the last
modification time.
- date(1) is now able to set the time with nanosecond precision. It is
not possible as of now to do that by specifying nanoseconds directly
via the command-line arguments. Instead, the -r flag can be used.
- date(1) is now using the clock_gettime(3) family of functions instead
of ctime(3) family of functions where possible.

Reviewed by: des, markj
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D44905


# e043f372 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# 90aea514 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# e9746806 07-Jul-2023 Alfonso Gregory <gfunni234@gmail.com>

Mark usage function as __dead2 in programs where it does not return

In most cases, usage does not return, so mark them as __dead2. For the
cases where they do return, they have not been marked __dead2.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/735


# 31edf56b 19-May-2023 Baptiste Daroussin <bapt@FreeBSD.org>

date: add -z output_zone option

Inpired by OpenBSD date(1), this option allows to do timezone conversion
via the date(1) command.

For example, to determine when the BSDCan livestream begins for me:

$ env -i TZ=EST5EDT date -z Europe/Paris -j 0900

MFC After: 1 week
Reviewed by: kib, bcr (manpage)
Differential Revision: https://reviews.freebsd.org/D40159


# c537bf9d 02-Nov-2021 Mateusz Piotrowski <0mp@FreeBSD.org>

date: Capitalize seconds string in synopses

This makes it consistent with other date(1) implementations. Also, it
feels more consistent since hours and minutes are already represented as
HH and MM respectively.

MFC after: 3 days


# a12b16f4 02-Nov-2021 Mateusz Piotrowski <0mp@FreeBSD.org>

date: Clean up synopses

MFC after: 3 days


# 8b82def3 23-Apr-2019 Warner Losh <imp@FreeBSD.org>

Restore the -n flag parsing, but ignore it.

Since D19668 was done, new users of the -n flag have surfaced. Parse
and ignore it on the command line until they can be updated.

Suggested by: rgrimes (in D19668).


# e77a99c1 21-Mar-2019 Warner Losh <imp@FreeBSD.org>

Remove -n flag, fix setting date / time

r342139 bork setting the date. This fixes it by simply removing the -n
flag.

Differential Revision: https://reviews.freebsd.org/D19668


# d24ba0bb 11-Mar-2019 Warner Losh <imp@FreeBSD.org>

Remove now useless -d and -t flags.

These were used to set dst flag and minutes west of UTC
respectively. These are obsolete and have been removed form the
kernel. These existed primarily to faithfully emulate early
Unix ABIs that have been removed from FreeBSD.

Reviewed by: jbh@, brooks@
Differential Revision: https://reviews.freebsd.org/D19550


# 53fc043d 15-Dec-2018 George V. Neville-Neil <gnn@FreeBSD.org>

Remove, the now very outdated, timed.

Submitted by: Kyle Spiers ksspiers at gmail
Reviewed by: bcr,brooks,bz,sbruno
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D18505


# 2c77ec54 04-Aug-2018 Conrad Meyer <cem@FreeBSD.org>

date(1): Add ISO 8601 formatting option

The new flag is named '-I'. It is documented in the manual page and covered
by basic unit tests.


# dfb1d80f 23-Jan-2018 Warner Losh <imp@FreeBSD.org>

Fill in ut_id. While it's not relevant to the {OLD,NEW}_TIME entries,
we shouldn't leak stack garbage into the field.

Sponsored by: Netflix


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# 81912964 20-Jul-2017 Ed Maste <emaste@FreeBSD.org>

date: avoid crash on invalid time

localtime(3) returns NULL when passed an invalid time_t but date(1)
previously did not handle it. Exit with an error in that case.

PR: 220828
Reported by: Vinícius Zavam
Reviewed by: cem, kevans
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D11660


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 8b45db8e 07-May-2015 Xin LI <delphij@FreeBSD.org>

date(1): Make -r behave like GNU's version when the option can not be
interpreted as a number, which checks the file's modification time and
use that as the date/time value.

This improves compatibility with GNU coreutils's version of time(1).

MFC after: 2 weeks


# b69ced8d 26-Apr-2014 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>

date(1): Add "-R" flag to use RFC 2822 date and time output format

As stated in the man page, this is equivalent to use "%a, %d %b %Y %T %z"
as the output format while LC_TIME is set to the "C" locale.

This is compatible with date(1) from the GNU core utilities.


# 902d9eaf 01-Sep-2012 Ed Schouten <ed@FreeBSD.org>

Rework all non-contributed files that use `struct timezone'.

This structure is not part of POSIX. According to POSIX, gettimeofday()
has the following prototype:

int gettimeofday(struct timeval *restrict tp, void *restrict tzp);

Also, POSIX states that gettimeofday() shall return 0 (as long as tzp is
not used). Remove dead error handling code. Also use NULL for a
nul-pointer instead of integer 0.

While there, change all pieces of code that only use tv_sec to use
time(3), as this provides less overhead.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 759dba8c 13-Jan-2010 Ed Schouten <ed@FreeBSD.org>

Port everything in bin/ from utmp to utmpx.

date: use libc utmpx routines instead of the ones provided by libulog.
pax: don't depend on <utmp.h>


# 9b796f44 05-Dec-2009 Ed Schouten <ed@FreeBSD.org>

Let date(1) use utmpx instead of logwtmp().

utmpx also has OLD_TIME/NEW_TIME messages, which seem to be intended for
the same purpose as how we call logwtmp() here.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# a6555081 07-Feb-2008 Ruslan Ermilov <ru@FreeBSD.org>

Don't reset DST computed by strptime() (when e.g. setting the
date via -f %s).

Reported by: Eugene Grosbein
Diagnosed by: Miguel Lopes Santos Ramos


# 9ddb49cb 10-Jan-2005 Warner Losh <imp@FreeBSD.org>

/*- or .\"- or #- to begin license clauses.


# 6195fb41 06-Apr-2004 Mark Murray <markm@FreeBSD.org>

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 662713f2 04-Mar-2004 Mike Makonnen <mtm@FreeBSD.org>

Rev. 1.32 moved a comment to the wrong line. The hack refered to
in the comment applies to a decision that needs to be made in relation
to the year 2000.

In fact, that statement probably should be changed to be
more generic (getting the year from the current time perhaps). Otherwise,
starting in 2069 two digit year conversions in date(1) will start assuming
1900 instead of 2000. hehe.


# 4566e7a4 04-Oct-2003 Diomidis Spinellis <dds@FreeBSD.org>

Check for write errors; report and exit with error value.


# e869e507 04-Feb-2003 Philippe Charnier <charnier@FreeBSD.org>

Enclose sccsid according to style(9).
udp/timed -> timed/udp


# 4e3b1d65 18-Oct-2002 Mark Murray <markm@FreeBSD.org>

Staticify for lint.


# 5eb43ac2 29-Jun-2002 David E. O'Brien <obrien@FreeBSD.org>

Consistently use __FBSDID


# 9afa09cd 22-Feb-2002 Mark Murray <markm@FreeBSD.org>

Fix warnings inspired by lint, a commercial lint and WARNS=4.


# f9bcb0be 01-Feb-2002 Warner Losh <imp@FreeBSD.org>

o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
they already are.

Approved by: arch@, new style(9)


# cd9c4257 27-Oct-2001 Matthew Dillon <dillon@FreeBSD.org>

Remove assumption that time_t is an int

MFC after: 1 day


# 1adbddec 09-Jun-2001 Dima Dorfman <dd@FreeBSD.org>

Add -j to the usage string.

PR: 27986
Submitted by: Cyrille Lefevre <clefevre@redirect.to>


# 10d86572 17-May-2001 Ruslan Ermilov <ru@FreeBSD.org>

Fix an off-by-hour bug when crossing Daylight Saving Time boundary.

PR: bin/27399
Submitted by: "Crist J. Clark" <crist.clark@globalstar.com>
MFC after: 3 days


# 2c15efcf 15-Aug-2000 Warner Losh <imp@FreeBSD.org>

Don't explicitly declare optarg and optind. These are declared in
unistd.h, which is already included.


# b4a3a038 22-Jul-2000 John W. De Boskey <jwd@FreeBSD.org>

Expand the -r option to support hex. Though undocumented, the -r
option already supported octal. Add a comment to the -r option
in the man page so it's a bit more specific.

Discrepancy brought to my attention by: sasdrq@unx.sas.com
Approved by: jkh


# d5dc63cc 19-May-2000 Daniel Baker <dbaker@FreeBSD.org>

Correct confusion and differentiate appropriately between GMT and UTC when
date is launched with the "u" argument. It now operates in the documented
manner.

Fix typo in date man page.

Submitted by: David McNett <nugget@slacker.com>


# a82111c3 29-Dec-1999 Sheldon Hearn <sheldonh@FreeBSD.org>

Back out previous commit and replace with a cleaner solution adapted
from the source attributed below. In particular, this removes a goto
inside a switch and replaces those horrendous ATOI macros with
something acceptable.

More clean-ups to come.

PR: bin/14151
Reported by: Christian Weisgerber <naddy@mips.rhein-neckar.de>
Obtained from: NetBSD


# 646e0924 10-Nov-1999 Sheldon Hearn <sheldonh@FreeBSD.org>

Allow the year to be specified with an optional century.

PR: 14472
Reported by: j_guojun@lbl.gov (Jin Guojun)


# 2a456239 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# d430c0c1 25-Jun-1999 Martin Cracauer <cracauer@FreeBSD.org>

Don't continue if parsing failed when -f is in use. Exit with nonzero value.


# 3bc1b1bb 13-May-1999 John-Mark Gurney <jmg@FreeBSD.org>

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


# 269dfbee 09-Mar-1999 Brian Somers <brian@FreeBSD.org>

Support seconds with -v.
PR: 6308
Submitted by: Max Euston <meuston@jmrodgers.com>


# f97fe122 03-Oct-1998 Alexander Langer <alex@FreeBSD.org>

Added missing #include <string.h>


# 574d1206 13-May-1998 Philippe Charnier <charnier@FreeBSD.org>

Restore Lite-2 sccsid. Restore include of sys/param.h.


# cbf6f7d3 06-May-1998 Philippe Charnier <charnier@FreeBSD.org>

Correct use of .Nm and other cosmetics. Add rcsid. Remove unused #inc.


# c1e8822a 25-Jan-1998 John Birrell <jb@FreeBSD.org>

Cast a size_t to a long to avoid a gcc warning.


# ad1c694b 10-Dec-1997 Brian Somers <brian@FreeBSD.org>

Put [+format] at the end of the usage message.
Make `date -?' output (pretty much) the same as
the man page
PR: 5269


# c5c1c135 02-Oct-1997 Daniel O'Callaghan <danny@FreeBSD.org>

Back out suppress '\n' mod.


# 34de7199 30-Sep-1997 Daniel O'Callaghan <danny@FreeBSD.org>

Add the '-s' flag to the usage string.


# 70a53cd7 30-Sep-1997 Daniel O'Callaghan <danny@FreeBSD.org>

Add the ability to supress the '\n' at the end of the date printed.


# adb7f7bc 30-Sep-1997 Joerg Wunsch <joerg@FreeBSD.org>

Fix the broken `date HHMM.SS' handling.

PR: bin/4661
Submitted by: blank@sliphost37.uni-trier.de (Sascha Blank)


# 233d16da 10-Aug-1997 Brian Somers <brian@FreeBSD.org>

Remove forgotten debug statement.


# 86a3e2a1 10-Aug-1997 Brian Somers <brian@FreeBSD.org>

Add "-f fmt date" for specification of the
date using strptime(3).
Suggested by: Michael Smith <msmith@atrad.adelaide.edu.au>

Change mm & dd to MM & DD so that they don't
clash with the month.


# 698f86e4 09-Aug-1997 Brian Somers <brian@FreeBSD.org>

Change [-DMHW [+|-]val] to [-v [+|-]val[ymwdHM]]
Support Hours & Minutes
Add -Wall to Makefile


# 7ca215a6 03-Aug-1997 Brian Somers <brian@FreeBSD.org>

Add [-DWMY] flags for date adjustment.
Discussed with: freebsd-hackers


# c4694019 01-Jul-1997 Bruce Evans <bde@FreeBSD.org>

Import Lite2's src/bin. All files in src/bin are off the vendor branch,
so this doesn't change the active versions.


# 749d4bb6 06-Jun-1997 Philippe Charnier <charnier@FreeBSD.org>

Cosmetic change in usage string.


# ec50d24e 15-Apr-1997 Daniel O'Callaghan <danny@FreeBSD.org>

Fix typo in comment; Document in an example that years beyond 1999
are handled; fix typo in same example.


# 93ef08af 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# b97fa2ef 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 42dbcdca 13-Dec-1996 Steve Price <steve@FreeBSD.org>

Merge Lite2 mods, fix incorrect default string, cleanup
use of .Nm macros, and -Wall cleaning.


# 008ff22c 05-Apr-1996 Andrey A. Chernov <ache@FreeBSD.org>

For nonexisten time use proper diagnostic instead of bad format and usage


# 4d279a06 23-Oct-1995 Andrey A. Chernov <ache@FreeBSD.org>

Add setlocale(LC_TIME,...


# 76f9ae3b 05-Aug-1995 Andrey A. Chernov <ache@FreeBSD.org>

Use %+ to print data using LC_TIME


# 29c52ddd 03-Apr-1995 Joerg Wunsch <joerg@FreeBSD.org>

date(1) didn't emit a final newline if the format had been specified
with `+'. This breaks tradition and violates Posix 1003.2.

Discoverd by: luigi@labinfo.iet.unipi.it (Luigi Rizzo)


# abdf1119 25-Dec-1994 Bruce Evans <bde@FreeBSD.org>

Obtained from: partly from 386BSD-0.1.2.4

Fix several bugs involving the obsolescent -d and -t options:
-d 0 and -t 0 were ignored
-t -600 was a usage error
-d 'atoi is not suitable for parsing args' and -t duh were not usage errors

Change some error messages to say which call to settimeofday failed.

Restore casts of NULL in function calls.

Finish conversion to using err() instead of perror().


# 89730b29 23-Sep-1994 David Greenman <dg@FreeBSD.org>

Added $Id$


# 4b88c807 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite bin Sources