class Fugit::Cron::TimeCursor

def dec(i); inc(-i); end

def dec(i); inc(-i); end

def dec_day

def dec_day
  dec(@t.hour * 3600 + @t.min * 60 + @t.sec + 1)
end

def dec_hour

def dec_hour
  dec(@t.min * 60 + @t.sec + 1)
end

def dec_min

def dec_min
  dec(@t.sec + 1)
end

def dec_month

def dec_month
  dec((@t.day - 1) * DAY_S + @t.hour * 3600 + @t.min * 60 + @t.sec + 1)
end

def dec_sec

def dec_sec
  target =
    @cron.seconds.reverse.find { |s| s < @t.sec } ||
    @cron.seconds.last
  inc(target - @t.sec - (@t.sec > target ? 0 : 60))
end

def inc(i); @t = @t + i; self; end

def inc(i); @t = @t + i; self; end

def inc_day

def inc_day
  inc((24 - @t.hour) * 3600 - @t.min * 60 - @t.sec)
  return if @t.hour == 0
  if @t.hour < 12
    begin
      @t = ::EtOrbi.make(@t.year, @t.month, @t.day, @t.zone)
    rescue ::TZInfo::PeriodNotFound
      inc((24 - @t.hour) * 3600)
    end
  else
    inc((24 - @t.hour) * 3600)
  end
end

def inc_hour

def inc_hour
  inc((60 - @t.min) * 60 - @t.sec)
end

def inc_min

def inc_min
  inc(60 - @t.sec)
end

def inc_month

def inc_month
  y = @t.year
  m = @t.month + 1
  if m == 13; m = 1; y += 1; end
  @t = ::EtOrbi.make(y, m, @t.zone)
  self
end

def inc_sec

def inc_sec
  if sec = @cron.seconds.find { |s| s > @t.sec }
    inc(sec - @t.sec)
  else
    inc(60 - @t.sec + @cron.seconds.first)
  end
end

def initialize(cron, t)

def initialize(cron, t)
  @cron = cron
  @t = t.is_a?(TimeCursor) ? t.time : t
  @t.seconds = @t.seconds.to_i
end

def time; @t; end

def time; @t; end

def to_i; @t.to_i; end

def to_i; @t.to_i; end

def to_t; @t; end

def to_t; @t; end