Class: Fugit::Cron::TimeCursor

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

Instance Method Summary collapse

Constructor Details

#initialize(cron, t) ⇒ TimeCursor

Returns a new instance of TimeCursor.



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

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

Instance Method Details

#dec(i) ⇒ Object



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

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

#dec_dayObject



121
122
123
# File 'lib/fugit/cron.rb', line 121

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

#dec_hourObject



124
125
126
# File 'lib/fugit/cron.rb', line 124

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

#dec_minObject



127
128
129
# File 'lib/fugit/cron.rb', line 127

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

#dec_monthObject



112
113
114
115
116
117
118
119
# File 'lib/fugit/cron.rb', line 112

def dec_month

  #dec(@t.day * 24 * 3600 + @t.hour * 3600 + @t.min * 60 + @t.sec + 1)
    #
    # gh-18, so that '0 9 29 feb *' doesn't get skipped (over and over)
    #
  dec(@t.day * 24 * 3600 + 1)
end

#dec_secObject



131
132
133
134
135
136
# File 'lib/fugit/cron.rb', line 131

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

#inc(i) ⇒ Object



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

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

#inc_dayObject



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

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

#inc_hourObject



97
98
99
# File 'lib/fugit/cron.rb', line 97

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

#inc_minObject



100
101
102
# File 'lib/fugit/cron.rb', line 100

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

#inc_monthObject



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

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

#inc_secObject



104
105
106
107
108
109
110
# File 'lib/fugit/cron.rb', line 104

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

#timeObject



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

def time; @t; end

#to_iObject



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

def to_i; @t.to_i; end