diff --git a/apps/cli/package.json b/apps/cli/package.json index 9ea7840..10540ff 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -23,7 +23,9 @@ "@lifetracker/trpc": "workspace:^", "date-fns": "^4.1.0", "dotenv": "^16.4.1", + "spacetime": "^7.6.2", "table": "^6.8.2", + "timezone-soft": "^1.5.2", "vite-tsconfig-paths": "^5.1.0" }, "devDependencies": { diff --git a/apps/cli/src/commands/days.ts b/apps/cli/src/commands/days.ts index 1545900..6489fba 100644 --- a/apps/cli/src/commands/days.ts +++ b/apps/cli/src/commands/days.ts @@ -12,6 +12,11 @@ import { format } from "date-fns"; import { TZDate } from "@date-fns/tz"; import { utc } from "@date-fns/utc"; import { getHourFromTime, getTimeFromHour } from "@lifetracker/shared/utils/hours"; +import { timezones } from "@lifetracker/shared/utils/timezones"; +import { hours } from "@lifetracker/db/schema"; +import { doHour } from "./hours"; +import soft from "timezone-soft"; +import spacetime from "spacetime"; function moodToStars(mood: number) { // const full_stars = Math.floor(mood / 2); @@ -20,51 +25,84 @@ function moodToStars(mood: number) { return "★".repeat(mood) + "☆".repeat(10 - mood); } +function getTimezone(req: string) { + try { + const tz = soft(req)[0].iana; + if (timezones[tz] === undefined) { + throw new Error("Valid timezone, but not supported by Lifetracker. Add it to the timezones list in the shared utils or try a different request."); + } + return tz; + } catch (e) { + throw new Error("Invalid timezone..." + e); + } + +} + export const daysCmd = new Command() .name("day") .description("Get data for a specific day") - .argument('', 'A date in ISO-8601 format, or "yesterday", "today", "tomorrow", etc.') + .argument('[date]', 'A date in ISO-8601 format, or "yesterday", "today", "tomorrow", etc.', "today") .option('-c, --comment ', "edit this day's comment") .option('-m, --mood ', "edit this day's mood") - .action(async (dateQuery: string, flags?) => { + .option('-h, --hour ', "manipulate a specific hour (