martinjw/Holiday

Exception Thrown: AustraliaPublicHoliday

Closed this issue · 2 comments

Hi there,

Firstly a great library, but I have a come across an issue while using your library:

Using **Australian Public Holiday** with state **NSW** and Year **2016**

Code

// Get the holidays based on state
var calendar = new AustraliaPublicHoliday { State = AustraliaPublicHoliday.States.NSW };
var result = calendar.PublicHolidayNames(2016);

**Exception: Message: "An item with the same key has already been added. Key: [26/12/2016 12:00:00 AM, Boxing Day]" **

'calendar.PublicHolidayNames(2016)' threw an exception of type 'System.ArgumentException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2147024809
    HelpLink: null
    InnerException: null
    Message: "An item with the same key has already been added. Key: [26/12/2016 12:00:00 AM, Boxing Day]"
    ParamName: null
    Source: "System.Collections"
    StackTrace: "   at System.Collections.Generic.TreeSet`1.AddIfNotPresent(T item)\r\n   at System.Collections.Generic.SortedDictionary`2.Add(TKey key, TValue value)\r\n   at PublicHoliday.AustraliaPublicHoliday.PublicHolidayNames(Int32 year)"
    TargetSite: {Boolean AddIfNotPresent(T)}

Even though this error shouldn't really be happening, as a first step I think it's important to ensure that the same item can't be added twice.

It was an error in the Boxing Day calculation. A check to avoid adding the date twice would have returned a wrong result (missing Boxing Day).

Thanks for the report! It'll be on nuget soon...

Cheers thanks for that, good point