add TZ parsing
This commit is contained in:
parent
6e92407fc9
commit
06b35d5a2c
|
@ -1,7 +1,7 @@
|
||||||
import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, TextStyles } from '../../../deps.ts';
|
import { Bot, Interaction, InteractionResponseTypes, MessageComponentTypes, TextStyles } from '../../../deps.ts';
|
||||||
import { somethingWentWrong } from '../../commandUtils.ts';
|
import { somethingWentWrong } from '../../commandUtils.ts';
|
||||||
import { eventTimeId, eventTimeZoneId, eventDateId, eventDescriptionId } from './step1-gameSelection.ts';
|
import { eventTimeId, eventTimeZoneId, eventDateId, eventDescriptionId } from './step1-gameSelection.ts';
|
||||||
import { getFinalActivity, getNestedActivity, idSeparator, pathIdxSeparator } from './utils.ts';
|
import { getFinalActivity, tzMap, idSeparator, pathIdxSeparator } from './utils.ts';
|
||||||
import { Activities, Activity } from './activities.ts';
|
import { Activities, Activity } from './activities.ts';
|
||||||
|
|
||||||
export const customId = 'finalize';
|
export const customId = 'finalize';
|
||||||
|
@ -50,21 +50,21 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify/Set Time
|
// Verify/Set Time
|
||||||
let parsedEventTime = rawEventTime.replaceAll(':', '').toUpperCase();
|
let preParsedEventTime = rawEventTime.replaceAll(':', '').toUpperCase();
|
||||||
let parsedEventTimePeriod = '';
|
let parsedEventTimePeriod = '';
|
||||||
// Get AM or PM out of the rawTime
|
// Get AM or PM out of the rawTime
|
||||||
if (parsedEventTime.endsWith('AM') || parsedEventTime.endsWith('PM')) {
|
if (preParsedEventTime.endsWith('AM') || preParsedEventTime.endsWith('PM')) {
|
||||||
parsedEventTimePeriod = parsedEventTime.slice(-2);
|
parsedEventTimePeriod = preParsedEventTime.slice(-2);
|
||||||
parsedEventTime = parsedEventTime.slice(0, -2).trim();
|
preParsedEventTime = preParsedEventTime.slice(0, -2).trim();
|
||||||
}
|
}
|
||||||
let parsedEventTimeHours: string;
|
let parsedEventTimeHours: string;
|
||||||
let parsedEventTimeMinutes: string;
|
let parsedEventTimeMinutes: string;
|
||||||
// Get Hours and Minutes out of rawTime
|
// Get Hours and Minutes out of rawTime
|
||||||
if (parsedEventTime.length > 2) {
|
if (preParsedEventTime.length > 2) {
|
||||||
parsedEventTimeMinutes = parsedEventTime.slice(-2);
|
parsedEventTimeMinutes = preParsedEventTime.slice(-2);
|
||||||
parsedEventTimeHours = parsedEventTime.slice(0, -2).trim();
|
parsedEventTimeHours = preParsedEventTime.slice(0, -2).trim();
|
||||||
} else {
|
} else {
|
||||||
parsedEventTimeHours = parsedEventTime.trim();
|
parsedEventTimeHours = preParsedEventTime.trim();
|
||||||
parsedEventTimeMinutes = '00'
|
parsedEventTimeMinutes = '00'
|
||||||
}
|
}
|
||||||
// Determine if we need to remove the time period
|
// Determine if we need to remove the time period
|
||||||
|
@ -73,6 +73,22 @@ const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify/Set Time Zone
|
// Verify/Set Time Zone
|
||||||
|
let preParsedEventTimeZone = rawEventTimeZone.replaceAll(' ', '').trim().toUpperCase();
|
||||||
|
let parsedEventTimeZone = '';
|
||||||
|
if (tzMap.has(preParsedEventTimeZone)) {
|
||||||
|
parsedEventTimeZone = tzMap.get(preParsedEventTimeZone) || 'UTC+0';
|
||||||
|
} else {
|
||||||
|
let addPlusSign = false;
|
||||||
|
if (!preParsedEventTimeZone.includes('+') || !preParsedEventTimeZone.includes('-')) {
|
||||||
|
addPlusSign = true;
|
||||||
|
}
|
||||||
|
if (!preParsedEventTimeZone.startsWith('UTC') || preParsedEventTimeZone.startsWith('GMT')) {
|
||||||
|
preParsedEventTimeZone = `UTC${addPlusSign && '+'}${preParsedEventTimeZone}`;
|
||||||
|
} else if (addPlusSign) {
|
||||||
|
preParsedEventTimeZone = `${preParsedEventTimeZone.slice(0, 3)}+${preParsedEventTimeZone.slice(3)}`;
|
||||||
|
}
|
||||||
|
parsedEventTimeZone = preParsedEventTimeZone;
|
||||||
|
}
|
||||||
|
|
||||||
// Verify/Set Date
|
// Verify/Set Date
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue