Skip to content

Commit

Permalink
Extend slowzone segment link to include 7 days of trailing data. (#857)
Browse files Browse the repository at this point in the history
* Extend slowzone segment link to include 7 days of trailing data.

* fix linting
  • Loading branch information
austinjpaul authored Sep 6, 2023
1 parent a8097c3 commit 9a7bf81
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions modules/slowzones/charts/LineSegments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import { Bar } from 'react-chartjs-2';
import React, { useMemo, useRef } from 'react';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import minMax from 'dayjs/plugin/minMax';
import ChartjsPluginWatermark from 'chartjs-plugin-watermark';

import type { ChartDataset } from 'chart.js';
import { DATE_FORMAT, YESTERDAY_MIDNIGHT, YESTERDAY_STRING } from '../../../common/constants/dates';
import {
DATE_FORMAT,
YESTERDAY_MIDNIGHT,
YESTERDAY_STRING,
TODAY,
} from '../../../common/constants/dates';
import { COLORS } from '../../../common/constants/colors';
import type { Direction, LineSegmentData, SlowZone } from '../../../common/types/dataPoints';
import type { LinePath } from '../../../common/types/lines';
Expand All @@ -24,6 +30,7 @@ import { stopIdsForStations } from '../../../common/utils/stations';
import { ALL_PAGES } from '../../../common/constants/pages';
import type { QueryParams } from '../../../common/types/router';
dayjs.extend(utc);
dayjs.extend(minMax);

interface LineSegmentsProps {
data: SlowZone[];
Expand Down Expand Up @@ -128,7 +135,7 @@ export const LineSegments: React.FC<LineSegmentsProps> = ({
const queryParams: QueryParams = {
// Show 7 days before slowzone start for comparison
startDate: dayjs(x[0]).subtract(7, 'days').format(DATE_FORMAT),
endDate: x[1],
endDate: dayjs.min(TODAY, dayjs(x[1]).add(7, 'days'))?.format(DATE_FORMAT),
to: stations.toStopIds?.[0],
from: stations.fromStopIds?.[0],
};
Expand Down Expand Up @@ -170,11 +177,12 @@ export const LineSegments: React.FC<LineSegmentsProps> = ({
if (!(start && end)) return 'Unknown dates';
const startUTC = dayjs.utc(start);
const endUTC = dayjs.utc(end);
return `${startUTC.format('MMM D, YYYY')} - ${
dayjs.utc(endUTC).isSame(YESTERDAY_MIDNIGHT)
? 'Ongoing'
: dayjs(endUTC).format('MMM D, YYYY')
}`;
return `${startUTC.format('MMM D, YYYY')} -
${
dayjs.utc(endUTC).isSame(YESTERDAY_MIDNIGHT)
? 'Ongoing'
: dayjs(endUTC).format('MMM D, YYYY')
}`;
},
},
},
Expand Down

0 comments on commit 9a7bf81

Please sign in to comment.