Initial commit: admin dashboard for GameNo.
Vue 3 + Vite dashboard with PrimeVue, i18n, and API integration for institution management.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// /src/composables/usePersianDate.js
|
||||
import moment from 'jalali-moment';
|
||||
|
||||
export function usePersianDate() {
|
||||
const toPersianDigits = (num) => {
|
||||
if (num === null || num === undefined) return '';
|
||||
const str = String(num);
|
||||
const farsiDigits = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
|
||||
return str.replace(/\d/g, (x) => farsiDigits[parseInt(x)]);
|
||||
};
|
||||
|
||||
const toLatinDigits = (str) => {
|
||||
if (!str) return '';
|
||||
const farsiDigits = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g];
|
||||
let result = String(str);
|
||||
for (let i = 0; i < 10; i++) {
|
||||
result = result.replace(farsiDigits[i], String(i));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const formatJalali = (date, formatStr = 'YYYY/MM/DD') => {
|
||||
if (!date) return '-';
|
||||
try {
|
||||
return moment(date).locale('fa').format(formatStr);
|
||||
} catch (e) {
|
||||
return '-';
|
||||
}
|
||||
};
|
||||
|
||||
const formatJalaliWithTime = (date) => {
|
||||
return formatJalali(date, 'YYYY/MM/DD - HH:mm');
|
||||
};
|
||||
|
||||
const jalaliToIso = (jalaliStr) => {
|
||||
if (!jalaliStr) return null;
|
||||
try {
|
||||
const latinStr = toLatinDigits(jalaliStr);
|
||||
return moment(latinStr, 'jYYYY/jMM/jDD').toISOString();
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
toPersianDigits,
|
||||
toLatinDigits,
|
||||
formatJalali,
|
||||
formatJalaliWithTime,
|
||||
jalaliToIso
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user