From d77f0752a5e41d3bd64b3bdcda334e1c51877584 Mon Sep 17 00:00:00 2001 From: Bashu Naimi-Roy Date: Tue, 26 Nov 2024 18:11:40 -0500 Subject: [PATCH] fix(datetime)!: get day of week key without using locale note that this removes the "locale" parameter from the param signature of several methods: * helpers.datetime.getDayOfWeekKey * helpers.location.getNextOpenIntervalAfterToday * helpers.location.getOpenIntervalsForToday --- src/helpers/datetime.ts | 8 +++---- src/helpers/location.ts | 13 +++-------- test/helpers.location.test.ts | 1 - typedocs/classes/helpers_location.Location.md | 22 +++++++++---------- typedocs/modules/helpers_datetime.md | 6 ++--- 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/helpers/datetime.ts b/src/helpers/datetime.ts index c25f600..54c15b3 100644 --- a/src/helpers/datetime.ts +++ b/src/helpers/datetime.ts @@ -56,15 +56,15 @@ export const localizeDate = (dateObj: Date, locale: string, format: localizeDate /** * Gets the appropriate 3 letter key for the day of the week for a given date object - * used to find the correct key of the hour data to pull data off of + * used to find the correct key of the hour data to pull data off of. + * We localize using the `en-US` locale, because the date keys are in that locale. * * @param {Date} dateObj - * @param {locale} string - Hyphenized language/country locale combo, e.g. en-US (BCP 47). * @param {String} timezone * @return {DayOfWeek} */ -export const getDayOfWeekKey = (dateObj: Date, locale: string, timezone: string): DayOfWeek => { - const dayOfWeek = localizeDate(dateObj, locale, DateFormats.weekdayShort, timezone); +export const getDayOfWeekKey = (dateObj: Date, timezone: string): DayOfWeek => { + const dayOfWeek = localizeDate(dateObj, 'en-US', DateFormats.weekdayShort, timezone); return dayOfWeek.toUpperCase() as DayOfWeek; }; diff --git a/src/helpers/location.ts b/src/helpers/location.ts index 2fe724d..378c8b4 100644 --- a/src/helpers/location.ts +++ b/src/helpers/location.ts @@ -118,7 +118,7 @@ export class Location { }; } - const nextOpenIntervalAfterToday = this.getNextOpenIntervalAfterToday(locale, timezone, hours); + const nextOpenIntervalAfterToday = this.getNextOpenIntervalAfterToday(timezone, hours); if (nextOpenIntervalAfterToday) { const { date, interval: nextInterval } = nextOpenIntervalAfterToday; const opensAt = getFormattedTime(date, nextInterval.open, DateFormats.hourNminuteN, locale, timezone, tzOffsetString); @@ -173,7 +173,6 @@ export class Location { nextDateObj.setDate(nextDateObj.getDate() + 1); const dayOfWeekKey = getDayOfWeekKey( nextDateObj, - locale, timezone, ); @@ -217,19 +216,16 @@ export class Location { /** * Gets open intervals for today * - * @param {string} locale - Hyphenized language/country locale combo, e.g. en-US (BCP 47). * @param {string} timezone * @param {Hours} hours * @return {OpenInterval[]} */ getOpenIntervalsForToday( - locale: string, timezone: string, hours: Hours ): OpenInterval[] { const dayOfWeekKey: DayOfWeek = getDayOfWeekKey( new Date(), - locale, timezone ); return hours[dayOfWeekKey]; @@ -248,7 +244,7 @@ export class Location { timezone: string, hours: Hours ): OpenInterval | null { - const todayOpenIntervals = this.getOpenIntervalsForToday(locale, timezone, hours); + const todayOpenIntervals = this.getOpenIntervalsForToday(timezone, hours); if (!todayOpenIntervals.length) { return null; } @@ -282,7 +278,7 @@ export class Location { timezone: string, hours: Hours ): OpenInterval | null { - const todayOpenIntervals = this.getOpenIntervalsForToday(locale, timezone, hours); + const todayOpenIntervals = this.getOpenIntervalsForToday(timezone, hours); if (!todayOpenIntervals.length) { return null; } @@ -311,13 +307,11 @@ export class Location { /** * Get the next opening period after today within the next seven days * - * @param {string} locale - Hyphenized language/country locale combo, e.g. en-US (BCP 47). * @param {string} timezone * @param {Hours} hours * @return {Object | null} { open: openTime, close: closeTime } */ getNextOpenIntervalAfterToday( - locale: string, timezone: string, hours: Hours, ): { @@ -331,7 +325,6 @@ export class Location { nextDateObj.setDate(nextDateObj.getDate() + 1); const dayOfWeekKey = getDayOfWeekKey( nextDateObj, - locale, timezone, ); diff --git a/test/helpers.location.test.ts b/test/helpers.location.test.ts index 6e26956..7c48888 100644 --- a/test/helpers.location.test.ts +++ b/test/helpers.location.test.ts @@ -982,7 +982,6 @@ describe('Check open intervals for today', () => { vi.setSystemTime(date); const result = sdk.helpers.location.getOpenIntervalsForToday( - 'en-US', 'UTC', location['PICKUP'].hours ); diff --git a/typedocs/classes/helpers_location.Location.md b/typedocs/classes/helpers_location.Location.md index 043d4c9..27219ce 100644 --- a/typedocs/classes/helpers_location.Location.md +++ b/typedocs/classes/helpers_location.Location.md @@ -123,17 +123,16 @@ ___ ### getOpenIntervalsForToday -▸ **getOpenIntervalsForToday**(`locale`, `timezone`, `hours`): [`OpenInterval`](../interfaces/types_helpers_location.OpenInterval.md)[] +▸ **getOpenIntervalsForToday**(`timezone`, `hours`): [`OpenInterval`](../interfaces/types_helpers_location.OpenInterval.md)[] Gets open intervals for today #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `locale` | `string` | Hyphenized language/country locale combo, e.g. en-US (BCP 47). | -| `timezone` | `string` | | -| `hours` | [`Hours`](../interfaces/types_helpers_location.Hours.md) | | +| Name | Type | +| :------ | :------ | +| `timezone` | `string` | +| `hours` | [`Hours`](../interfaces/types_helpers_location.Hours.md) | #### Returns @@ -184,17 +183,16 @@ ___ ### getNextOpenIntervalAfterToday -▸ **getNextOpenIntervalAfterToday**(`locale`, `timezone`, `hours`): ``null`` \| { `date`: `Date` ; `interval`: [`OpenInterval`](../interfaces/types_helpers_location.OpenInterval.md) } +▸ **getNextOpenIntervalAfterToday**(`timezone`, `hours`): ``null`` \| { `date`: `Date` ; `interval`: [`OpenInterval`](../interfaces/types_helpers_location.OpenInterval.md) } Get the next opening period after today within the next seven days #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `locale` | `string` | Hyphenized language/country locale combo, e.g. en-US (BCP 47). | -| `timezone` | `string` | | -| `hours` | [`Hours`](../interfaces/types_helpers_location.Hours.md) | | +| Name | Type | +| :------ | :------ | +| `timezone` | `string` | +| `hours` | [`Hours`](../interfaces/types_helpers_location.Hours.md) | #### Returns diff --git a/typedocs/modules/helpers_datetime.md b/typedocs/modules/helpers_datetime.md index 4b1cd34..01f8a64 100644 --- a/typedocs/modules/helpers_datetime.md +++ b/typedocs/modules/helpers_datetime.md @@ -82,17 +82,17 @@ ___ ### getDayOfWeekKey -▸ **getDayOfWeekKey**(`dateObj`, `locale`, `timezone`): [`DayOfWeek`](types_helpers_datetime.md#dayofweek) +▸ **getDayOfWeekKey**(`dateObj`, `timezone`): [`DayOfWeek`](types_helpers_datetime.md#dayofweek) Gets the appropriate 3 letter key for the day of the week for a given date object -used to find the correct key of the hour data to pull data off of +used to find the correct key of the hour data to pull data off of. +We localize using the `en-US` locale, because the date keys are in that locale. #### Parameters | Name | Type | | :------ | :------ | | `dateObj` | `Date` | -| `locale` | `string` | | `timezone` | `string` | #### Returns