[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Is there a POSIX compliant way of turning a "HH:MM:SS" formatted string to seconds? ...



On Jul 17, 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:
> 
> _HHMMSS="19:09"
> _HHMMSS="19:08"
> IFS=$(echo -en "\n\b"); _SEKNDS_AR=($(echo "${_HHMMSS}" | tr ':' '\n')); _SEKNDS_ARL=${#_SEKNDS_AR[@]}
> if [[ ${_SEKNDS_ARL} -eq 2 ]]; then
> _SEKNDS=$(( 60 * ${_SEKNDS_AR[0]} )); _SEKNDS=$(( _SEKNDS + ${_SEKNDS_AR[1]} ))
> echo "// __ \$_SEKNDS: |${_SEKNDS}|"
> fi
> 
> bash: _SEKNDS + 08: value too great for base (error token is "08")

It thinks you're using Octal.  I have this in my notes (egregiously
stolen from http://mywiki.wooledge.org ... but I don't have the exact
page, and it's throwing 502 at me ..)



August is the month when all your scripts break because you placed
$(date +%m) in a variable and tried to do arithmetic with it, without
removing the leading zeros. 08 is considered octal. Use $((10#$month))
to force decimal, or strip the zero.


Hope it helps :)


-- 
|_|O|_| 
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1  E067 6D65 70E5 4CE7 2860

Attachment: signature.asc
Description: PGP signature


Reply to: