aboutsummaryrefslogtreecommitdiff
path: root/bin/date/date.c
Commit message (Collapse)AuthorAgeFilesLines
* date: Improve nanosecond supportDag-Erling Smørgrav2025-11-191-46/+102
| | | | | | | | | | | | | | | Add support for a field width, which defaults to 9 if unspecified or zero. If the width is not exactly 9, we have to either cut off digits or append zeroes to make up the difference. If the width is a dash, we pick a width based on the clock's reported resolution. This brings us in line with GNU coreutils. PR: 287080 MFC after: 1 week Reviewed by: 0mp Differential Revision: https://reviews.freebsd.org/D53667 (cherry picked from commit 38839c872e7af6a1424009bf07d6b4450e9ca61d)
* date: Fix a few nits.Dag-Erling Smørgrav2024-10-061-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | * Don't use `asprintf()` when `strdup()` can do the job just as well. * Fix a couple of typos in a comment. Fixes: eeb04a736cb9 MFC after: 3 days Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D46533 (cherry picked from commit a8ddd1926a34fc20970d9ceaad71b31fc414b1c5) date: Documentation nits. * Fix spurious capitalization. * Fix inconsistent quoting. * Use `Dq` rather than ASCII double quotes. MFC after: 3 days Sponsored by: Klara, Inc. Reviewed by: 0mp Differential Revision: https://reviews.freebsd.org/D46622 (cherry picked from commit 355ebf80b1ed98cf7ca9c51ce7e3e6dcb376853d)
* date: Correctly check outcome of mktime().Dag-Erling Smørgrav2024-05-021-1/+3
| | | | | | | | X-MFC-With: 7b390cb63689 Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D44982 (cherry picked from commit dafb424b8d44c7fdc9cfe876a79aad05c438def0)
* date: Fix tests by initializing timespec structureMateusz Piotrowski2024-05-021-0/+2
| | | | | | | | | | | | 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 (cherry picked from commit 7b390cb636899582243e4daa8edbdb30d686d9fb)
* date: Add support for nanosecondsMateusz Piotrowski2024-05-021-27/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 (cherry picked from commit eeb04a736cb9c07d191af886e25d5f198824658e)
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Mark usage function as __dead2 in programs where it does not returnAlfonso Gregory2023-07-071-2/+2
| | | | | | | | 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
* date: add -z output_zone optionBaptiste Daroussin2023-05-191-3/+9
| | | | | | | | | | | | | 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
* date: Capitalize seconds string in synopsesMateusz Piotrowski2021-11-031-1/+1
| | | | | | | | 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
* date: Clean up synopsesMateusz Piotrowski2021-11-031-3/+3
| | | | MFC after: 3 days
* Restore the -n flag parsing, but ignore it.Warner Losh2019-04-241-1/+3
| | | | | | | | | | 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). Notes: svn path=/head/; revision=346624
* Remove -n flag, fix setting date / timeWarner Losh2019-03-211-23/+17
| | | | | | | | | | r342139 bork setting the date. This fixes it by simply removing the -n flag. Differential Revision: https://reviews.freebsd.org/D19668 Notes: svn path=/head/; revision=345365
* Remove now useless -d and -t flags.Warner Losh2019-03-121-28/+3
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=345050
* Remove, the now very outdated, timed.George V. Neville-Neil2018-12-151-4/+2
| | | | | | | | | | Submitted by: Kyle Spiers ksspiers at gmail Reviewed by: bcr,brooks,bz,sbruno Relnotes: yes Differential Revision: https://reviews.freebsd.org/D18505 Notes: svn path=/head/; revision=342139
* date(1): Add ISO 8601 formatting optionConrad Meyer2018-08-041-9/+95
| | | | | | | | The new flag is named '-I'. It is documented in the manual page and covered by basic unit tests. Notes: svn path=/head/; revision=337332
* Fill in ut_id. While it's not relevant to the {OLD,NEW}_TIME entries,Warner Losh2018-01-231-0/+1
| | | | | | | | | we shouldn't leak stack garbage into the field. Sponsored by: Netflix Notes: svn path=/head/; revision=328282
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=326025
* date: avoid crash on invalid timeEd Maste2017-07-201-4/+8
| | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=321293
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | 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 Notes: svn path=/head/; revision=314436
* date(1): Make -r behave like GNU's version when the option can not beXin LI2015-05-071-2/+8
| | | | | | | | | | | | 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 Notes: svn path=/head/; revision=282608
* date(1): Add "-R" flag to use RFC 2822 date and time output formatJean-Sébastien Pédron2014-04-261-4/+20
| | | | | | | | | | 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. Notes: svn path=/head/; revision=264968
* Rework all non-contributed files that use `struct timezone'.Ed Schouten2012-09-011-4/+4
| | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=239991
* Port everything in bin/ from utmp to utmpx.Ed Schouten2010-01-131-2/+1
| | | | | | | | date: use libc utmpx routines instead of the ones provided by libulog. pax: don't depend on <utmp.h> Notes: svn path=/head/; revision=202193
* Let date(1) use utmpx instead of logwtmp().Ed Schouten2009-12-051-3/+9
| | | | | | | | utmpx also has OLD_TIME/NEW_TIME messages, which seem to be intended for the same purpose as how we call logwtmp() here. Notes: svn path=/head/; revision=200157
* Don't reset DST computed by strptime() (when e.g. setting theRuslan Ermilov2008-02-071-6/+3
| | | | | | | | | | date via -f %s). Reported by: Eugene Grosbein Diagnosed by: Miguel Lopes Santos Ramos Notes: svn path=/head/; revision=176094
* /*- or .\"- or #- to begin license clauses.Warner Losh2005-01-101-1/+1
| | | | Notes: svn path=/head/; revision=139969
* Remove clause 3 from the UCB licenses.Mark Murray2004-04-061-4/+0
| | | | | | | OK'ed by: imp, core Notes: svn path=/head/; revision=127958
* Rev. 1.32 moved a comment to the wrong line. The hack refered toMike Makonnen2004-03-041-2/+2
| | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=126605
* Check for write errors; report and exit with error value.Diomidis Spinellis2003-10-041-0/+2
| | | | Notes: svn path=/head/; revision=120729
* Enclose sccsid according to style(9).Philippe Charnier2003-02-051-2/+3
| | | | | | | udp/timed -> timed/udp Notes: svn path=/head/; revision=110390
* Staticify for lint.Mark Murray2002-10-181-2/+2
| | | | Notes: svn path=/head/; revision=105396
* Consistently use __FBSDIDDavid E. O'Brien2002-06-301-2/+2
| | | | Notes: svn path=/head/; revision=99109
* Fix warnings inspired by lint, a commercial lint and WARNS=4.Mark Murray2002-02-221-4/+4
| | | | Notes: svn path=/head/; revision=91079
* o __P has been reovedWarner Losh2002-02-021-14/+9
| | | | | | | | | | | | | | 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) Notes: svn path=/head/; revision=90108
* Remove assumption that time_t is an intMatthew Dillon2001-10-281-1/+3
| | | | | | | MFC after: 1 day Notes: svn path=/head/; revision=85615
* Add -j to the usage string.Dima Dorfman2001-06-091-1/+1
| | | | | | | | PR: 27986 Submitted by: Cyrille Lefevre <clefevre@redirect.to> Notes: svn path=/head/; revision=77934
* Fix an off-by-hour bug when crossing Daylight Saving Time boundary.Ruslan Ermilov2001-05-171-0/+3
| | | | | | | | | PR: bin/27399 Submitted by: "Crist J. Clark" <crist.clark@globalstar.com> MFC after: 3 days Notes: svn path=/head/; revision=76749
* Don't explicitly declare optarg and optind. These are declared inWarner Losh2000-08-161-2/+0
| | | | | | | unistd.h, which is already included. Notes: svn path=/head/; revision=64692
* Expand the -r option to support hex. Though undocumented, the -rJohn W. De Boskey2000-07-221-1/+2
| | | | | | | | | | | 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 Notes: svn path=/head/; revision=63761
* Correct confusion and differentiate appropriately between GMT and UTC whenDaniel Baker2000-05-191-3/+3
| | | | | | | | | | | | 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> Notes: svn path=/head/; revision=60718
* Back out previous commit and replace with a cleaner solution adaptedSheldon Hearn1999-12-291-11/+21
| | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=55225
* Allow the year to be specified with an optional century.Sheldon Hearn1999-11-101-2/+10
| | | | | | | | PR: 14472 Reported by: j_guojun@lbl.gov (Jin Guojun) Notes: svn path=/head/; revision=53082
* $Id$ -> $FreeBSD$Peter Wemm1999-08-271-1/+1
| | | | Notes: svn path=/head/; revision=50471
* Don't continue if parsing failed when -f is in use. Exit with nonzero value.Martin Cracauer1999-06-251-3/+2
| | | | Notes: svn path=/head/; revision=48214
* the month and three days are up for -hackers and the 24hrs for -committers.John-Mark Gurney1999-05-141-18/+26
| | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=47129
* Support seconds with -v.Brian Somers1999-03-091-2/+2
| | | | | | | | PR: 6308 Submitted by: Max Euston <meuston@jmrodgers.com> Notes: svn path=/head/; revision=44598
* Added missing #include <string.h>Alexander Langer1998-10-031-1/+2
| | | | Notes: svn path=/head/; revision=39925
* Restore Lite-2 sccsid. Restore include of sys/param.h.Philippe Charnier1998-05-131-2/+3
| | | | Notes: svn path=/head/; revision=36006
* Correct use of .Nm and other cosmetics. Add rcsid. Remove unused #inc.Philippe Charnier1998-05-061-5/+4
| | | | Notes: svn path=/head/; revision=35773
* Cast a size_t to a long to avoid a gcc warning.John Birrell1998-01-251-3/+3
| | | | Notes: svn path=/head/; revision=32756