Class: Fugit::Cron::TimeCursor

Inherits:
Object
  • Object
show all
Defined in:
lib/fugit/cron.rb

Instance Method Summary collapse

Constructor Details

#initialize(t) ⇒ TimeCursor

Returns a new instance of TimeCursor.



68
69
70
71
# File 'lib/fugit/cron.rb', line 68

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

Instance Method Details

#dec(i) ⇒ Object



83
# File 'lib/fugit/cron.rb', line 83

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

#dec_dayObject



107
# File 'lib/fugit/cron.rb', line 107

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

#dec_hourObject



108
# File 'lib/fugit/cron.rb', line 108

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

#dec_minObject



109
# File 'lib/fugit/cron.rb', line 109

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

#dec_monthObject



104
105
106
# File 'lib/fugit/cron.rb', line 104

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

#dec_sec(seconds) ⇒ Object



111
112
113
114
# File 'lib/fugit/cron.rb', line 111

def dec_sec(seconds)
  target = seconds.reverse.find { |s| s < @t.sec } || seconds.last
  inc(target - @t.sec)
end

#inc(i) ⇒ Object



79
80
81
82
# File 'lib/fugit/cron.rb', line 79

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

#inc_dayObject



92
# File 'lib/fugit/cron.rb', line 92

def inc_day; inc((24 - @t.hour) * 3600 - @t.min * 60 - @t.sec); end

#inc_hourObject



93
# File 'lib/fugit/cron.rb', line 93

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

#inc_minObject



94
# File 'lib/fugit/cron.rb', line 94

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

#inc_monthObject



85
86
87
88
89
90
91
# File 'lib/fugit/cron.rb', line 85

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

#inc_sec(seconds) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/fugit/cron.rb', line 96

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

#timeObject



73
# File 'lib/fugit/cron.rb', line 73

def time; @t; end

#to_iObject



74
# File 'lib/fugit/cron.rb', line 74

def to_i; @t.to_i; end