2024-03-22 17:10:00 +00:00
|
|
|
import { reactive, ref, computed } from 'vue';
|
2024-03-14 12:48:04 +00:00
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
|
|
|
|
export const useWeekdayStore = defineStore('weekdayStore', () => {
|
2024-04-03 11:08:54 +00:00
|
|
|
const { t } = useI18n();
|
|
|
|
|
2024-03-14 12:48:04 +00:00
|
|
|
const weekdays = [
|
|
|
|
{ code: 'sun', name: 'Sunday' },
|
|
|
|
{ code: 'mon', name: 'Monday' },
|
|
|
|
{ code: 'tue', name: 'Tuesday' },
|
|
|
|
{ code: 'wed', name: 'Wednesday' },
|
|
|
|
{ code: 'thu', name: 'Thursday' },
|
|
|
|
{ code: 'fri', name: 'Friday' },
|
|
|
|
{ code: 'sat', name: 'Saturday' },
|
|
|
|
];
|
|
|
|
|
2024-04-03 11:08:54 +00:00
|
|
|
const monthCodes = [
|
|
|
|
'jan',
|
|
|
|
'feb',
|
|
|
|
'mar',
|
|
|
|
'apr',
|
|
|
|
'may',
|
|
|
|
'jun',
|
|
|
|
'jul',
|
|
|
|
'aug',
|
|
|
|
'sep',
|
|
|
|
'oct',
|
|
|
|
'nov',
|
|
|
|
'dec',
|
|
|
|
];
|
|
|
|
|
2024-03-22 17:10:00 +00:00
|
|
|
const localeOrder = {
|
|
|
|
es: ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'],
|
|
|
|
en: ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
|
|
|
|
};
|
|
|
|
|
2024-03-14 12:48:04 +00:00
|
|
|
const weekdaysMap = reactive({});
|
2024-03-22 17:10:00 +00:00
|
|
|
const localeWeekdays = ref([]);
|
2024-03-14 12:48:04 +00:00
|
|
|
|
|
|
|
const initStore = () => {
|
|
|
|
getWeekdaysMap();
|
|
|
|
};
|
|
|
|
|
|
|
|
const getWeekdaysMap = () => {
|
|
|
|
if (Object.keys(weekdaysMap).length > 0) return weekdaysMap;
|
|
|
|
|
|
|
|
weekdays.forEach((day, i) => {
|
|
|
|
const obj = {
|
|
|
|
...day,
|
|
|
|
index: i,
|
|
|
|
char: day.name.substr(0, 1),
|
|
|
|
abr: day.name.substr(0, 3),
|
|
|
|
};
|
|
|
|
weekdaysMap[day.code] = obj;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-03-22 17:10:00 +00:00
|
|
|
const getLocales = computed(() => {
|
|
|
|
// El día de mañana esto permitirá ordenar los weekdays en base a el locale si se lo desea reemplazando localeOrder.es por localeOrder[locale]
|
|
|
|
const locales = [];
|
|
|
|
for (let code of localeOrder.es) {
|
2024-04-02 12:13:12 +00:00
|
|
|
const weekDay = weekdaysMap[code];
|
|
|
|
const locale = t(`weekdays.${weekdaysMap[code].code}`);
|
2024-03-22 17:10:00 +00:00
|
|
|
const obj = {
|
2024-04-02 12:13:12 +00:00
|
|
|
...weekDay,
|
|
|
|
locale,
|
|
|
|
localeChar: locale.substr(0, 1),
|
|
|
|
localeAbr: locale.substr(0, 3),
|
2024-03-22 17:10:00 +00:00
|
|
|
};
|
|
|
|
locales.push(obj);
|
|
|
|
}
|
|
|
|
return locales;
|
|
|
|
});
|
|
|
|
|
2024-04-03 11:08:54 +00:00
|
|
|
const getLocaleMonths = computed(() => {
|
|
|
|
const locales = [];
|
|
|
|
for (let code of monthCodes) {
|
|
|
|
const obj = {
|
|
|
|
code: code,
|
|
|
|
locale: t(`months.${code}`),
|
|
|
|
};
|
|
|
|
locales.push(obj);
|
|
|
|
}
|
|
|
|
return locales;
|
|
|
|
});
|
|
|
|
|
2024-03-14 12:48:04 +00:00
|
|
|
return {
|
|
|
|
initStore,
|
|
|
|
weekdaysMap,
|
2024-03-22 17:10:00 +00:00
|
|
|
localeWeekdays,
|
|
|
|
getLocales,
|
2024-04-03 11:08:54 +00:00
|
|
|
weekdays,
|
|
|
|
monthCodes,
|
|
|
|
getLocaleMonths,
|
2024-03-14 12:48:04 +00:00
|
|
|
};
|
|
|
|
});
|