Add DST notice to TZ entry
This commit is contained in:
parent
a6848eb33a
commit
7c999ed27b
|
@ -84,14 +84,20 @@ const parseEventTime = (preParsedEventTime: string): [string, string, string] =>
|
||||||
return [parsedEventTimeHours, parsedEventTimeMinutes, parsedEventTimePeriod];
|
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
|
// Takes user input Time Zone and makes it actually usable
|
||||||
const parseEventTimeZone = (preParsedEventTimeZone: string): [string, string] => {
|
const parseEventTimeZone = (preParsedEventTimeZone: string): [string, string] => {
|
||||||
if (shorthandUSTZ.includes(preParsedEventTimeZone)) {
|
if (shorthandUSTZ.includes(preParsedEventTimeZone)) {
|
||||||
// Handle shorthand US timezones, adding S for standard time and D for Daylight Savings
|
// Handle shorthand US timezones, adding S for standard time and D for Daylight Savings
|
||||||
const today = new Date();
|
if (isDSTActive()) {
|
||||||
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())) {
|
|
||||||
preParsedEventTimeZone = `${preParsedEventTimeZone.slice(0, 1)}DT`;
|
preParsedEventTimeZone = `${preParsedEventTimeZone.slice(0, 1)}DT`;
|
||||||
} else {
|
} else {
|
||||||
preParsedEventTimeZone = `${preParsedEventTimeZone.slice(0, 1)}ST`;
|
preParsedEventTimeZone = `${preParsedEventTimeZone.slice(0, 1)}ST`;
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { idSeparator, LfgEmbedIndexes, lfgStartTimeName } from '../eventUtils.ts
|
||||||
import utils from '../../utils.ts';
|
import utils from '../../utils.ts';
|
||||||
import { customId as createCustomActivityBtnId } from './step1a-openCustomModal.ts';
|
import { customId as createCustomActivityBtnId } from './step1a-openCustomModal.ts';
|
||||||
import { customId as finalizeEventBtnId } from './step2-finalize.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';
|
import { dbClient, queries } from '../../db.ts';
|
||||||
|
|
||||||
export const customId = 'gameSel';
|
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();
|
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, {
|
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||||
type: InteractionResponseTypes.Modal,
|
type: InteractionResponseTypes.Modal,
|
||||||
data: {
|
data: {
|
||||||
|
@ -86,7 +89,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
components: [{
|
components: [{
|
||||||
type: MessageComponentTypes.InputText,
|
type: MessageComponentTypes.InputText,
|
||||||
customId: eventTimeZoneId,
|
customId: eventTimeZoneId,
|
||||||
label: 'Time Zone:',
|
label: `Time Zone: ${dstNotice}`,
|
||||||
placeholder: 'Enter your time zone abbreviation (UTC±## also works)',
|
placeholder: 'Enter your time zone abbreviation (UTC±## also works)',
|
||||||
style: TextStyles.Short,
|
style: TextStyles.Short,
|
||||||
minLength: 2,
|
minLength: 2,
|
||||||
|
|
Loading…
Reference in New Issue