datetime - Is there a comprehensive library/module for ISO 8601 in ruby? -


is there implementation of date, time, duration , interval usage of iso 8601 standard in ruby? mean class can set , details like, year, month, day, day_of_the_week, week, hour, minutes, is_duration?, has_recurrence? , on can set , exported string?

require 'time'  time = time.iso8601 time.now.iso8601 # iso8601 <--> string time.year    # => year of date  time.month   # => month of date (1 12) time.day     # => day of date (1 31 ) time.wday    # => 0: day of week: 0 sunday time.yday    # => 365: day of year time.hour    # => 23: 24-hour clock time.min     # => 59 time.sec     # => 59 time.usec    # => 999999: microseconds time.zone    # => "utc": timezone name 

have @ time. has lot of stuff in it.

unfortunately ruby's built-in date-time functions not seem thought through (comparing .net example), other functionality need use gems.

good thing using gems feel it's built-into ruby implementation.

most useful time calculations activesupport (rails 3).
don't need require rails small library: gem install activesupport.

then you can do:

require 'active_support/all' time.now.advance(:hours => 1) - time.now # ~ 3600 1.hour.from_now - time.now # ~ 3600 - same above time.now.at_beginning_of_day # ~ 2010-11-24 00:00:00 +1100 # at_beginning_of_xxx: xx in [day, month, quarter, year, week] # same applies at_end_of_xxx 

there lot of things can , believe find suites needs well.

so instead of giving abstract examples here encourage experiment irb requiring active_support it.

keep time calculations @ hand.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -