Skip to content

Commit

Permalink
Render multi-day storm schedule dates correctly
Browse files Browse the repository at this point in the history
It's possible for a storm schedule to span several days; however, to
this point, we were implicitly assuming that all storm schedules are one
day long and only showing the start date. Corrected for storm schedules
that span multiple days.
  • Loading branch information
phildarnowsky committed Jan 30, 2020
1 parent f40ed0b commit 9e39a0b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
12 changes: 10 additions & 2 deletions apps/site/assets/ts/helpers/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const groupByType = (
return { ...acc, [currentServiceType]: updatedGroup };
};

const startToEnd = (startDateObject: Date, endDateObject: Date): string =>
`${formattedDate(startDateObject)} to ${formattedDate(endDateObject)}`;

export const groupServiceByDate = (
service: ServiceWithServiceDate,
ratingEndDate: string
Expand Down Expand Up @@ -81,10 +84,15 @@ export const groupServiceByDate = (
? "current"
: "future";

const stormServicePeriod =
startDate === endDate
? formattedDate(startDateObject)
: startToEnd(startDateObject, endDateObject);

return [
{
type,
servicePeriod: formattedDate(new Date(startDateObject)),
servicePeriod: stormServicePeriod,
service
}
];
Expand Down Expand Up @@ -133,7 +141,7 @@ export const serviceDate = (
return `starts ${formattedDate(startDateObject)}`;
}
}
return `${formattedDate(startDateObject)} to ${formattedDate(endDateObject)}`;
return startToEnd(startDateObject, endDateObject);
};

type MonthInteger = number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
Expand Down
18 changes: 17 additions & 1 deletion apps/site/assets/ts/schedule/__tests__/ServiceSelectorTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,27 @@ const services: ServiceInSelector[] = [
added_dates_notes: {},
added_dates: [],
"default_service?": false
},
{
valid_days: [1, 2, 3, 4, 5],
typicality: "unplanned_disruption",
type: "weekday",
start_date: "2019-07-22",
service_date: "2019-07-09",
removed_dates_notes: {},
removed_dates: [],
name: "Weekday",
id: "BUS319-storm-1",
end_date: "2019-07-23",
description: "Storm (reduced service)",
added_dates_notes: {},
added_dates: [],
"default_service?": false
}
];

describe("ServiceSelector", () => {
it("it renders", () => {
it("renders", () => {
createReactRoot();
const tree = renderer.create(
<ServiceSelector
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ServiceSelector it renders 1`] = `
exports[`ServiceSelector renders 1`] = `
Array [
<h3>
Daily Schedule
Expand Down Expand Up @@ -72,6 +72,12 @@ Array [
Storm service,
July 15
</option>
<option
value="BUS319-storm-1"
>
Storm service,
July 22 to July 23
</option>
</optgroup>
</select>
<span
Expand Down

0 comments on commit 9e39a0b

Please sign in to comment.