fix(dashboard): fix date conversion offset, calendar arrow directions, payment duplicate warning, attendance class filter, and session auto-generation
This commit is contained in:
@@ -19,23 +19,71 @@ export function usePersianDate() {
|
||||
return result;
|
||||
};
|
||||
|
||||
const parseToMoment = (value) => {
|
||||
if (!value) return null;
|
||||
if (value instanceof Date) {
|
||||
if (Number.isNaN(value.getTime())) return null;
|
||||
return moment.utc(value.toISOString());
|
||||
}
|
||||
const latin = toLatinDigits(String(value)).trim();
|
||||
if (!latin) return null;
|
||||
|
||||
if (/^\d{4}-\d{2}-\d{2}T/.test(latin)) {
|
||||
const m = moment.utc(latin);
|
||||
return m.isValid() ? m : null;
|
||||
}
|
||||
|
||||
const match = latin.match(/^(\d{3,4})[./\-](\d{1,2})[./\-](\d{1,2})/);
|
||||
if (match) {
|
||||
const year = parseInt(match[1], 10);
|
||||
const month = parseInt(match[2], 10);
|
||||
const day = parseInt(match[3], 10);
|
||||
if (year >= 1200 && year <= 1599) {
|
||||
const normalized = `${year}/${String(month).padStart(2, '0')}/${String(day).padStart(2, '0')}`;
|
||||
const m = moment(normalized, 'jYYYY/jMM/jDD');
|
||||
return m.isValid() ? m : null;
|
||||
}
|
||||
if (year >= 1900 && year <= 2200) {
|
||||
const normalized = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
||||
const m = moment.utc(normalized, 'YYYY-MM-DD');
|
||||
return m.isValid() ? m : null;
|
||||
}
|
||||
}
|
||||
|
||||
const m = moment.utc(latin);
|
||||
return m.isValid() ? m : null;
|
||||
};
|
||||
|
||||
const formatJalali = (date, formatStr = 'jYYYY/jMM/jDD') => {
|
||||
if (!date) return '-';
|
||||
try {
|
||||
return toPersianDigits(moment(date).locale('fa').format(formatStr));
|
||||
const m = parseToMoment(date);
|
||||
if (!m || !m.isValid()) return '-';
|
||||
return toPersianDigits(m.locale('fa').format(formatStr));
|
||||
} catch (e) {
|
||||
return '-';
|
||||
}
|
||||
};
|
||||
|
||||
const formatJalaliWithTime = (date) => {
|
||||
return formatJalali(date, 'jYYYY/jMM/jDD - HH:mm');
|
||||
if (!date) return '-';
|
||||
try {
|
||||
const latin = toLatinDigits(String(date)).trim();
|
||||
if (/^\d{4}-\d{2}-\d{2}T/.test(latin) || date instanceof Date) {
|
||||
return toPersianDigits(moment(date).locale('fa').format('jYYYY/jMM/jDD - HH:mm'));
|
||||
}
|
||||
return formatJalali(date, 'jYYYY/jMM/jDD - HH:mm');
|
||||
} catch (e) {
|
||||
return '-';
|
||||
}
|
||||
};
|
||||
|
||||
const toJalaliPickerValue = (value) => {
|
||||
if (!value) return '';
|
||||
try {
|
||||
return toLatinDigits(moment(value).locale('fa').format('jYYYY/jMM/jDD'));
|
||||
const m = parseToMoment(value);
|
||||
if (!m || !m.isValid()) return '';
|
||||
return toLatinDigits(m.locale('fa').format('jYYYY/jMM/jDD'));
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
@@ -43,11 +91,10 @@ export function usePersianDate() {
|
||||
|
||||
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;
|
||||
const m = parseToMoment(jalaliValue);
|
||||
if (!m || !m.isValid()) return undefined;
|
||||
return `${m.format('YYYY-MM-DD')}T00:00:00.000Z`;
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -66,6 +113,7 @@ export function usePersianDate() {
|
||||
return {
|
||||
toPersianDigits,
|
||||
toLatinDigits,
|
||||
parseToMoment,
|
||||
formatJalali,
|
||||
formatJalaliWithTime,
|
||||
toJalaliPickerValue,
|
||||
|
||||
Reference in New Issue
Block a user