Skip to content

Commit

Permalink
fix: various issues found in newfoundland stations (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
Forceh91 authored Jul 2, 2024
1 parent 1038c98 commit b7f6029
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/__tests__/ecccDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/display/components/weather/conditions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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} `;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/conditions/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 3 additions & 1 deletion src/lib/date/ecccDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
10 changes: 7 additions & 3 deletions src/lib/eccc/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/types/eccc.types.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Expand Down Expand Up @@ -37,7 +37,7 @@ export type ECCCWindDirection = {
export type ECCCWind = {
speed: ECCCUnitString;
gust: ECCCUnitString;
direction: ECCCWindDirection;
direction: ECCCWindDirection | null;
};

export type ECCCSunRiseSet = {
Expand Down

0 comments on commit b7f6029

Please sign in to comment.