lib/timing/time_in_zone.rb in timing-0.0.2 vs lib/timing/time_in_zone.rb in timing-0.0.3
- old
+ new
@@ -3,12 +3,12 @@
extend Forwardable
REGEXP = /[+-]\d\d:?\d\d/
- def_delegators :time, :to_i, :to_f, :<, :<=, :==, :>, :>=, :between?, :eql?, :hash
- def_delegators :time_with_offset, :year, :month, :day, :hour, :min, :sec
+ def_delegators :time, :to_i, :to_f, :to_date, :to_datetime, :<, :<=, :==, :>, :>=, :between?, :eql?, :hash
+ def_delegators :time_with_offset, :year, :month, :day, :hour, :min, :sec, :wday, :yday
attr_reader :zone_offset
def initialize(time, zone_offset=nil)
@time = time
@@ -54,9 +54,37 @@
end
alias_method :inspect, :to_s
def strftime(format)
time_with_offset.strftime format.gsub('%Z', '').gsub('%z', zone_offset.to_s)
+ end
+
+ %w(hour day week month year).each do |interval|
+ beginning_method_name = "beginning_of_#{interval}"
+ define_method beginning_method_name do
+ Timing.send beginning_method_name, self
+ end
+
+ end_method_name = "end_of_#{interval}"
+ define_method end_method_name do
+ Timing.send end_method_name, self
+ end
+ end
+
+ def months_ago(count)
+ Timing.months_ago self, count
+ end
+
+ def months_after(count)
+ Timing.months_after self, count
+ end
+
+ def years_ago(count)
+ Timing.years_ago self, count
+ end
+
+ def years_after(count)
+ Timing.years_after self, count
end
def self.now(zone_offset=nil)
new Time.now, zone_offset
end
\ No newline at end of file