I’m looking to output duration in iso8601 format in ruby on rails for schema.org. I already know how to output the timestamp in iso8601. e.g. video.created_at.iso8601
What I’m looking to do now is output something in the format of:
<meta itemprop="duration" content="PT1M33S" />
That’s the iso8601 duration format. You can read about the spec at http://en.wikipedia.org/wiki/ISO_8601#Durations
Currently I’m hacking in a strftime, but that’s not ideal…
Time.at(@video.duration).strftime('PT%MM:%SS')
Would appreciate a classier solution. And one smart enough to handle hours, etc when needed. I have no problem relying on ActiveSupport, etc as it’ll be in a Rails 3.2 app. Thanks!
If you’re still looking for an answer to this, check out the ruby-duration gem.