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 // @ts-check
import { z } from 'zod'; 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")); const TimezoneSchema = z.enum(Intl.supportedValuesOf("timeZone"));
/** /**
* Specify your server-side environment variables schema here. * Specify your server-side environment variables schema here.
* This way you can ensure the app isn't built with invalid env vars. * This way you can ensure the app isn't built with invalid env vars.

View File

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