Sort holidays in ascending date so we can reason on a collection of holidays a bit better
This commit is contained in:
parent
7901d65a43
commit
5b19ac8ee4
|
@ -141,7 +141,7 @@ module Holidays
|
|||
end
|
||||
end
|
||||
|
||||
holidays
|
||||
holidays.sort{|a, b| a[:date] <=> b[:date] }
|
||||
end
|
||||
|
||||
# Merge a new set of definitions into the Holidays module.
|
||||
|
|
|
@ -114,4 +114,15 @@ class HolidaysTests < Test::Unit::TestCase
|
|||
assert_equal 'Easter Monday', Holidays.on(date, :ca_qc, :informal)[0][:name]
|
||||
end
|
||||
end
|
||||
|
||||
def test_sorting
|
||||
(1..10).each{|year|
|
||||
(1..12).each{|month|
|
||||
holidays = Holidays.between(Date.civil(year, month, 1), Date.civil(year, month, 28), :gb_)
|
||||
holidays.each_with_index{|holiday, index|
|
||||
assert holiday[:date] >= holidays[index - 1][:date] if index > 0
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue