fix(dates): enforce standard Iranian calendar dates for default values and monthly range
This commit is contained in:
@@ -35,7 +35,7 @@ export function usePersianDate() {
|
|||||||
const toJalaliPickerValue = (value) => {
|
const toJalaliPickerValue = (value) => {
|
||||||
if (!value) return '';
|
if (!value) return '';
|
||||||
try {
|
try {
|
||||||
return moment(value).locale('fa').format('jYYYY/jMM/jDD');
|
return toLatinDigits(moment(value).locale('fa').format('jYYYY/jMM/jDD'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,11 @@ export function usePersianDate() {
|
|||||||
const jalaliToIso = (jalaliStr) => toGregorianIso(jalaliStr) || null;
|
const jalaliToIso = (jalaliStr) => toGregorianIso(jalaliStr) || null;
|
||||||
|
|
||||||
const getTodayJalali = (formatStr = 'jYYYY/jMM/jDD') => {
|
const getTodayJalali = (formatStr = 'jYYYY/jMM/jDD') => {
|
||||||
return moment().locale('fa').format(formatStr);
|
return toLatinDigits(moment().locale('fa').format(formatStr));
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStartOfJalaliMonth = (formatStr = 'jYYYY/jMM/jDD') => {
|
||||||
|
return toLatinDigits(moment().startOf('jMonth').locale('fa').format(formatStr));
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -67,7 +71,9 @@ export function usePersianDate() {
|
|||||||
toJalaliPickerValue,
|
toJalaliPickerValue,
|
||||||
toGregorianIso,
|
toGregorianIso,
|
||||||
jalaliToIso,
|
jalaliToIso,
|
||||||
getTodayJalali
|
getTodayJalali,
|
||||||
|
getStartOfJalaliMonth
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -159,10 +159,11 @@ const resetForm = () => {
|
|||||||
form.title = '';
|
form.title = '';
|
||||||
form.category = '';
|
form.category = '';
|
||||||
form.amount = 0;
|
form.amount = 0;
|
||||||
form.date = toJalaliPickerValue(new Date());
|
form.date = getTodayJalali();
|
||||||
form.notes = '';
|
form.notes = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const openCreateModal = () => {
|
const openCreateModal = () => {
|
||||||
isEditMode.value = false;
|
isEditMode.value = false;
|
||||||
editingId.value = null;
|
editingId.value = null;
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ import TabPanel from 'primevue/tabpanel';
|
|||||||
import DatePicker from 'vue3-persian-datetime-picker';
|
import DatePicker from 'vue3-persian-datetime-picker';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { toPersianDigits, formatJalali, toGregorianIso, toJalaliPickerValue, getTodayJalali } = usePersianDate();
|
const { toPersianDigits, formatJalali, toGregorianIso, toJalaliPickerValue, getTodayJalali, getStartOfJalaliMonth } = usePersianDate();
|
||||||
const { showError } = useToast();
|
const { showError } = useToast();
|
||||||
|
|
||||||
const formatToman = (value) => `${toPersianDigits(Math.round(value || 0).toLocaleString())} تومان`;
|
const formatToman = (value) => `${toPersianDigits(Math.round(value || 0).toLocaleString())} تومان`;
|
||||||
@@ -416,12 +416,11 @@ const rangeReport = ref(null);
|
|||||||
const isRangeReportLoading = ref(false);
|
const isRangeReportLoading = ref(false);
|
||||||
|
|
||||||
const setThisMonth = () => {
|
const setThisMonth = () => {
|
||||||
const now = new Date();
|
rangeForm.startDate = getStartOfJalaliMonth();
|
||||||
const first = new Date(now.getFullYear(), now.getMonth(), 1);
|
rangeForm.endDate = getTodayJalali();
|
||||||
rangeForm.startDate = toJalaliPickerValue(first);
|
|
||||||
rangeForm.endDate = toJalaliPickerValue(now);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const loadRangeReport = async () => {
|
const loadRangeReport = async () => {
|
||||||
isRangeReportLoading.value = true;
|
isRangeReportLoading.value = true;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user