Sha256: 1c1d433cd3ba383ad16db527266aa35782034cbedba2622963ad5d0b181bb705
Contents?: true
Size: 1.22 KB
Versions: 24
Compression:
Stored size: 1.22 KB
Contents
class Time # Returns a new Time where one or more of the elements # have been changed according to the +options+ parameter. # The time options (hour, minute, sec, usec) reset # cascadingly, so if only the hour is passed, then # minute, sec, and usec is set to 0. If the hour and # minute is passed, then sec and usec is set to 0. def change(options) opts={}; options.each_pair{ |k,v| opts[k] = v.to_i } self.class.send( self.utc? ? :utc : :local, opts[:year] || self.year, opts[:month] || self.month, opts[:day] || self.day, opts[:hour] || self.hour, opts[:min] || (opts[:hour] ? 0 : self.min), opts[:sec] || ((opts[:hour] || opts[:min]) ? 0 : self.sec), opts[:usec] || ((opts[:hour] || opts[:min] || opts[:usec]) ? 0 : self.usec) ) end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' require 'time' class TCTime < Test::Unit::TestCase def setup @t = Time.parse('4/20/2006 15:37') end def test_change n = Time.now n = n.change( :month=>4, :day=>20, :hour=>15, :min=>37, :year=>2006 ) assert_equal( @t, n ) end end =end
Version data entries
24 entries across 24 versions & 1 rubygems