Fix payment transaction edit save and Jalali due date display.
Convert dates between Jalali picker values and ISO before API calls, and format due dates with proper Persian calendar tokens and digits.
This commit is contained in:
@@ -19,34 +19,49 @@ export function usePersianDate() {
|
||||
return result;
|
||||
};
|
||||
|
||||
const formatJalali = (date, formatStr = 'YYYY/MM/DD') => {
|
||||
const formatJalali = (date, formatStr = 'jYYYY/jMM/jDD') => {
|
||||
if (!date) return '-';
|
||||
try {
|
||||
return moment(date).locale('fa').format(formatStr);
|
||||
return toPersianDigits(moment(date).locale('fa').format(formatStr));
|
||||
} catch (e) {
|
||||
return '-';
|
||||
}
|
||||
};
|
||||
|
||||
const formatJalaliWithTime = (date) => {
|
||||
return formatJalali(date, 'YYYY/MM/DD - HH:mm');
|
||||
return formatJalali(date, 'jYYYY/jMM/jDD - HH:mm');
|
||||
};
|
||||
|
||||
const jalaliToIso = (jalaliStr) => {
|
||||
if (!jalaliStr) return null;
|
||||
const toJalaliPickerValue = (value) => {
|
||||
if (!value) return '';
|
||||
try {
|
||||
const latinStr = toLatinDigits(jalaliStr);
|
||||
return moment(latinStr, 'jYYYY/jMM/jDD').toISOString();
|
||||
return moment(value).locale('fa').format('jYYYY/jMM/jDD');
|
||||
} catch (e) {
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
const toGregorianIso = (jalaliValue) => {
|
||||
if (!jalaliValue) return undefined;
|
||||
if (jalaliValue instanceof Date) return jalaliValue.toISOString();
|
||||
try {
|
||||
const latin = toLatinDigits(String(jalaliValue));
|
||||
const m = moment(latin, 'jYYYY/jMM/jDD');
|
||||
return m.isValid() ? m.toDate().toISOString() : undefined;
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const jalaliToIso = (jalaliStr) => toGregorianIso(jalaliStr) || null;
|
||||
|
||||
return {
|
||||
toPersianDigits,
|
||||
toLatinDigits,
|
||||
formatJalali,
|
||||
formatJalaliWithTime,
|
||||
toJalaliPickerValue,
|
||||
toGregorianIso,
|
||||
jalaliToIso
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user