lib/timing/zone_offset.rb in timing-0.0.3 vs lib/timing/zone_offset.rb in timing-0.0.4
- old
+ new
@@ -1,21 +1,21 @@
module Timing
- class ZoneOffset < SimpleDelegator
+ class ZoneOffset < TransparentProxy
REGEXP = /^([+-]?)(\d\d):?(\d\d)$/
def initialize(seconds)
raise ArgumentError, "#{seconds} is not a number" unless seconds.is_a? Numeric
super
end
def to_s
- hours = Interval.new(to_f).to_hours.to_i
- minutes = Interval.new(to_f % Interval.hours(1)).to_minutes.to_i
- sign = self < 0 ? '-' : '+'
+ "#{sign}#{hour.to_s.rjust(2, '0')}#{minute.to_s.rjust(2, '0')}"
+ end
- "#{sign}#{hours.to_s.rjust(2, '0')}#{minutes.to_s.rjust(2, '0')}"
+ def iso8601
+ "#{sign}#{hour.to_s.rjust(2, '0')}:#{minute.to_s.rjust(2, '0')}"
end
def inspect
"#{to_s} (#{to_f})"
end
@@ -28,9 +28,23 @@
sign = match.captures[0] == '-' ? -1 : 1
hours = match.captures[1].to_i
minutes = match.captures[2].to_i
new (Interval.hours(hours) + Interval.minutes(minutes)) * sign
+ end
+
+ private
+
+ def hour
+ Interval.new(to_f).to_hours.to_i
+ end
+
+ def minute
+ Interval.new(to_f % Interval.hours(1)).to_minutes.to_i
+ end
+
+ def sign
+ self < 0 ? '-' : '+'
end
end
end
\ No newline at end of file