Correct details surrounding Intl.supportedValuesOf, improve comments/solve TODO

This commit is contained in:
2023-09-03 20:26:42 -05:00
parent 47659831a9
commit dbe531bcd2
3 changed files with 8 additions and 4 deletions

3
src/env/schema.mjs vendored
View File

@@ -1,8 +1,9 @@
// @ts-check
import { z } from 'zod';
// @ts-ignore
// If this line fails, you're not running Node v18 or higher. Please upgrade.
const TimezoneSchema = z.enum(Intl.supportedValuesOf("timeZone"));
/**
* Specify your server-side environment variables schema here.
* This way you can ensure the app isn't built with invalid env vars.

View File

@@ -56,7 +56,7 @@ export function distance(
export async function getDistance(): Promise<number> {
let client;
try {
// Setup the Life360 API client
// Set up the Life360 API client
client = await life360.login(env.LIFE360_USERNAME, env.LIFE360_PASSWORD);
} catch (e) {
throw new Error(

View File

@@ -2,8 +2,11 @@ import { utcToZonedTime } from 'date-fns-tz';
import { z } from 'zod';
import { env } from '@/env/server.mjs';
// @ts-ignore TS2339 -- TODO: Figure out why Intl.supportedValuesOf isn't seen by Typescript
export const TimezoneSchema = z.enum(Intl.supportedValuesOf('timeZone'));
// If this line fails in Typescript, then install typescript@^5.1.3
export const TimezoneSchema = z.enum(
// 'as' to assume at least one element
Intl.supportedValuesOf('timeZone') as [string, ...string[]]
);
export type Timezone = z.infer<typeof TimezoneSchema>;
export function localNow(now?: Date, zone?: Timezone): Date {