From 5b19ac8ee4932c1c10cff0cfadc01089766da745 Mon Sep 17 00:00:00 2001 From: Rowan Crawford Date: Sat, 1 May 2010 18:25:09 +0800 Subject: [PATCH] Sort holidays in ascending date so we can reason on a collection of holidays a bit better --- lib/holidays.rb | 2 +- test/test_holidays.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/holidays.rb b/lib/holidays.rb index 3b722c7..b818ed0 100644 --- a/lib/holidays.rb +++ b/lib/holidays.rb @@ -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. diff --git a/test/test_holidays.rb b/test/test_holidays.rb index c62be1f..8baa2ae 100644 --- a/test/test_holidays.rb +++ b/test/test_holidays.rb @@ -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