Skip to content

Commit

Permalink
feat: add trash utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ematala committed Apr 27, 2023
1 parent 3307e27 commit 10e49ea
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { trash } from "./data";
import { closestTo, format } from "date-fns";

const trashMap: Record<number, string> = {
0: "Papiertonne",
1: "Restabfalltonne",
2: "Biotonne",
3: "Wertstofftonne",
4: "Sperrgut, Grünabfall",
};

const parseDate = (date: string) => {
const [year, month, day] = date.split("-").map(Number);
return new Date(year, month - 1, day);
};

export const getTrash = () => {
const dates = Object.keys(trash)
.map(parseDate)
.filter((d) => d > new Date());
const closest = closestTo(new Date(), dates);
if (!closest) return [];
const date = format(closest, "yyyy-MM-dd");
return trash[date].map((t) => trashMap[t]);
};

0 comments on commit 10e49ea

Please sign in to comment.