refactor to ES modules

This commit is contained in:
2023-12-02 13:27:37 +01:00
parent 1137d26cd6
commit 308baf0b16
8 changed files with 206 additions and 139 deletions
+44
View File
@@ -0,0 +1,44 @@
import Data from './data.js'
import Day from './day.js'
import Transform from './transform.js'
export default class Championship {
static last = null
static get next() {
let remainingOffset = 0
let day = Day.today
let time = Championship.nextTime
if (time == null) {
remainingOffset += 1440
day = Day.tomorrow
time = Championship.firstTimeNextDay
}
return {
day: day,
time: time,
location: Data.championships[day][time],
remaining: (remainingOffset + time) - Day.minutesPassedSinceMidnight,
}
}
static firstTimeOnDay(day) {
return Math.min(...Object.keys(Data.championships[day]))
}
static get nextTime() {
let nextTimes = Transform.dropChampionshipsBefore(Data.championshipsToday, Day.minutesPassedSinceMidnight)
if (nextTimes.length < 1) {
return null
}
return Math.min(...nextTimes)
}
static get firstTimeTomorrow() {
return Championship.firstTimeOnDay(Day.tomorrow)
}
}