Re: Is there a POSIX compliant way of turning a "HH:MM:SS" formatted string to seconds? ...
On Sat 19 Jul 2025 at 22:37:38 (+0000), Tim Woodall wrote:
> On Thu, 17 Jul 2025, lbrtchx@tutamail.com wrote:
>
> > Video durations are formatted in youtube's .info.json files as "HH:MM:SS"; so, I went monkey and did the conversion myself, but I got two errors which I can't make sense of whatsoever with only two values:
[ … ]
> Not sure about posix but:
>
> date -u -d '1/1/70 12:08' '+%s'
> 43680
That illustrates the rule that makes this method fail: a time-of-day
(which is what 12:08 is in this context) must contain the hours.
For youtube, this period is 12m 8s, ie 728 seconds. OTOH date
understands the time as eight minutes past noon, leading to a
60-fold inflation. When the youtube period reaches 24 minutes,
date will report it invalid, but will work when beyond an hour.
AFAICT any method that confuses times with periods will be
fragile or fail.
Cheers,
David.
Reply to: