diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-07 16:35:33 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-07 16:35:33 +0000 |
commit | 75334db3c6479ea3cd7462d36ca5464d386f9c72 (patch) | |
tree | c97df2c7aa02f3d0e65524890924f1b294871073 /spec/ruby/core/time/fixtures | |
parent | 5c7c6763f6cf7b4face107735071c5470e835476 (diff) |
Update to ruby/spec@6cf8ebe
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/time/fixtures')
-rw-r--r-- | spec/ruby/core/time/fixtures/classes.rb | 69 |
1 files changed, 64 insertions, 5 deletions
diff --git a/spec/ruby/core/time/fixtures/classes.rb b/spec/ruby/core/time/fixtures/classes.rb index d89e4911c8..ece7ed2bca 100644 --- a/spec/ruby/core/time/fixtures/classes.rb +++ b/spec/ruby/core/time/fixtures/classes.rb @@ -9,18 +9,77 @@ module TimeSpecs end end - Timezone = Struct.new(:name, :abbr, :offset) class Timezone - def utc_offset(t = nil) - offset + def initialize(options) + @offset = options[:offset] end def local_to_utc(t) - t - utc_offset(t) + t - @offset end def utc_to_local(t) - t + utc_offset(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 |