Fixed compareDate function for flexible months

This breaks the year layout, but it's 100% caused by the props of the screen, it's not caused by the date comparison
This commit is contained in:
Alexis
2024-05-20 12:07:13 +02:00
parent ce2dbbc8a4
commit 784b5cf421
2 changed files with 10 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ const { defaultDate, getFormattedDateTitle, getRelativeString } = useCalendar()
const { selectedDate } = storeToRefs(useCalendar()) const { selectedDate } = storeToRefs(useCalendar())
const mainDateTitle = computed(() => getFormattedDateTitle(selectedDate.value, true)) const mainDateTitle = computed(() => getFormattedDateTitle(selectedDate.value, true))
// const mainDateTitle = computed(() => convertDateToDays(selectedDate.value))
const dateDifference = computed(() => getRelativeString(defaultDate, selectedDate.value)) const dateDifference = computed(() => getRelativeString(defaultDate, selectedDate.value))
</script> </script>

View File

@@ -384,20 +384,23 @@ export const useCalendar = defineStore('calendar', () => {
/** /**
* Converts a RPGDate to its equivalent in days * Converts a RPGDate to its equivalent in days
* *
* @todo Handle negative dates
* @param dateToConvert The date object * @param dateToConvert The date object
* @returns How many days does it represent * @returns How many days does it represent
*/ */
function convertDateToDays(dateToConvert: RPGDate): number { function convertDateToDays(dateToConvert: RPGDate): number {
// To modify, obviously
const daysPerMonth = 32
let numberOfDays: number = dateToConvert.day let numberOfDays: number = dateToConvert.day
numberOfDays = numberOfDays + dateToConvert.month * daysPerMonth // Get only the remaining months on the year
const validMonths = sortedMonths.value.filter((m) => dateToConvert.month >= m.position)
// From remaining months, reduce their days value
const monthDaysToAdd = validMonths.reduce((a, b) => {
return a + b.days
}, 0)
numberOfDays = numberOfDays + monthDaysToAdd
numberOfDays = numberOfDays + dateToConvert.year * daysPerYear.value numberOfDays = numberOfDays + dateToConvert.year * daysPerYear.value
return numberOfDays return numberOfDays - 1
} }
/** /**