Re: Is there a POSIX compliant way of turning a "HH:MM:SS" formatted string to seconds? ...
On Fri, Jul 18, 2025 at 00:31:17 +0100, Alain D D Williams wrote:
> On Fri, Jul 18, 2025 at 01:21:08AM +0200, lbrtchx@tutamail.com wrote:
> > OK, the Math is right, but the assumptions made by date aren't smart. I "overtested" your one liner with the kinds of input you would grab using jq from youtube .info.json files
>
> > and to my amazement, when you only have two semicolon separated values, the bash date utility assumes the first chunk to be the hours and the second the minutes!:
Colon, not semicolon, yes?
> I am not at all surprised. It could have been either HH:MM or MM:SS. I think
> that HH:MM is reasonable/correct - but I will not argue. But you now know how it
> interprets it so simply detect the NN:NN case and append :00
Yeah, I'm not surprised either. The design of GNU date's -d parsing is to
interpret strings that are written by or for humans. Also remember, these
are *times* and not durations. If a human writes "The party is at 7:30",
they almost certainly mean 19:30:00 rather than 7.5 minutes past midnight.
Reply to: