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



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

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

#dec_dayObject



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

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

#dec_hourObject



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

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

#dec_minObject



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

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

#dec_monthObject



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

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

#dec_secObject



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

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



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

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

#inc_dayObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fugit/cron.rb', line 96

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



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

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

#inc_minObject



116
117
118
# File 'lib/fugit/cron.rb', line 116

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

#inc_monthObject



85
86
87
88
89
90
91
92
93
94
# 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, @t.zone)

  self
end

#inc_secObject



120
121
122
123
124
125
126
# File 'lib/fugit/cron.rb', line 120

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



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

def to_i; @t.to_i; end

#to_tObject



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

def to_t; @t; end