fix date formatting and parsing logic

- Support time formatting in `formatDate` with `time` option.
- Improve parsing in `ISOToDate` to handle time information or date-only strings.
This commit is contained in:
2025-08-11 15:51:46 +02:00
parent ebc2921696
commit 90d3bf32e6
3 changed files with 33 additions and 5 deletions

View File

@@ -0,0 +1,6 @@
kind: Fixed
body: fix date formatting in calendar range display
time: 2025-08-11T15:52:12.949078671+02:00
custom:
Issue: ""
SchemaChange: No schema change

View File

@@ -104,7 +104,7 @@
event.title
}}</b>
<b v-else-if="event.extendedProps.is === 'range'"
>{{ formatDate(event.startStr) }} -
>{{ formatDate(event.startStr) }} - {{ formatDate(event.endStr, 'time') }}:
{{ event.extendedProps.locationName }}</b
>
<b v-else-if="event.extendedProps.is === 'local'">{{
@@ -296,9 +296,26 @@ const nextWeeks = computed((): Weeks[] =>
}),
);
const formatDate = (datetime: string) => {
console.log(typeof datetime);
return ISOToDate(datetime);
const formatDate = (datetime: string, format: null | 'time' = null) => {
const date = ISOToDate(datetime);
if (!date) return '';
if (format === 'time') {
return date.toLocaleTimeString('fr-FR', {
hour: '2-digit',
minute: '2-digit'
});
}
// French date formatting
return date.toLocaleDateString('fr-FR', {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
};
const baseOptions = ref<CalendarOptions>({

View File

@@ -37,8 +37,13 @@ export const ISOToDate = (str: string | null): Date | null => {
return null;
}
const [year, month, day] = str.split("-").map((p) => parseInt(p));
// If the string already contains time info, use it directly
if (str.includes('T') || str.includes(' ')) {
return new Date(str);
}
// Otherwise, parse date only
const [year, month, day] = str.split("-").map((p) => parseInt(p));
return new Date(year, month - 1, day, 0, 0, 0, 0);
};