islamic-network / api.aladhan.com

The AlAdhan API
GNU General Public License v3.0
124 stars 32 forks source link

Duplicate dates appear in date conversion #30

Closed meezaan closed 5 years ago

meezaan commented 5 years ago

This is likely related to the code here: https://github.com/islamic-network/api.aladhan.com/blob/master/src/AlAdhanApi/Model/HijriCalendarService.php#L418.

Calling http://api.aladhan.com/v1/gToH?date=30-10-2019 or http://api.aladhan.com/v1/gToH?date=29-10-2019 returns the same Hijri date (01-03-1441), which is obviously incorrect. It should likely correspond to 30-10-2019, as http://api.aladhan.com/v1/hToG?date=01-03-1441 produces.

meezaan commented 5 years ago

Fixed. This issue occurred because we were using PHP'd Date validation to validate a Hijri Date. It so happened that 2019 happens to be the year where October 29 in the Gregorian Calendar aligns with Safar 29, 1441. Safar 29 was interpreted as February 29 by the Date class in PHP in a leap year, so it switched the date to the first of March.

There is now a separate method to validate Hijri dates, but it needs work as it only really validates the format.