Sort holidays in ascending date so we can reason on a collection of holidays a bit better

This commit is contained in:
Rowan Crawford 2010-05-01 18:25:09 +08:00 committed by Alex Dunae
parent 7901d65a43
commit 5b19ac8ee4
2 changed files with 12 additions and 1 deletions

View file

@ -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.

View file

@ -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