mirror of
https://github.com/Xevion/bus-reminder.git
synced 2026-01-31 08:23:39 -06:00
Setup Timezone specification support
This commit is contained in:
Vendored
+3
-1
@@ -1,6 +1,7 @@
|
||||
// @ts-check
|
||||
import { z } from 'zod';
|
||||
|
||||
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.
|
||||
@@ -18,5 +19,6 @@ export const serverSchema = z.object({
|
||||
EDGE_CACHE_TIME_SECONDS: z.coerce.number().int().nonnegative().default(60),
|
||||
REDIS_URL: z.string().url(),
|
||||
DISCORD_TOKEN: z.string(),
|
||||
DISCORD_TARGET_USER_ID: z.string()
|
||||
DISCORD_TARGET_USER_ID: z.string(),
|
||||
TIMEZONE: TimezoneSchema
|
||||
});
|
||||
|
||||
Vendored
+2
-1
@@ -19,7 +19,8 @@ const _serverEnv = serverSchema.safeParse({
|
||||
EDGE_CACHE_TIME_SECONDS: process.env.EDGE_CACHE_TIME_SECONDS,
|
||||
REDIS_URL: process.env.REDIS_URL,
|
||||
DISCORD_TOKEN: process.env.DISCORD_TOKEN,
|
||||
DISCORD_TARGET_USER_ID: process.env.DISCORD_TARGET_USER_ID
|
||||
DISCORD_TARGET_USER_ID: process.env.DISCORD_TARGET_USER_ID,
|
||||
TIMEZONE: process.env.TIMEZONE
|
||||
});
|
||||
|
||||
if (_serverEnv.success === false) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { env } from "@/env/server.mjs";
|
||||
type ResponseData = {
|
||||
now: number;
|
||||
status: string;
|
||||
timezone: string;
|
||||
};
|
||||
|
||||
export default async function handler(
|
||||
@@ -14,5 +15,6 @@ export default async function handler(
|
||||
res.status(200).json({
|
||||
now: new Date().getTime(),
|
||||
status: req.query.key == env.API_KEY ? "Authorized" : "Unauthorized",
|
||||
timezone: env.TIMEZONE
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
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'));
|
||||
export type Timezone = z.infer<typeof TimezoneSchema>;
|
||||
|
||||
export function localNow(now?: Date, zone?: Timezone): Date {
|
||||
zone = zone ?? env.TIMEZONE;
|
||||
now = now ?? new Date();
|
||||
return utcToZonedTime(now, zone);
|
||||
}
|
||||
Reference in New Issue
Block a user