Client - minor refactor

This commit is contained in:
Sam 2021-10-23 15:44:25 +02:00
parent 8efbc4584e
commit bf229860ae
3 changed files with 10 additions and 7 deletions

View File

@ -11,7 +11,7 @@ import {
} from 'date-fns' } from 'date-fns'
import { utcToZonedTime } from 'date-fns-tz' import { utcToZonedTime } from 'date-fns-tz'
export const startDate = ( export const getStartDate = (
duration: string, duration: string,
day: Date, day: Date,
weekStartingMonday: boolean weekStartingMonday: boolean

View File

@ -23,7 +23,7 @@ import {
TStatisticsDatasets, TStatisticsDatasets,
TStatisticsFromApi, TStatisticsFromApi,
} from '@/types/statistics' } from '@/types/statistics'
import { incrementDate, startDate } from '@/utils/dates' import { incrementDate, getStartDate } from '@/utils/dates'
import { sportColors } from '@/utils/sports' import { sportColors } from '@/utils/sports'
const dateFormats: Record<string, Record<string, string>> = { const dateFormats: Record<string, Record<string, string>> = {
@ -53,7 +53,7 @@ export const getDateKeys = (
): Date[] => { ): Date[] => {
const days = [] const days = []
for ( for (
let day = startDate(params.duration, params.start, weekStartingMonday); let day = getStartDate(params.duration, params.start, weekStartingMonday);
day <= params.end; day <= params.end;
day = incrementDate(params.duration, day) day = incrementDate(params.duration, day)
) { ) {

View File

@ -3,7 +3,7 @@ import { assert, expect } from 'chai'
import { import {
getCalendarStartAndEnd, getCalendarStartAndEnd,
incrementDate, incrementDate,
startDate, getStartDate,
formatWorkoutDate, formatWorkoutDate,
} from '@/utils/dates' } from '@/utils/dates'
@ -34,7 +34,7 @@ describe('startDate (week starting Sunday)', () => {
const day: Date = new Date(testParams.inputDate) const day: Date = new Date(testParams.inputDate)
const expected: Date = new Date(testParams.expectedDate) const expected: Date = new Date(testParams.expectedDate)
assert.deepEqual( assert.deepEqual(
startDate(testParams.inputDuration, day, false), getStartDate(testParams.inputDuration, day, false),
expected expected
) )
}) })
@ -67,7 +67,10 @@ describe('startDate (week starting Monday)', () => {
it(testParams.description, () => { it(testParams.description, () => {
const day: Date = new Date(testParams.inputDate) const day: Date = new Date(testParams.inputDate)
const expected: Date = new Date(testParams.expectedDate) const expected: Date = new Date(testParams.expectedDate)
assert.deepEqual(startDate(testParams.inputDuration, day, true), expected) assert.deepEqual(
getStartDate(testParams.inputDuration, day, true),
expected
)
}) })
) )
}) })
@ -75,7 +78,7 @@ describe('startDate (week starting Monday)', () => {
describe('startDate (week starting Monday)', () => { describe('startDate (week starting Monday)', () => {
it('it throws an exception if duration is invalid', () => { it('it throws an exception if duration is invalid', () => {
const day: Date = new Date('August 21, 2021 20:00:00') const day: Date = new Date('August 21, 2021 20:00:00')
expect(() => startDate('invalid duration', day, true)).to.throw( expect(() => getStartDate('invalid duration', day, true)).to.throw(
'Invalid duration, expected: "week", "month", "year", got: "invalid duration"' 'Invalid duration, expected: "week", "month", "year", got: "invalid duration"'
) )
}) })