[Bug 248918] date(1) -f uses current time for unspecified components

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Wed Aug 26 00:21:42 UTC 2020


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=248918

            Bug ID: 248918
           Summary: date(1) -f uses current time for unspecified
                    components
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs at FreeBSD.org
          Reporter: emaste at freebsd.org

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.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list