diff options
author | Georg Zotti <Georg.Zotti@univie.ac.at> | 2022-01-31 18:49:52 +0100 |
---|---|---|
committer | Georg Zotti <Georg.Zotti@univie.ac.at> | 2022-01-31 18:49:52 +0100 |
commit | d1f4288c37f159b52097a1b96b7c2e748ab62094 (patch) | |
tree | e11ac9f4e55e903202440f916da89ad903807ad0 | |
parent | 6f44323dc7a158786a164d9e19e66c73c49d05e8 (diff) |
Calendars: Fix a stupid bug (Fix #2153)
-rw-r--r-- | plugins/Calendars/src/HebrewCalendar.cpp | 16 | ||||
-rw-r--r-- | plugins/Calendars/src/test/testCalendars.cpp | 6 |
2 files changed, 17 insertions, 5 deletions
diff --git a/plugins/Calendars/src/HebrewCalendar.cpp b/plugins/Calendars/src/HebrewCalendar.cpp index 6e84a19ba9..2eb1cdc47c 100644 --- a/plugins/Calendars/src/HebrewCalendar.cpp +++ b/plugins/Calendars/src/HebrewCalendar.cpp @@ -72,7 +72,6 @@ void HebrewCalendar::setJD(double JD) // get a stringlist of calendar date elements sorted from the largest to the smallest. // Year, Month, MonthName, Day, DayName -// Again, in this plugin only, note no year zero, and AD/BC counting. QStringList HebrewCalendar::getDateStrings() const { const int rd=fixedFromHebrew(parts); @@ -150,8 +149,15 @@ double HebrewCalendar::molad(int hYear, int hMonth) int HebrewCalendar::hebrewCalendarElapsedDays(int hYear) { const int monthsElapsed=StelUtils::intFloorDiv(235*hYear-234, 19); - const int partsElapsed=12084+13753*monthsElapsed; - const int days = 29*monthsElapsed+StelUtils::intFloorDiv(partsElapsed, 25920); + //const int partsElapsed=12084+13753*monthsElapsed; + //const int days = 29*monthsElapsed+StelUtils::intFloorDiv(partsElapsed, 25920); + // Alternative solution to avoid large 32bit ints: + const int partsElapsed=204+793*StelUtils::imod(monthsElapsed, 1080); + const int hoursElapsed=11+12*monthsElapsed + + 793*StelUtils::intFloorDiv(monthsElapsed, 1080) + + StelUtils::intFloorDiv(partsElapsed, 1080); + const int days=29*monthsElapsed+ StelUtils::intFloorDiv(hoursElapsed, 24); + if (StelUtils::imod(3*(days+1), 7)<3) return days+1; else @@ -229,7 +235,7 @@ int HebrewCalendar::fixedFromHebrew(QVector<int> hebrew) QVector<int> HebrewCalendar::hebrewFromFixed(int rd) { - const int approx = StelUtils::intFloorDiv(98496*(rd-hebrewEpoch), 35975351)+1; + const int approx = StelUtils::intFloorDivLL(98496*(rd-hebrewEpoch), 35975351)+1; int year=approx-1; while (hebrewNewYear(year+1)<=rd) @@ -238,7 +244,7 @@ QVector<int> HebrewCalendar::hebrewFromFixed(int rd) const int start= (rd<fixedFromHebrew({year, HebrewCalendar::nisan, 1}) ? HebrewCalendar::tishri : HebrewCalendar::nisan); int month=start; - while (rd>fixedFromHebrew({year, month, lastDayOfHebrewMonth(month, year)})) + while (rd>fixedFromHebrew({year, month, lastDayOfHebrewMonth(year, month)})) month++; const int day=rd-fixedFromHebrew({year, month, 1})+1; diff --git a/plugins/Calendars/src/test/testCalendars.cpp b/plugins/Calendars/src/test/testCalendars.cpp index e5e9da9164..ce69455af2 100644 --- a/plugins/Calendars/src/test/testCalendars.cpp +++ b/plugins/Calendars/src/test/testCalendars.cpp @@ -985,6 +985,7 @@ void TestCalendars::testIslamic() void TestCalendars::testHebrew() { + QVERIFY(HebrewCalendar::hebrewEpoch==-1373427); QVERIFY(-214193==HebrewCalendar::fixedFromHebrew({3174, 5, 10})); QVERIFY( -61387==HebrewCalendar::fixedFromHebrew({3593, 9, 25})); QVERIFY( 25469==HebrewCalendar::fixedFromHebrew({3831, 7, 3})); @@ -1054,6 +1055,11 @@ void TestCalendars::testHebrew() QVERIFY(HebrewCalendar::hebrewFromFixed( 728714)==QVector<int>({5756, 12, 5})); QVERIFY(HebrewCalendar::hebrewFromFixed( 744313)==QVector<int>({5799, 8, 12})); QVERIFY(HebrewCalendar::hebrewFromFixed( 764652)==QVector<int>({5854, 5, 5})); + + // Bug GH#2153 + QVERIFY(HebrewCalendar::hebrewFromFixed(GregorianCalendar::fixedFromGregorian({2022, 1, 2})) == QVector<int>({5782, 10, 29})); + QVERIFY(HebrewCalendar::hebrewFromFixed(GregorianCalendar::fixedFromGregorian({2022, 1, 3})) == QVector<int>({5782, 11, 1})); + QVERIFY(HebrewCalendar::hebrewFromFixed(GregorianCalendar::fixedFromGregorian({2022, 1, 4})) == QVector<int>({5782, 11, 2})); } void TestCalendars::testPersian() |