Flowdock
method

change

Importance_2
v6.1.3.1 - Show latest stable - 0 notes - Class: ActiveSupport::TimeWithZone
change(options) public

Returns a new +ActiveSupport::TimeWithZone+ where one or more of the elements have been changed according to the options parameter. The time options (:hour, :min, :sec, :usec, :nsec) reset cascadingly, so if only the hour is passed, then minute, sec, usec and nsec is set to 0. If the hour and minute is passed, then sec, usec and nsec is set to 0. The options parameter takes a hash with any of these keys: :year, :month, :day, :hour, :min, :sec, :usec, :nsec, :offset, :zone. Pass either :usec or :nsec, not both. Similarly, pass either :zone or :offset, not both.

t = Time.zone.now          # => Fri, 14 Apr 2017 11:45:15.116992711 EST -05:00
t.change(year: 2020)       # => Tue, 14 Apr 2020 11:45:15.116992711 EST -05:00
t.change(hour: 12)         # => Fri, 14 Apr 2017 12:00:00.116992711 EST -05:00
t.change(min: 30)          # => Fri, 14 Apr 2017 11:30:00.116992711 EST -05:00
t.change(offset: "-10:00") # => Fri, 14 Apr 2017 11:45:15.116992711 HST -10:00
t.change(zone: "Hawaii")   # => Fri, 14 Apr 2017 11:45:15.116992711 HST -10:00
Show source
Register or log in to add new notes.