GNU bug report logs - #72023
feature request for date(1): strptime-style format string when you don't want date to guess

Previous Next

Package: coreutils;

Reported by: <mark.yagnatinsky <at> barclays.com>

Date: Wed, 10 Jul 2024 02:20:01 UTC

Severity: wishlist

To reply to this bug, email your comments to 72023 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#72023; Package coreutils. (Wed, 10 Jul 2024 02:20:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to <mark.yagnatinsky <at> barclays.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Wed, 10 Jul 2024 02:20:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: <mark.yagnatinsky <at> barclays.com>
To: <bug-coreutils <at> gnu.org>
Subject: feature request for date(1): strptime-style format string when you
 don't want date to guess
Date: Tue, 9 Jul 2024 20:29:44 +0000
[Message part 1 (text/plain, inline)]
I suspect this has been requested many times over the decades but I haven't found anything in the issue tracker so...
The date command lets you choose my output format, but for input it tries to figure it out without hints.  For interactive use, this is great.
For usage in scripts, this is less than ideal, because that means you need to understand the heuristics to have confidence that your script will do what you want.
For instance, this page:
https://www.gnu.org/software/coreutils/manual/html_node/Pure-numbers-in-date-strings.html
says that "If the decimal number is of the form yyyymmdd [...] yyyy is read as the year"
I stared at that sentence for a bit in confusion, thinking to myself "but how could it possibly KNOW that the number is of the form yyyymmdd??"
I finally realized that what it's really saying is that "if the number is exactly 8 digits long, we ASSUME that the first four digits are the year".
Thus, if you have an 8-digit number that you want to interpret differently then you should massage it before passing it to date.

As it happens, I have an 8 digit number, and indeed the built-in assumptions happen to be a perfect fit for me.
But I still don't like to rely on them if I don't have to, and would rather just tell it what I already know, instead of forcing date(1) to re-derive it.

Thoughts?
Mark.

This message is for information purposes only. It is not a recommendation, advice, offer or solicitation to buy or sell a product or service, nor an official confirmation of any transaction. It is directed at persons who are professionals and is intended for the recipient(s) only. It is not directed at retail customers. This message is subject to the terms at: https://www.ib.barclays/disclosures/web-and-email-disclaimer.html. 

For important disclosures, please see: https://www.ib.barclays/disclosures/sales-and-trading-disclaimer.html regarding marketing commentary from Barclays Sales and/or Trading desks, who are active market participants; https://www.ib.barclays/disclosures/barclays-global-markets-disclosures.html regarding our standard terms for Barclays Investment Bank where we trade with you in principal-to-principal wholesale markets transactions; and in respect to Barclays Research, including disclosures relating to specific issuers, see: https://publicresearch.barclays.com.
__________________________________________________________________________________ 
If you are incorporated or operating in Australia, read these important disclosures: https://www.ib.barclays/disclosures/important-disclosures-asia-pacific.html.
__________________________________________________________________________________
For more details about how we use personal information, see our privacy notice: https://www.ib.barclays/disclosures/personal-information-use.html. 
__________________________________________________________________________________
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#72023; Package coreutils. (Wed, 10 Jul 2024 10:46:01 GMT) Full text and rfc822 format available.

Message #8 received at 72023 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: mark.yagnatinsky <at> barclays.com, 72023 <at> debbugs.gnu.org
Subject: Re: bug#72023: feature request for date(1): strptime-style format
 string when you don't want date to guess
Date: Wed, 10 Jul 2024 12:44:52 +0200
I'm dubious. I've never had much luck with strptime, as in practice it 
has its own glitches that are even worse than what 'date' currently 
uses. For example, it's dicey in non-C locales, and it mishandles time 
zones and daylight saving transitions even in the C locale.

That being said, if someone can write the code and documentation and 
test cases it might be a good thing to have - particularly if some other 
'date' implementation is already doing that sort of thing and people 
have had good experience with it.




Information forwarded to bug-coreutils <at> gnu.org:
bug#72023; Package coreutils. (Wed, 10 Jul 2024 12:00:03 GMT) Full text and rfc822 format available.

Message #11 received at 72023 <at> debbugs.gnu.org (full text, mbox):

From: <mark.yagnatinsky <at> barclays.com>
To: <eggert <at> cs.ucla.edu>, <72023 <at> debbugs.gnu.org>
Subject: RE: bug#72023: feature request for date(1): strptime-style format
 string when you don't want date to guess
Date: Wed, 10 Jul 2024 11:59:14 +0000
Re: other dates: BSD date has this flag, and needs it, because it mostly refuses to guess.
Re: strptime... I didn't mean it has to literally be that function.
I just want some way to say what format the input is in.

-----Original Message-----
From: Paul Eggert <eggert <at> cs.ucla.edu> 
Sent: Wednesday, July 10, 2024 6:45 AM
To: Yagnatinsky, Mark : IT (NYK) <mark.yagnatinsky <at> barclays.com>; 72023 <at> debbugs.gnu.org
Subject: Re: bug#72023: feature request for date(1): strptime-style format string when you don't want date to guess


CAUTION: This email originated from outside our organisation - eggert <at> cs.ucla.edu Do not click on links, open attachments, or respond unless you recognize the sender and can validate the content is safe.
I'm dubious. I've never had much luck with strptime, as in practice it has its own glitches that are even worse than what 'date' currently uses. For example, it's dicey in non-C locales, and it mishandles time zones and daylight saving transitions even in the C locale.

That being said, if someone can write the code and documentation and test cases it might be a good thing to have - particularly if some other 'date' implementation is already doing that sort of thing and people have had good experience with it.

This message is for information purposes only. It is not a recommendation, advice, offer or solicitation to buy or sell a product or service, nor an official confirmation of any transaction. It is directed at persons who are professionals and is intended for the recipient(s) only. It is not directed at retail customers. This message is subject to the terms at: https://www.ib.barclays/disclosures/web-and-email-disclaimer.html. 

For important disclosures, please see: https://www.ib.barclays/disclosures/sales-and-trading-disclaimer.html regarding marketing commentary from Barclays Sales and/or Trading desks, who are active market participants; https://www.ib.barclays/disclosures/barclays-global-markets-disclosures.html regarding our standard terms for Barclays Investment Bank where we trade with you in principal-to-principal wholesale markets transactions; and in respect to Barclays Research, including disclosures relating to specific issuers, see: https://publicresearch.barclays.com.
__________________________________________________________________________________ 
If you are incorporated or operating in Australia, read these important disclosures: https://www.ib.barclays/disclosures/important-disclosures-asia-pacific.html.
__________________________________________________________________________________
For more details about how we use personal information, see our privacy notice: https://www.ib.barclays/disclosures/personal-information-use.html. 
__________________________________________________________________________________

Information forwarded to bug-coreutils <at> gnu.org:
bug#72023; Package coreutils. (Wed, 10 Jul 2024 12:57:02 GMT) Full text and rfc822 format available.

Message #14 received at 72023 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: mark.yagnatinsky <at> barclays.com, 72023 <at> debbugs.gnu.org
Subject: Re: bug#72023: feature request for date(1): strptime-style format
 string when you don't want date to guess
Date: Wed, 10 Jul 2024 14:56:36 +0200
On 7/10/24 13:59, mark.yagnatinsky--- via GNU coreutils Bug Reports wrote:
> BSD date has this flag

Unfortunately it uses -f for the flag, and -f already has a 
well-established different meaning in GNU 'date'. We could add it to GNU 
date under a different (long) option name, though we'd still be 
incompatible with BSD 'date'.

Again, if someone wants to write the code and (just as important) 
documentation, and also the tests, go for it. I tend to think strptime 
is a mistake, so I'm not likely to volunteer.




Information forwarded to bug-coreutils <at> gnu.org:
bug#72023; Package coreutils. (Wed, 10 Jul 2024 13:13:01 GMT) Full text and rfc822 format available.

Message #17 received at 72023 <at> debbugs.gnu.org (full text, mbox):

From: <mark.yagnatinsky <at> barclays.com>
To: <eggert <at> cs.ucla.edu>, <72023 <at> debbugs.gnu.org>
Subject: RE: bug#72023: feature request for date(1): strptime-style format
 string when you don't want date to guess
Date: Wed, 10 Jul 2024 13:12:00 +0000
Re: strptime is mistake: you think that particular function is bad, or the whole idea of
"here is a string describing the format, please parse accordingly" is a bad idea?

-----Original Message-----
From: Paul Eggert <eggert <at> cs.ucla.edu> 
Sent: Wednesday, July 10, 2024 8:57 AM
To: Yagnatinsky, Mark : IT (NYK) <mark.yagnatinsky <at> barclays.com>; 72023 <at> debbugs.gnu.org
Subject: Re: bug#72023: feature request for date(1): strptime-style format string when you don't want date to guess


CAUTION: This email originated from outside our organisation - eggert <at> cs.ucla.edu Do not click on links, open attachments, or respond unless you recognize the sender and can validate the content is safe.
On 7/10/24 13:59, mark.yagnatinsky--- via GNU coreutils Bug Reports wrote:
> BSD date has this flag

Unfortunately it uses -f for the flag, and -f already has a well-established different meaning in GNU 'date'. We could add it to GNU date under a different (long) option name, though we'd still be incompatible with BSD 'date'.

Again, if someone wants to write the code and (just as important) documentation, and also the tests, go for it. I tend to think strptime is a mistake, so I'm not likely to volunteer.

This message is for information purposes only. It is not a recommendation, advice, offer or solicitation to buy or sell a product or service, nor an official confirmation of any transaction. It is directed at persons who are professionals and is intended for the recipient(s) only. It is not directed at retail customers. This message is subject to the terms at: https://www.ib.barclays/disclosures/web-and-email-disclaimer.html. 

For important disclosures, please see: https://www.ib.barclays/disclosures/sales-and-trading-disclaimer.html regarding marketing commentary from Barclays Sales and/or Trading desks, who are active market participants; https://www.ib.barclays/disclosures/barclays-global-markets-disclosures.html regarding our standard terms for Barclays Investment Bank where we trade with you in principal-to-principal wholesale markets transactions; and in respect to Barclays Research, including disclosures relating to specific issuers, see: https://publicresearch.barclays.com.
__________________________________________________________________________________ 
If you are incorporated or operating in Australia, read these important disclosures: https://www.ib.barclays/disclosures/important-disclosures-asia-pacific.html.
__________________________________________________________________________________
For more details about how we use personal information, see our privacy notice: https://www.ib.barclays/disclosures/personal-information-use.html. 
__________________________________________________________________________________

Information forwarded to bug-coreutils <at> gnu.org:
bug#72023; Package coreutils. (Wed, 10 Jul 2024 16:24:02 GMT) Full text and rfc822 format available.

Message #20 received at 72023 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: mark.yagnatinsky <at> barclays.com, 72023 <at> debbugs.gnu.org
Subject: Re: bug#72023: feature request for date(1): strptime-style format
 string when you don't want date to guess
Date: Wed, 10 Jul 2024 18:23:00 +0200
On 7/10/24 15:12, mark.yagnatinsky <at> barclays.com wrote:
> Re: strptime is mistake: you think that particular function is bad

Yes, though I lack the time to go into details right now.




Information forwarded to bug-coreutils <at> gnu.org:
bug#72023; Package coreutils. (Wed, 10 Jul 2024 16:26:02 GMT) Full text and rfc822 format available.

Message #23 received at 72023 <at> debbugs.gnu.org (full text, mbox):

From: <mark.yagnatinsky <at> barclays.com>
To: <eggert <at> cs.ucla.edu>, <72023 <at> debbugs.gnu.org>
Subject: RE: bug#72023: feature request for date(1): strptime-style format
 string when you don't want date to guess
Date: Wed, 10 Jul 2024 16:25:14 +0000
Fair enough... I was worried you were objecting to the whole concept, not just that one function

-----Original Message-----
From: Paul Eggert <eggert <at> cs.ucla.edu> 
Sent: Wednesday, July 10, 2024 12:23 PM
To: Yagnatinsky, Mark : IT (NYK) <mark.yagnatinsky <at> barclays.com>; 72023 <at> debbugs.gnu.org
Subject: Re: bug#72023: feature request for date(1): strptime-style format string when you don't want date to guess


CAUTION: This email originated from outside our organisation - eggert <at> cs.ucla.edu Do not click on links, open attachments, or respond unless you recognize the sender and can validate the content is safe.
On 7/10/24 15:12, mark.yagnatinsky <at> barclays.com wrote:
> Re: strptime is mistake: you think that particular function is bad

Yes, though I lack the time to go into details right now.

This message is for information purposes only. It is not a recommendation, advice, offer or solicitation to buy or sell a product or service, nor an official confirmation of any transaction. It is directed at persons who are professionals and is intended for the recipient(s) only. It is not directed at retail customers. This message is subject to the terms at: https://www.ib.barclays/disclosures/web-and-email-disclaimer.html. 

For important disclosures, please see: https://www.ib.barclays/disclosures/sales-and-trading-disclaimer.html regarding marketing commentary from Barclays Sales and/or Trading desks, who are active market participants; https://www.ib.barclays/disclosures/barclays-global-markets-disclosures.html regarding our standard terms for Barclays Investment Bank where we trade with you in principal-to-principal wholesale markets transactions; and in respect to Barclays Research, including disclosures relating to specific issuers, see: https://publicresearch.barclays.com.
__________________________________________________________________________________ 
If you are incorporated or operating in Australia, read these important disclosures: https://www.ib.barclays/disclosures/important-disclosures-asia-pacific.html.
__________________________________________________________________________________
For more details about how we use personal information, see our privacy notice: https://www.ib.barclays/disclosures/personal-information-use.html. 
__________________________________________________________________________________

Information forwarded to bug-coreutils <at> gnu.org:
bug#72023; Package coreutils. (Tue, 10 Sep 2024 05:59:01 GMT) Full text and rfc822 format available.

Message #26 received at 72023 <at> debbugs.gnu.org (full text, mbox):

From: Stephane Chazelas <stephane <at> chazelas.org>
To: 72023 <at> debbugs.gnu.org
Subject: Re: bug#72023: feature request for date(1): strptime-style format
Date: Tue, 10 Sep 2024 06:57:45 +0100
I agree strptime()-style input format specification is badly
missing in GNU date. Most other implementations support it:

- BSD with -f since 1997 (on FreeBSD at least; see also -v for adjustments)
- ast-open's with -p since 2004 (also via standard getdate() DATEMSK)
- busybox' with -D since 2006
- toybox' with -D since 2014

It's a regular occurrence on usenet or unix.stackexchange.com to
see it mentioned that if you need to parse arbitrary date
formats, you need to switch to another date implementation or
use shell builtin facilities such as zsh's strftime builtin or
ksh93's printf %T or resort to perl/ruby/python...

Assaf Gordon did propose a patch in
https://lists.gnu.org/archive/html/coreutils/2019-07/msg00053.html

Both -p and -D are unassigned ATM AFAICT so could be used here.
busybox and toybox mostly copied the GNU API, so it would make
sense for GNU date to use -D for that so they don't become
misaligned.

While strptime() is not perfect, it's still better IMO
than having to rely on the current -d behaviour which mostly
accepts only US-English time specs and whose rules to parse
times are not crystal clear.

-- 
Stephane




This bug report was last modified 278 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.