How can I shorten this (working) code to create future dates in ruby for use as params in URLs?I'm doing:require 'cgi'require 'time'now=Time.new()now_year=now.strftime('%Y').to_inow_month=now.strftime('%m').to_inow_day=now.strftime('%d').to_inow_hour=now.strftime('%H').to_istart_hour=(now_hour + 1)end_hour=(now_hour + 2)start_datetime=Time.new(now_year, now_month, now_day, start_hour)end_datetime=Time.new(now_year, now_month, now_day, end_hour)starts=CGI.escape(start_datetime.utc.strftime(%Y-%m-%dT%H:%M:%S.%3NZ))ends=CGI.escape(end_datetime.utc.strftime(%Y-%m-%dT%H:%M:%S.%3NZ))and it works, but it seems long and clumsy.  Is there an easier way?
Adding time offsets to create future dates
ruby;datetime;url
You can add seconds directly to a Time object, so you could do:now = Time.now.utcstarts = now + 3600 # Add 1 hour's worth of seconds (60 * 60)ends   = now + 7200 # Add 2 hoursand then do the strftime-formatting.Of course, since you need to do this twice, I'd suggest adding a method to avoid the repetition, i.e.:def offset_utc_timestamp(offset, format = %Y-%m-%dT%H:%M:%S.%3NZ)  time = Time.now.utc + offset  time.strftime(format)endYou may want to split it up differently (i.e. have the method just return a Time object, which you make into a string elsewhere; or have the method also do the URL escaping).I'd also recommend using the URI.escape method instead, if this is intended for URLsWith all that your code becomes:starts = URI.escape(offset_utc_timestamp(3600))ends   = URI.escape(offset_utc_timestamp(7200))Alternatively, the ActiveSupport gem has a ton of helpful time stuff, letting you do things like 2.hours.from_now.utc