Bug 248918 - date(1) -j -f uses current time for unspecified components
Summary: date(1) -j -f uses current time for unspecified components
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Ed Maste
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-26 00:21 UTC by Ed Maste
Modified: 2020-09-05 02:05 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2020-08-26 00:21:42 UTC
Date's -j and -f flags can be used together to specify a date, in an arbitrary format, to convert it to a different format. The man page gives

% date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"

as an example to convert a string in date's usual output format to an epoch timestamp.

If the -j and -f flags are used without specifying all components of struct tm the unspecified components keep their current values:

% date -j -f %Y-%m-%d 2021-09-30 +%s; sleep 5; date -j -f %Y-%m-%d 2021-09-30 +%s
1633047180
1633047185

This is behaviour is surprising; it's useful for -f alone (the user might want to change the time but leave the date alone, for example), but seems like -j should start with all components zeroed.
Comment 1 commit-hook freebsd_committer freebsd_triage 2020-08-26 00:32:35 UTC
A commit references this bug:

Author: emaste
Date: Wed Aug 26 00:31:59 UTC 2020
New revision: 364790
URL: https://svnweb.freebsd.org/changeset/base/364790

Log:
  date.1: note possibly surprising behaviour of -j -f

  PR:		248918
  MFC after:	1 week
  Sponsored by:	The FreeBSD Foundation

Changes:
  head/bin/date/date.1
Comment 2 commit-hook freebsd_committer freebsd_triage 2020-09-02 17:47:37 UTC
A commit references this bug:

Author: emaste
Date: Wed Sep  2 17:46:56 UTC 2020
New revision: 365263
URL: https://svnweb.freebsd.org/changeset/base/365263

Log:
  MFC r364790: date.1: note possibly surprising behaviour of -j -f

  PR:		248918

Changes:
_U  stable/12/
  stable/12/bin/date/date.1
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2020-09-05 01:26:25 UTC
^Triage: assign to committer that resolved.
Comment 4 Ed Maste freebsd_committer freebsd_triage 2020-09-05 02:05:22 UTC
Reopen: the oddity is now noted in the man page, but we should fix the surprising behaviour