Skip to content

Comment on Signed and Permanent Cookies in Rails 3parent

Comments

    irb(main):033:0> 20.years
    => 20 years               # ??????
    irb(main):030:0> 20.years.to_i
    => 631152000              # number of seconds in 20 years
    irb(main):026:0> 20.years.from_now
    => Sun Feb 10 10:14:11 +1100 2030 # AEDT
    irb(main):027:0> 20.years.from_now.utc
    => Sat Feb 09 23:14:14 UTC 2030   # UTC/GMT
Ruby Time instances have a timezone, calling Time#utc returns the instance time converted from localtime -- or whatever timezone it is -- to UTC or Greenwich Mean Time. You are correct in that it shouldn't matter which one you use in this situation though.

Your first one, commented with ??????, is an instance of a Duration object. It implements the #ago and #from_now methods, so that Integer objects aren't cluttered with methods that mean nothing to it.

http://api.rubyonrails.org/classes/ActiveSupport/Duration.ht...

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.