fix some extention bug
This commit is contained in:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user