Skip to content

Commit

Permalink
fix: quote random
Browse files Browse the repository at this point in the history
  • Loading branch information
Valexr committed May 20, 2024
1 parent 2f8476f commit df2e1e8
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/lib/counters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { dates } from './dates';
import { quotes } from './quotes';
import { DateTime, Interval } from "luxon";

export const counters = derived<[Writable<StartDate[]>, Writable<Quote[]>], Counter[]>(([dates, quotes]),
([$dates, $quotes], set) => {
export const counters = derived<Writable<StartDate[]>, Counter[]>(dates, ($dates, set) => {

set($dates.map(({ start, title, quote }, id) => count(id, start, title, quote)))
set($dates.map(({ start, title }, id) => count(id, start, title)))

function count(id: number, start: string, title: string, quote: Quote) {
const { years, months, weeks, days, interval } = elapse(start)
return {
id, title, quote: quote || quotes.random(id), start: start,
years, months, days, weeks,
full: {
months: Math.trunc(interval.length('months')),
weeks: Math.trunc(interval.length('weeks')),
days: Math.trunc(interval.length('days')),
hours: Math.trunc(interval.length('hours')),
}
function count(id: number, start: string, title: string) {
const { years, months, weeks, days, interval } = elapse(start)
return {
id, title, start,
quote: quotes.random(id),
years, months, days, weeks,
full: {
months: Math.trunc(interval.length('months')),
weeks: Math.trunc(interval.length('weeks')),
days: Math.trunc(interval.length('days')),
hours: Math.trunc(interval.length('hours')),
}
}
}, [])
}
}, [])

function elapse(start: string) {
const TO = DateTime.now();
Expand Down

0 comments on commit df2e1e8

Please sign in to comment.