lib/rufus/scheduler/cronline.rb in rufus-scheduler-3.3.4 vs lib/rufus/scheduler/cronline.rb in rufus-scheduler-3.4.0

- old
+ new

@@ -1,32 +1,7 @@ -#-- -# Copyright (c) 2006-2017, John Mettraux, jmettraux@gmail.com -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -# Made in Japan. -#++ -require 'set' - class Rufus::Scheduler # # A 'cron line' is a line in the sense of a crontab # (man 5 crontab) file line. @@ -61,14 +36,14 @@ @original = line @original_timezone = nil items = line.split - if @timezone = ZoTime.get_tzone(items.last) + if @timezone = EoTime.get_tzone(items.last) @original_timezone = items.pop else - @timezone = ZoTime.get_tzone(:current) + @timezone = EoTime.local_tzone end fail ArgumentError.new( "not a valid cronline : '#{line}'" ) unless items.length == 5 or items.length == 6 @@ -97,14 +72,14 @@ # Returns true if the given time matches this cron line. # def matches?(time) - # FIXME Don't create a new ZoTime if time is already a ZoTime in same + # FIXME Don't create a new EoTime if time is already a EoTime in same # zone ... # Wait, this seems only used in specs... - t = ZoTime.new(time.to_f, @timezone) + t = EoTime.new(time.to_f, @timezone) return false unless sub_match?(t, :sec, @seconds) return false unless sub_match?(t, :min, @minutes) return false unless sub_match?(t, :hour, @hours) return false unless date_match?(t) @@ -136,14 +111,14 @@ # Time.utc(2008, 10, 24, 7, 29)).localtime # #=> Fri Oct 24 02:30:00 -0500 2008 # # (Thanks to K Liu for the note and the examples) # - def next_time(from=ZoTime.now) + def next_time(from=EoTime.now) nt = nil - zt = ZoTime.new(from.to_i + 1, @timezone) + zt = EoTime.new(from.to_i + 1, @timezone) maxy = from.year + NEXT_TIME_MAX_YEARS loop do nt = zt.dup @@ -177,14 +152,14 @@ end # Returns the previous time the cronline matched. It's like next_time, but # for the past. # - def previous_time(from=ZoTime.now) + def previous_time(from=EoTime.now) pt = nil - zt = ZoTime.new(from.to_i - 1, @timezone) + zt = EoTime.new(from.to_i - 1, @timezone) miny = from.year - NEXT_TIME_MAX_YEARS loop do pt = zt.dup @@ -193,23 +168,23 @@ "failed to reach occurrence within " + "#{NEXT_TIME_MAX_YEARS} years for '#{original}'" ) if pt.year < miny unless date_match?(pt) - zt.substract(pt.hour * 3600 + pt.min * 60 + pt.sec + 1) + zt.subtract(pt.hour * 3600 + pt.min * 60 + pt.sec + 1) next end unless sub_match?(pt, :hour, @hours) - zt.substract(pt.min * 60 + pt.sec + 1) + zt.subtract(pt.min * 60 + pt.sec + 1) next end unless sub_match?(pt, :min, @minutes) - zt.substract(pt.sec + 1) + zt.subtract(pt.sec + 1) next end unless sub_match?(pt, :sec, @seconds) - zt.substract(prev_second(pt)) + zt.subtract(prev_second(pt)) next end break end @@ -257,10 +232,10 @@ # Caching facility. Currently only used for brute frequencies. # @cache = {}; class << self; attr_reader :cache; end - # Returns the shortest delta between two potential occurences of the + # Returns the shortest delta between two potential occurrences of the # schedule described by this cronline. # # . # # For a simple cronline like "*/5 * * * *", obviously the frequency is