getFullMoonDatesInHijriYear static method

List<HijriDate> getFullMoonDatesInHijriYear(
  1. int hijriYear
)

الحصول على جميع تواريخ البدر في سنة هجرية معينة

Implementation

static List<HijriDate> getFullMoonDatesInHijriYear(int hijriYear) {
  List<HijriDate> fullMoons = [];

  // البدء من بداية السنة الهجرية
  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 full moon (to avoid duplicate consecutive days)
    if (moonInfo.phase == MoonPhase.fullMoon &&
        lastPhase != MoonPhase.fullMoon) {
      HijriDate hijriFullMoon = HijriDate.fromDate(currentDate);
      fullMoons.add(hijriFullMoon);
    }

    lastPhase = moonInfo.phase;
    currentDate = currentDate.add(Duration(days: 1));
  }

  return fullMoons;
}