fix some extention bug

This commit is contained in:
2026-09-16 13:44:58 +03:30
parent cf92635c0e
commit 6ba6a9cd45
3 changed files with 43 additions and 22 deletions
+4 -18
View File
@@ -1,6 +1,6 @@
/** Shared Iran timezone helpers for SuperAdmin API. */
import { toGregorian, jalaaliMonthLength } from 'jalaali-js';
import { toGregorian, jalaaliMonthLength, toJalaali } from 'jalaali-js';
export const IRAN_TZ = 'Asia/Tehran';
@@ -45,23 +45,9 @@ export type IranJalaliYmd = { year: number; month: number; day: number };
/** Jalali Y/M/D for a Date in Asia/Tehran. */
export function iranJalaliParts(date: Date): IranJalaliYmd {
const parts = new Intl.DateTimeFormat('en-u-ca-persian', {
timeZone: IRAN_TZ,
year: 'numeric',
month: 'numeric',
day: 'numeric',
}).formatToParts(date);
const num = (type: Intl.DateTimeFormatPartTypes) => {
const raw = parts.find((p) => p.type === type)?.value ?? '';
const n = Number(raw);
if (!Number.isFinite(n)) {
throw new Error(`Cannot read Jalali ${type} from ${date.toISOString()}`);
}
return n;
};
return { year: num('year'), month: num('month'), day: num('day') };
const [gy, gm, gd] = iranYmd(date).split('-').map(Number);
const { jy, jm, jd } = toJalaali(gy, gm, gd);
return { year: jy, month: jm, day: jd };
}
/** Noon Iran (+03:30) for a Jalali calendar day. */