class TimeBoots::MonthBoot
Public Class Methods
new()
click to toggle source
Calls superclass method
TimeBoots::Boot::new
# File lib/time_boots/boot/month.rb, line 4 def initialize super(:month) end
Public Instance Methods
measure(from, to)
click to toggle source
# File lib/time_boots/boot/month.rb, line 8 def measure(from, to) ydiff = to.year - from.year mdiff = to.month - from.month to.day >= from.day ? (ydiff * 12 + mdiff) : (ydiff * 12 + mdiff - 1) end
Protected Instance Methods
_advance(tm, steps)
click to toggle source
# File lib/time_boots/boot/month.rb, line 31 def _advance(tm, steps) steps.times.inject(tm) { |t| succ(t) } end
_decrease(tm, steps)
click to toggle source
# File lib/time_boots/boot/month.rb, line 35 def _decrease(tm, steps) steps.times.inject(tm) { |t| prev(t) } end
fix_month(t, expected)
click to toggle source
fix for too far advance/insufficient decrease:
Time.new(2013,2,31) #=> 2013-03-02 00:00:00 +0200
# File lib/time_boots/boot/month.rb, line 41 def fix_month(t, expected) t.month == expected ? day.decrease(t, t.day) : t end
prev(tm)
click to toggle source
# File lib/time_boots/boot/month.rb, line 24 def prev(tm) return generate(tm, year: tm.year - 1, month: 12) if tm.month == 1 t = generate(tm, month: tm.month - 1) fix_month(t, t.month - 1) end
succ(tm)
click to toggle source
# File lib/time_boots/boot/month.rb, line 17 def succ(tm) return generate(tm, year: tm.year + 1, month: 1) if tm.month == 12 t = generate(tm, month: tm.month + 1) fix_month(t, t.month + 1) end