getNewMoonDatesInHijriYear static method
الحصول على جميع تواريخ المحاق في سنة هجرية معينة
Implementation
static List<HijriDate> getNewMoonDatesInHijriYear(int hijriYear) {
List<HijriDate> newMoons = [];
HijriDate startDate = HijriDate();
startDate.hYear = hijriYear;
startDate.hMonth = 1;
startDate.hDay = 1;
DateTime startGregorian = startDate.hijriToGregorian(hijriYear, 1, 1);
DateTime endGregorian = startDate.hijriToGregorian(hijriYear + 1, 1, 1);
DateTime currentDate = startGregorian;
MoonPhase? lastPhase;
while (currentDate.isBefore(endGregorian)) {
MoonPhaseInfo moonInfo = getMoonPhase(currentDate);
// Add only when transitioning to new moon (to avoid duplicate consecutive days)
if (moonInfo.phase == MoonPhase.newMoon &&
lastPhase != MoonPhase.newMoon) {
HijriDate hijriNewMoon = HijriDate.fromDate(currentDate);
newMoons.add(hijriNewMoon);
}
lastPhase = moonInfo.phase;
currentDate = currentDate.add(Duration(days: 1));
}
return newMoons;
}