Added default date config in calendar data

This commit is contained in:
Alexis
2024-05-18 18:01:49 +02:00
parent 3de59116aa
commit 73e4b0e3d7
7 changed files with 58 additions and 33 deletions

View File

@@ -1,12 +1,15 @@
import type { CalendarEvent } from "./CalendarEvent"
import type { CalendarMonth } from "./CalendarMonth"
import type { RPGDate } from "./Date"
export interface CalendarConfig {
months: CalendarMonth[]
daysPerMonth: number
today: RPGDate
}
export interface Calendar extends CalendarConfig {
id: number
name: string
events: CalendarEvent[]
}

View File

@@ -2,11 +2,8 @@ export interface RPGDate {
day: number
month: number
year: number
period?: RPGPeriod
}
export type RPGPeriod = 'ante' | 'nante'
export type RPGPeriodShort = 'A.R' | 'N.R'
export type RPGDateOrder = 'asc' | 'desc'
export const monthsPerYear: number = 10
@@ -36,12 +33,6 @@ export function compareDates(a: RPGDate, b: RPGDate, order: RPGDateOrder = 'desc
// Reverses the order if specified
const orderFactor: number = order === 'desc' ? 1 : -1
// Compare eras
if ((a.period === 'ante' && b.period === 'nante') || (a.year < 0 && b.year >= 0))
return -1 * orderFactor
if ((a.period === 'nante' && b.period === 'ante') || (a.year >= 0 && b.year < 0))
return 1 * orderFactor
// Compare years
if (a.year < b.year) return -1 * orderFactor
if (a.year > b.year) return 1 * orderFactor