1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/core/time/fixtures/classes.rb
eregon 75334db3c6 Update to ruby/spec@6cf8ebe
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-07 16:35:33 +00:00

85 lines
1.4 KiB
Ruby

module TimeSpecs
class SubTime < Time; end
class MethodHolder
class << self
define_method(:now, &Time.method(:now))
define_method(:new, &Time.method(:new))
end
end
class Timezone
def initialize(options)
@offset = options[:offset]
end
def local_to_utc(t)
t - @offset
end
def utc_to_local(t)
t + @offset
end
end
class TimezoneMethodCallRecorder < Timezone
def initialize(options, &blk)
super(options)
@blk = blk
end
def local_to_utc(t)
@blk.call(t)
super
end
def utc_to_local(t)
@blk.call(t)
super
end
end
class TimeLikeArgumentRecorder
def self.result
arguments = []
zone = TimeSpecs::TimezoneMethodCallRecorder.new(offset: 0) do |obj|
arguments << obj
end
# ensure timezone's methods are called at least once
Time.new(2000, 1, 1, 12, 0, 0, zone)
return arguments[0]
end
end
class TimezoneWithAbbr < Timezone
def initialize(options)
super
@abbr = options[:abbr]
end
def abbr(time)
@abbr
end
end
class TimezoneWithName < Timezone
def initialize(options)
super
@name = options[:name]
end
def name
@name
end
end
class TimeWithFindTimezone < Time
def self.find_timezone(name)
TimezoneWithName.new(name: name.to_s, offset: -10*60*60)
end
end
end