UEA-Prodem
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
import { toGregorianDate, toHijriDate } from "./conversion.js";
|
||||
import { clampHijriDate } from "./range.js";
|
||||
const MAX_DAY_IN_HIJRI_MONTH = 30;
|
||||
const MIN_DAY_IN_HIJRI_MONTH = 29;
|
||||
export function getDaysInMonth(year, monthIndex) {
|
||||
const clamped = clampHijriDate({ year, monthIndex, day: 1 });
|
||||
for (let day = MAX_DAY_IN_HIJRI_MONTH; day >= MIN_DAY_IN_HIJRI_MONTH; day -= 1) {
|
||||
const candidateDate = toGregorianDate({
|
||||
year: clamped.year,
|
||||
monthIndex: clamped.monthIndex,
|
||||
day,
|
||||
});
|
||||
const roundTrip = toHijriDate(candidateDate);
|
||||
if (roundTrip.year === clamped.year &&
|
||||
roundTrip.monthIndex === clamped.monthIndex &&
|
||||
roundTrip.day === day) {
|
||||
return day;
|
||||
}
|
||||
}
|
||||
return MIN_DAY_IN_HIJRI_MONTH;
|
||||
}
|
||||
Reference in New Issue
Block a user