Skip to content

Commit

Permalink
refactor(forecast): snow amount truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
Forceh91 committed Oct 25, 2023
1 parent 20c96d4 commit 87803b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/__tests__/abbreviateForecast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ describe("forecast truncation", () => {
expect(abbreviateForecast("amount 5 - 10 mm", forecastLengthWanted)).toStrictEqual("amount 5-10mm");
expect(abbreviateForecast("local amount 5 - 10 mm", forecastLengthWanted)).toStrictEqual("local amount 5-10mm");
expect(abbreviateForecast("amount 15 - 30 mm", forecastLengthWanted)).toStrictEqual("amount 15-30mm");
expect(abbreviateForecast("amount 5 - 10 cm", forecastLengthWanted)).toStrictEqual("amount 5-10cm");
expect(abbreviateForecast("local amount 5 - 10 cm", forecastLengthWanted)).toStrictEqual("local amount 5-10cm");
expect(abbreviateForecast("amount 15 - 30 cm", forecastLengthWanted)).toStrictEqual("amount 15-30cm");
expect(abbreviateForecast("midnight", forecastLengthWanted)).toStrictEqual("12am");
expect(abbreviateForecast("temperature steady", forecastLengthWanted)).toStrictEqual("temp steady");
expect(
Expand Down
4 changes: 4 additions & 0 deletions src/lib/conditions/forecast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export function abbreviateForecast(
abbreviatedSummary = abbreviatedSummary.replace(/amount (\d+) - (\d+) mm/gi, "amount $1-$2mm");
if (abbreviatedSummary.length <= maxCharacters) return abbreviatedSummary;

// squish up the snowfall amount predicitons
abbreviatedSummary = abbreviatedSummary.replace(/amount (\d+) - (\d+) cm/gi, "amount $1-$2cm");
if (abbreviatedSummary.length <= maxCharacters) return abbreviatedSummary;

// temperature steady
abbreviatedSummary = abbreviatedSummary.replace(/temperature/gi, "temp");
if (abbreviatedSummary.length <= maxCharacters) return abbreviatedSummary;
Expand Down

0 comments on commit 87803b1

Please sign in to comment.