first exploration of place of feature and how to access data

This commit is contained in:
tina
2024-10-15 14:47:42 +02:00
parent d492a27797
commit fd6f39fbc4
4 changed files with 138 additions and 1 deletions
+44
View File
@@ -0,0 +1,44 @@
import * as joda from '@js-joda/core'
const LocalDate = joda.LocalDate
// const DAYS = joda.ChronoUnit.DAYS
export default function config(opts) {
let cycleStartsSortedByDate
if (!opts) {
// we only want to require (and run) the db module
// when not running the tests
cycleStartsSortedByDate = require('../db').getCycleStartsSortedByDate()
// maxCycleLength = 45
} else {
cycleStartsSortedByDate = opts.cycleStartsSortedByDate || []
// maxCycleLength = opts.maxCycleLength || 99
}
function getCycleStartsOfLastYear() {
const today = LocalDate.parse(new Date().toISOString().slice(0, 10))
const firstRelevantCycleStart = today.minusYears(1)
const relevantCycles = cycleStartsSortedByDate.filter(({ date }) =>
LocalDate.parse(date).isAfter(firstRelevantCycleStart)
)
return relevantCycles.map(({ date }) => date)
}
function getTodayDate() {
return new Date().toISOString().slice(0, 10)
}
const getStats = () =>
cycleStartsSortedByDate.map((day, i) => {
const today = getTodayDate()
return {
date: today,
k: i,
}
})
return {
getCycleStartsOfLastYear,
getStats,
}
}