Class: Fugit::Cron::TimeCursor
- Inherits:
-
Object
- Object
- Fugit::Cron::TimeCursor
- Defined in:
- lib/fugit/cron.rb
Instance Method Summary collapse
- #dec(i) ⇒ Object
- #dec_day ⇒ Object
- #dec_hour ⇒ Object
- #dec_min ⇒ Object
- #dec_month ⇒ Object
- #dec_sec ⇒ Object
- #inc(i) ⇒ Object
- #inc_day ⇒ Object
- #inc_hour ⇒ Object
- #inc_min ⇒ Object
- #inc_month ⇒ Object
- #inc_sec ⇒ Object
-
#initialize(cron, t) ⇒ TimeCursor
constructor
A new instance of TimeCursor.
- #time ⇒ Object
- #to_i ⇒ Object
- #to_t ⇒ Object
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_day ⇒ Object
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_hour ⇒ Object
135 136 137 |
# File 'lib/fugit/cron.rb', line 135 def dec_hour dec(@t.min * 60 + @t.sec + 1) end |
#dec_min ⇒ Object
138 139 140 |
# File 'lib/fugit/cron.rb', line 138 def dec_min dec(@t.sec + 1) end |
#dec_month ⇒ Object
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_sec ⇒ Object
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_day ⇒ Object
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_hour ⇒ Object
113 114 115 |
# File 'lib/fugit/cron.rb', line 113 def inc_hour inc((60 - @t.min) * 60 - @t.sec) end |
#inc_min ⇒ Object
116 117 118 |
# File 'lib/fugit/cron.rb', line 116 def inc_min inc(60 - @t.sec) end |
#inc_month ⇒ Object
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_sec ⇒ Object
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 |
#time ⇒ Object
74 |
# File 'lib/fugit/cron.rb', line 74 def time; @t; end |
#to_i ⇒ Object
77 |
# File 'lib/fugit/cron.rb', line 77 def to_i; @t.to_i; end |
#to_t ⇒ Object
75 |
# File 'lib/fugit/cron.rb', line 75 def to_t; @t; end |