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.



89
90
91
92
93
# File 'lib/fugit/cron.rb', line 89

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



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

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

#dec_dayObject



153
154
155
# File 'lib/fugit/cron.rb', line 153

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

#dec_hourObject



156
157
158
# File 'lib/fugit/cron.rb', line 156

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

#dec_minObject



159
160
161
# File 'lib/fugit/cron.rb', line 159

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

#dec_monthObject



149
150
151
# File 'lib/fugit/cron.rb', line 149

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

#dec_secObject



163
164
165
166
167
168
# File 'lib/fugit/cron.rb', line 163

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



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

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

#inc_dayObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/fugit/cron.rb', line 117

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

#inc_hourObject



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

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

#inc_minObject



137
138
139
# File 'lib/fugit/cron.rb', line 137

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

#inc_monthObject



106
107
108
109
110
111
112
113
114
115
# File 'lib/fugit/cron.rb', line 106

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



141
142
143
144
145
146
147
# File 'lib/fugit/cron.rb', line 141

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



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

def time; @t; end

#to_iObject



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

def to_i; @t.to_i; end

#to_tObject



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

def to_t; @t; end