Duration.parse
As far as I can tell, the de facto standard Ruby duration class can't parse ISO 8601 durations (e.g., PT1H for one hour). This makes the iCal parser rather worthless, if your source happens to actually use the Event.duration member.I wrote an ISO 8601 parse method for Duration. The code is quite awful (I haven't really written any Ruby since 2002, and I'm very out of practice!) but it works:
irb(main):001:0> load "iso8601-duration.rb"I'm putting this code in the public domain. If any of the Duration maintainers want to integrate it, they can go right ahead (though an email to let me know about it wouldn't go amiss!).
=> true
irb(main):002:0> Duration.parse("P1H20M")
=> #<BigDuration: 1 hour and 20 minutes>
Posted at 2007-04-22 21:08:53 by Richard • Link to Duration.parse
Comments, trackbacks.
