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.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) => { frame.from.setMonth(frame.from.getMonth() + 1); frame.to.setMonth(frame.to.getMonth() + 1); return frame; }); }, prev: () => { update((frame: ScrollingTimeframe) => { frame.from.setMonth(frame.from.getMonth() - 1); frame.to.setMonth(frame.to.getMonth() - 1); return frame; }); }, }; } export const scrollingTimeFrameStore = await createStore();