import { type ScrollingTimeframe } from "$lib/types"; import { type Writable, writable } from "svelte/store"; async function createStore(): Promise & { next: Function; prev: Function }> { const thism = new Date(); const lastm = new Date(); thism.setDate(1); lastm.setDate(1); thism.setMonth(thism.getMonth() - 1); lastm.setMonth(lastm.getMonth() - 2); const { subscribe, update, set } = writable({ from: lastm, to: thism }); return { subscribe, update, set, next: () => { update((frame: ScrollingTimeframe) => { const newFrom = new Date(frame.from); const newTo = new Date(frame.to); newFrom.setMonth(newFrom.getMonth() + 1); newTo.setMonth(newTo.getMonth() + 1); return { from: newFrom, to: newTo }; }); }, prev: () => { update((frame: ScrollingTimeframe) => { const newFrom = new Date(frame.from); const newTo = new Date(frame.to); newFrom.setMonth(newFrom.getMonth() - 1); newTo.setMonth(newTo.getMonth() - 1); return { from: newFrom, to: newTo }; }); }, }; } export const scrollingTimeFrameStore = await createStore();