MCPcopy Create free account
hub / github.com/dailydotdev/apps / parsePatchyDay

Function parsePatchyDay

packages/shared/src/features/patchy/patchyDay.ts:34–53  ·  view source on GitHub ↗
(raw: string | null, now: Date)

Source from the content-addressed store, hash-verified

32
33// Anything stored for another day, or broken, starts a fresh day.
34export const parsePatchyDay = (raw: string | null, now: Date): PatchyDay => {
35 const fresh = createPatchyDay(now);
36 if (!raw) {
37 return fresh;
38 }
39 try {
40 const stored = JSON.parse(raw) as Partial<PatchyDay>;
41 if (!stored || stored.day !== fresh.day) {
42 return fresh;
43 }
44 return {
45 day: fresh.day,
46 reads: isCount(stored.reads) ? stored.reads : 0,
47 upvotes: isCount(stored.upvotes) ? stored.upvotes : 0,
48 bookmarks: isCount(stored.bookmarks) ? stored.bookmarks : 0,
49 };
50 } catch {
51 return fresh;
52 }
53};
54
55const counterFor: Partial<
56 Record<

Callers 2

patchyDay.spec.tsFile · 0.90
readPatchyDayFunction · 0.85

Calls 2

createPatchyDayFunction · 0.85
isCountFunction · 0.70

Tested by

no test coverage detected