Bug 198530

Summary: date(1) command: parsing of %T broken in 10.1-RELEASE
Product: Base System Reporter: Euan Thoms <euan>
Component: binAssignee: Fernando ApesteguĂ­a <fernape>
Status: Closed Unable to Reproduce    
Severity: Affects Many People CC: fernape
Priority: ---    
Version: 10.1-RELEASE   
Hardware: Any   
OS: Any   

Description Euan Thoms 2015-03-11 20:47:57 UTC
The parsing of a date by date(1) using the -f flag and %T is now broken in 10.1-RELEASE.

I noticed it when my script that previous worked no longer does.

For example, in FreeBSD 10.0-RELEASE-p7:

$ date -j -f "%a %b %d %T %Y" "Thu Mar 12 3:08 2015" +%s
1426100897

But in FreeBSD 10.1-RELEASE-p0:

$ date -j -f "%a %b %d %T %Y" "Thu Mar 12 3:08 2015" +%s
Failed conversion of ``Thu Mar 12 3:08 2015'' using format ``%a %b %d %T %Y''
date: illegal time format
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]

And from the man pages' example section, in FeeeBSD 10.1-RELEASE:

$ date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"
Failed conversion of ``Thu 12 Mar 2015 04:28:16 SGT'' using format ``%a %b %d %T %Z %Y''
date: illegal time format
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]



I may be able to workaround / fix my script by changing the %T to %H:%M, since it seems it's the lack of the minutes that's upsetting the parser.

For example, in FreeBSD 10.1-RELEASE:

$ date -j -f "%a %b %d %H:%M %Y" "Thu Mar 12 3:08 2015" +%s
1426100907


The date string I'm using is from "zfs -H -o creation pool/filesytem". And the reason the man page example doesn't work is probably the timezone. In my case SGT. e.g:

$ date
Thu 12 Mar 2015 04:34:39 SGT

Perhaps the change is intentional, to make the parser more strict. But it's not nice when a script gets broken. And the man page needs updating in any case.
Comment 1 Fernando ApesteguĂ­a freebsd_committer freebsd_triage 2023-01-24 16:21:23 UTC
In 14-CURRENT

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