martinjw / Holiday

Calculate Public Holidays
MIT License
208 stars 82 forks source link

For Turkey public holidays wrong Ramadan and FeastOfSacrifices holidays calculations #125

Closed hasankaplan-github closed 5 months ago

hasankaplan-github commented 6 months ago

Hi, For Turkey public holidays, Ramadan holidays and FeastOfSacrifices holidays calculations are not completely correct for some years. In one Gregorian year, 2000 or 2033 for example, two Ramadan holidays may exist (in January and in December.) To cover that case GetHijriYear() method and Ramadan and FeastOfSacrifices holidays methods should return multiple results. Below is my solution:

private IEnumerable<int> GetHijriYears(int year)
{
    var diff = year - 621;
    var hijriYear = Convert.ToInt32(Math.Round(diff + decimal.Divide(diff, 33), MidpointRounding.ToZero));
    return [hijriYear, hijriYear + 1];
}

public IEnumerable<DateTime> RamadanFirstDay(int year)
{
    var hijriCalendar = new UmAlQuraCalendar();
    var hijriYears = GetHijriYears(year);

    foreach (var hijriYear in hijriYears)
    {
        var dateTime = hijriCalendar.ToDateTime(hijriYear, 10, 1, 0, 0, 0, 0);
        if (dateTime.Year != year)
        {
            continue;
        }

        yield return dateTime;
    }
}
martinjw commented 5 months ago

Released in https://github.com/martinjw/Holiday/releases/tag/2.39.0.0