Skip to content

Commit

Permalink
normalize my dates
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesTaylor7 committed Aug 9, 2023
1 parent f7cd062 commit 89a4011
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/weather-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class WeatherDashboard {
return this.cities.map((city) => ({
name: city.label,
data: city.data
.map((d) => ({ x: d.datetime, y: d.temperature }))
.map((d) => ({ x: normalizeDate(d.datetime), y: d.temperature }))
.slice(0, this.forecastDays),
}));
}
Expand Down Expand Up @@ -88,6 +88,12 @@ export default class WeatherDashboard {
});
}
}
// truncates the datetimes to just a date, so it's easy to compare cities in different timezones
export function normalizeDate(datetime: Date) {
const month = datetime.getMonth() + 1
const day = datetime.getDate()
return new Date(`${datetime.getFullYear()}-${month}-${day}`);
}

export function formatDate(datetime: Date) {
const month = String(datetime.getMonth() + 1).padStart(2, '0');
Expand Down

0 comments on commit 89a4011

Please sign in to comment.