Skip to content

Commit

Permalink
Occurrences in DST start/end hour shouldn't be skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
avit authored and rlivsey committed Jun 18, 2013
1 parent 4436bfb commit 94549ea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/ice_cube/time_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ def self.days_in_n_months(time, month_distance)
((date >> month_distance) - date).to_i
end

def self.dst_change(time)
one_hour_ago = time - ONE_HOUR
if time.dst? ^ one_hour_ago.dst?
(time.utc_offset - one_hour_ago.utc_offset) / ONE_HOUR
end
end

# A utility class for safely moving time around
class TimeWrapper

Expand Down
19 changes: 18 additions & 1 deletion lib/ice_cube/validations/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module IceCube

module Validations::Lock

INTERVALS = {:hour => 24, :min => 60, :sec => 60, :month => 12, :wday => 7}
INTERVALS = {:min => 60, :sec => 60, :month => 12, :wday => 7}

def validate(time, schedule)
return send(:"validate_#{type}_lock", time, schedule) unless INTERVALS[type]
Expand All @@ -16,6 +16,23 @@ def validate(time, schedule)

private

# Lock the hour if explicitly set by hour_of_day, but allow for the nearest
# hour during DST start to keep the correct interval.
#
def validate_hour_lock(time, schedule)
hour = value || schedule.start_time.send(type)
hour = 24 + hour if hour < 0
if hour >= time.hour
hour - time.hour
else
if dst_offset = TimeUtil.dst_change(time)
hour - time.hour + dst_offset
else
24 - time.hour + hour
end
end
end

# For monthly rules that have no specified day value, the validation relies
# on the schedule start time and jumps to include every month even if it
# has fewer days than the schedule's start day.
Expand Down
6 changes: 6 additions & 0 deletions lib/ice_cube/validations/schedule_lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def build_ical(builder)
def build_hash(builder)
end

def dst_adjust?
case @type
when :sec, :min then false
else true
end
end
end

end
Expand Down

0 comments on commit 94549ea

Please sign in to comment.