date-fns#getISODay TypeScript Examples

The following examples show how to use date-fns#getISODay. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: queryCovid19Data.ts    From covid19-trend-map with Apache License 2.0 6 votes vote down vote up
getBiggestWeeklyIncrease = (data: Covid19CasesByTimeFeature[]) => {
    let featureWithBiggestWeeklyIncrease = data[0];
    let biggestWeeklyIncrease = Number.NEGATIVE_INFINITY;

    const dateForFirstFeature = parse(
        data[0].attributes.dt,
        'yyyy-MM-dd',
        new Date()
    );

    const dayForFirstFeature = getISODay(dateForFirstFeature);

    for (let i = 0, len = data.length; i < len; i++) {
        let dayOfWeek = (i % 7) + dayForFirstFeature;

        dayOfWeek = dayOfWeek > 7 ? dayOfWeek - 7 : dayOfWeek;

        if (dayOfWeek === 1) {
            const { Confirmed } = data[i].attributes;

            const feature7DaysAgo = i - 6 >= 0 ? data[i - 6] : data[0];

            const weeklyIncrease =
                Confirmed - feature7DaysAgo.attributes.Confirmed;

            if (weeklyIncrease > biggestWeeklyIncrease) {
                biggestWeeklyIncrease = weeklyIncrease;
                featureWithBiggestWeeklyIncrease = data[i];
            }
        }
    }

    const dateWithBiggestWeeklyIncrease =
        featureWithBiggestWeeklyIncrease.attributes.dt; //parse(featureWithBiggestWeeklyIncrease.attributes.dt, 'yyyy-MM-dd', new Date())

    return dateWithBiggestWeeklyIncrease; //format(dateWithBiggestWeeklyIncrease, 'MMMM dd, yyyy');
}