diff --git a/src/__tests__/ecccDate.test.ts b/src/__tests__/ecccDate.test.ts index 53476e16..8c71ed40 100644 --- a/src/__tests__/ecccDate.test.ts +++ b/src/__tests__/ecccDate.test.ts @@ -21,6 +21,12 @@ describe("Helpers for ECCC dates", () => { expect(ecccDateStringToTSDate(ecccDateString)).toStrictEqual(expectedDate); }); + it("parses to a newfoundland date object correctly", () => { + const ecccDateString = "Sunday August 13, 2023 at 12:00"; + expect(ecccDateStringToTSDate(`${ecccDateString} AST`)).toStrictEqual(new Date(2023, 7, 13, 11, 0, 0)); + expect(ecccDateStringToTSDate(`${ecccDateString} NDT`)).toStrictEqual(new Date(2023, 7, 13, 10, 30, 0)); + }); + it("gets the correct months for the current season", () => { jest.useFakeTimers(); diff --git a/src/display/components/weather/conditions.tsx b/src/display/components/weather/conditions.tsx index bd551d18..74c06b8a 100644 --- a/src/display/components/weather/conditions.tsx +++ b/src/display/components/weather/conditions.tsx @@ -54,7 +54,7 @@ export function Conditions(props: ConditionsProp) { return CONDITIONS_WIND_SPEED_CALM; const speed = windSpeedValue ?? ""; - const direction = (windDirection ?? "N/A").padStart(3); + const direction = (windDirection ?? "").padStart(3); // gust is a different format (omits units) if (windGust) return `${direction} ${speed}G${windGust.value} `; diff --git a/src/lib/conditions/conditions.ts b/src/lib/conditions/conditions.ts index 567bd66a..38b47068 100644 --- a/src/lib/conditions/conditions.ts +++ b/src/lib/conditions/conditions.ts @@ -15,7 +15,7 @@ export function harshTruncateConditions( isUSForecast: boolean = false ) { // to lowercase - condition = condition.toLowerCase(); + condition = (condition ?? "").toLowerCase(); // handle thunderstorm when its prefaced with light/heavy if (condition.includes("light thunderstorm") || condition.includes("heavy thunderstorm")) diff --git a/src/lib/date/ecccDate.ts b/src/lib/date/ecccDate.ts index ebf438c8..07bb4bbb 100644 --- a/src/lib/date/ecccDate.ts +++ b/src/lib/date/ecccDate.ts @@ -2,7 +2,9 @@ import { format } from "date-fns"; import { getIsWinterSeason } from "./season"; export function ecccDateStringToTSDate(date: string) { - return new Date(date.replace(" at", "").replace(",", "")); + // JS doesn't see ATS/NDT (newfoundland time) as a valid date for some reason + const fixedTimezone = date.replace("AST", "GMT-0300").replace("NDT", "GMT-0230"); + return new Date(fixedTimezone.replace(" at", "").replace(",", "")); } export function getShorthandMonthNamesForSeason(stopAtCurrentMonth: boolean, date: Date = new Date()) { diff --git a/src/lib/eccc/conditions.ts b/src/lib/eccc/conditions.ts index f5a27be2..806ba8fa 100644 --- a/src/lib/eccc/conditions.ts +++ b/src/lib/eccc/conditions.ts @@ -199,7 +199,7 @@ class CurrentConditions { const offsetFromUTC = -localDate.getTimezoneOffset(); // get the number of minutes behind taht the station time is from utc - const stationOffsetFromUTC = parseInt(date.UTCOffset) * 60; + const stationOffsetFromUTC = parseFloat(date.UTCOffset) * 60; // now we can figure out the difference between these and use it on the ui // timezones dont really exist in js so it'll really just end up being the local time @@ -226,11 +226,15 @@ class CurrentConditions { wind: { speed: { value: windSpeedValue, units: windSpeedUnits }, gust: { value: windGustValue, units: windGustUnits }, - direction: { value: windDirectionValue }, + direction: windDirection, }, - visibility: { value: visibilityValue, units: visibilityUnits }, + visibility, } = conditions; + // handle wind direction and visibility potentially being null + const { value: windDirectionValue = null } = windDirection ?? {}; + const { value: visibilityValue = null, units: visibilityUnits = null } = visibility ?? {}; + // store it to our conditions this._conditions = { condition, diff --git a/src/types/eccc.types.ts b/src/types/eccc.types.ts index e54c84a3..71f5530a 100644 --- a/src/types/eccc.types.ts +++ b/src/types/eccc.types.ts @@ -1,8 +1,8 @@ export type ECCCConditions = { - condition: string; + condition: string | null; temperature: ECCCUnitString; pressure: ECCCPressure; - visibility: ECCCUnitString; + visibility: ECCCUnitString | null; relativeHumidity: ECCCUnitString; wind: ECCCWind; }; @@ -37,7 +37,7 @@ export type ECCCWindDirection = { export type ECCCWind = { speed: ECCCUnitString; gust: ECCCUnitString; - direction: ECCCWindDirection; + direction: ECCCWindDirection | null; }; export type ECCCSunRiseSet = {