Skip to content

Commit

Permalink
馃悰 Fix entries, summary key name
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 15, 2022
1 parent 69835b8 commit a9386cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Twitter,
Wakatime,
} from "./";
import { zero } from "./common";
import { sortObject, zero } from "./common";

const INTEGRATIONS = [
Clockify,
Expand Down Expand Up @@ -70,8 +70,8 @@ const cli = async () => {
for (const month of months) {
const file = join(".", "data", dir, "summary", "days", year, month);
const data = (await readJson(file)) as Record<string, any>;
Object.values(data).forEach(([day, value]) => {
summary[`${zero(year)}-${zero(month)}-${zero(day)}`] = value;
Object.entries(data).forEach(([day, value]) => {
summary[`${zero(year)}-${zero(month.replace(".json", ""))}-${zero(day)}`] = value;
});
}
}
Expand All @@ -80,7 +80,7 @@ const cli = async () => {
if (Object.keys(summary).length)
await writeFile(
join(".", "data", dir, "summary", "days.json"),
JSON.stringify(summary, null, 2) + "\n"
JSON.stringify(sortObject(summary), null, 2) + "\n"
);
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ export const write = async (name: string, contents: any) => {
};

export const zero = (num: string) => (parseInt(num) > 9 ? num : `0${num}`);

export const sortObject = <T>(o: Record<string, T>) =>
Object.keys(o)
.sort()
.reduce((r, k) => ((r[k] = o[k]), r), {} as Record<string, T>);

0 comments on commit a9386cb

Please sign in to comment.