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.



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

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



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

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

#dec_dayObject



145
146
147
# File 'lib/fugit/cron.rb', line 145

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

#dec_hourObject



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

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

#dec_minObject



151
152
153
# File 'lib/fugit/cron.rb', line 151

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

#dec_monthObject



141
142
143
# File 'lib/fugit/cron.rb', line 141

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

#dec_secObject



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

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



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

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

#inc_dayObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fugit/cron.rb', line 109

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



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

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

#inc_minObject



129
130
131
# File 'lib/fugit/cron.rb', line 129

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

#inc_monthObject



98
99
100
101
102
103
104
105
106
107
# File 'lib/fugit/cron.rb', line 98

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



133
134
135
136
137
138
139
# File 'lib/fugit/cron.rb', line 133

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



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

def time; @t; end

#to_iObject



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

def to_i; @t.to_i; end

#to_tObject



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

def to_t; @t; end