Fixed issue with past dates

Some past dates would render as the wrong year packet number
This commit is contained in:
Alexis
2024-05-20 18:55:09 +02:00
parent a1d0ae0f35
commit f361fdeb49

View File

@@ -505,11 +505,20 @@ export const useCalendar = defineStore('calendar', () => {
const isSameMonth = baseDate.month === relativeDate.month const isSameMonth = baseDate.month === relativeDate.month
const isSameYear = baseDate.year === relativeDate.year const isSameYear = baseDate.year === relativeDate.year
const yearPackets: number = direction === 'future' || isSameYear ? Math.abs(baseDate.year - relativeDate.year) : Math.abs(baseDate.year - relativeDate.year) let yearPackets: number
// const monthPackets: number = Math.abs(Math.trunc(differenceInDays / daysPerMonth) % months.value.length)
const monthPackets: number = direction === 'future' || isSameMonth ? Math.abs(baseDate.month - relativeDate.month) : Math.abs(months.value.length - relativeDate.month) const monthPackets: number = direction === 'future' || isSameMonth ? Math.abs(baseDate.month - relativeDate.month) : Math.abs(months.value.length - relativeDate.month)
// This would need to be a reduce with an array of valid months appart like in the previous refactor if (direction === 'future') {
yearPackets = Math.abs(baseDate.year - relativeDate.year)
} else {
if (!isSameYear && monthPackets === 0) {
yearPackets = Math.abs(baseDate.year - relativeDate.year)
} else {
yearPackets = Math.abs(baseDate.year - relativeDate.year) - 1
}
}
// This would need to be a reduce with an array of valid months appart like in the previous refactor ?
const remainingDays: number = const remainingDays: number =
Math.abs(differenceInDays) - (yearPackets * daysPerYear.value * monthPackets) Math.abs(differenceInDays) - (yearPackets * daysPerYear.value * monthPackets)
@@ -517,10 +526,10 @@ export const useCalendar = defineStore('calendar', () => {
// In the meantime : It's not really that much of a problem on larger scale to not compute days, honestly. // In the meantime : It's not really that much of a problem on larger scale to not compute days, honestly.
if (isSameMonth && isSameYear) { if (isSameMonth && isSameYear) {
if (remainingDays) { if (remainingDays) {
if (remainingDays === 1) { if (differenceInDays === 1) {
output += ` ${remainingDays} jour` output += ` ${differenceInDays} jour`
} else { } else {
output += ` ${remainingDays} jours` output += ` ${differenceInDays} jours`
} }
} }
@@ -529,26 +538,14 @@ export const useCalendar = defineStore('calendar', () => {
// Assign year part // Assign year part
if (yearPackets) { if (yearPackets) {
if (yearPackets === 1) { if (yearPackets <= 1 ) {
if (direction === 'future') { output += `${yearPackets} an`
return "L'année prochaine" } else {
} else { output += `${yearPackets} ans`
return "L'année dernière"
}
} }
output += `${yearPackets} ans`
} }
if (monthPackets) { if (monthPackets) {
if (monthPackets === 1) {
if (direction === 'future') {
return 'Le mois prochain'
} else {
return 'Le mois dernier'
}
}
if (yearPackets) { if (yearPackets) {
output += ' et ' output += ' et '
} }