Convert enclosure Duration from unix to humane readable time

i want to convert enclosure duration that i have in length

<enclosure length="70588566" type="audio/mpeg" url="http://traffic.libsyn.com/thewebplatform/TWPP-193.mp3" /> 

to something like that , duration 48:41

i have duration in params like that :
duration: 70588566

i have tried this but it didn’t work:

 {{ $duration := .Params.duration }}
  
 {{ time.ParseDuration   $duration  }}

all go time functions:

https://golang.org/pkg/time/

thanks for your reply, i have looked into that and i can’t find a way to make it work :frowning:

See Hugo doc: https://gohugo.io/functions/format/ and https://gohugo.io/functions/unix/

:sweat_smile: i’ve seen that before posting here, the thing is that i have tried all what i have seen there and nothing seem to make it work , i’m new to Go so yeah!

Enclosure 'length' is measured in bytes, not time.

2 Likes

ParseDuration parses a duration string (e.g. “30s”), which is the opposite of what you want

Try:

{{ 70588566 | time.Duration "ms" }}
Unit is one of nanosecond/ns, microsecond/us/µs, millisecond/ms, second/s, minute/m or hour/h.

@regis Duration and ParseDuration does not come up when searching from them in the docs site … hint …

2 Likes