From 7c999ed27b7c3a604d664b26fe3f2837dd8f50e5 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Tue, 11 Apr 2023 20:22:18 -0400 Subject: [PATCH] Add DST notice to TZ entry --- src/buttons/event-creation/dateTimeUtils.ts | 14 ++++++++++---- src/buttons/event-creation/step1-gameSelection.ts | 7 +++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/buttons/event-creation/dateTimeUtils.ts b/src/buttons/event-creation/dateTimeUtils.ts index 7a7eba9..b409f66 100644 --- a/src/buttons/event-creation/dateTimeUtils.ts +++ b/src/buttons/event-creation/dateTimeUtils.ts @@ -84,14 +84,20 @@ const parseEventTime = (preParsedEventTime: string): [string, string, string] => return [parsedEventTimeHours, parsedEventTimeMinutes, parsedEventTimePeriod]; }; +// Check if DST is currently active +export const isDSTActive = (): boolean => { + const today = new Date(); + const jan = new Date(today.getFullYear(), 0, 1); + const jul = new Date(today.getFullYear(), 6, 1); + + return today.getTimezoneOffset() < Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()); +}; + // Takes user input Time Zone and makes it actually usable const parseEventTimeZone = (preParsedEventTimeZone: string): [string, string] => { if (shorthandUSTZ.includes(preParsedEventTimeZone)) { // Handle shorthand US timezones, adding S for standard time and D for Daylight Savings - const today = new Date(); - const jan = new Date(today.getFullYear(), 0, 1); - const jul = new Date(today.getFullYear(), 6, 1); - if (today.getTimezoneOffset() < Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset())) { + if (isDSTActive()) { preParsedEventTimeZone = `${preParsedEventTimeZone.slice(0, 1)}DT`; } else { preParsedEventTimeZone = `${preParsedEventTimeZone.slice(0, 1)}ST`; diff --git a/src/buttons/event-creation/step1-gameSelection.ts b/src/buttons/event-creation/step1-gameSelection.ts index d22f6c5..1978f29 100644 --- a/src/buttons/event-creation/step1-gameSelection.ts +++ b/src/buttons/event-creation/step1-gameSelection.ts @@ -7,7 +7,7 @@ import { idSeparator, LfgEmbedIndexes, lfgStartTimeName } from '../eventUtils.ts import utils from '../../utils.ts'; import { customId as createCustomActivityBtnId } from './step1a-openCustomModal.ts'; import { customId as finalizeEventBtnId } from './step2-finalize.ts'; -import { monthsShort } from './dateTimeUtils.ts'; +import { isDSTActive, monthsShort } from './dateTimeUtils.ts'; import { dbClient, queries } from '../../db.ts'; export const customId = 'gameSel'; @@ -64,6 +64,9 @@ const execute = async (bot: Bot, interaction: Interaction) => { prefillDescription = interaction.message.embeds[0].fields[LfgEmbedIndexes.Description].value.trim(); } + // DST notice to try to get people to use the right TZ + const dstNotice = isDSTActive() ? '(Note: DST is in effect in NA)' : ''; + bot.helpers.sendInteractionResponse(interaction.id, interaction.token, { type: InteractionResponseTypes.Modal, data: { @@ -86,7 +89,7 @@ const execute = async (bot: Bot, interaction: Interaction) => { components: [{ type: MessageComponentTypes.InputText, customId: eventTimeZoneId, - label: 'Time Zone:', + label: `Time Zone: ${dstNotice}`, placeholder: 'Enter your time zone abbreviation (UTC±## also works)', style: TextStyles.Short, minLength: 2,