Re: Is there a POSIX compliant way of turning a "HH:MM:SS" formatted string to seconds? ...
E.g.:
printf 01:02:03 | (IFS=: read h m s; printf '%s\n' $(( $((h * 3600)) +
$((m * 60)) + $s )))
On Thu, Jul 17, 2025 at 2:39 PM <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")
> ~
> yet, it works for _HHMMSS={"3:54:14", "20:01", "20:00", "19:07", "19:06", "19:05", ... } and all other similar conversion?!
>
> lbrtchx
Reply to: