Client - minor refactor
This commit is contained in:
parent
8efbc4584e
commit
bf229860ae
@ -11,7 +11,7 @@ import {
|
||||
} from 'date-fns'
|
||||
import { utcToZonedTime } from 'date-fns-tz'
|
||||
|
||||
export const startDate = (
|
||||
export const getStartDate = (
|
||||
duration: string,
|
||||
day: Date,
|
||||
weekStartingMonday: boolean
|
||||
|
@ -23,7 +23,7 @@ import {
|
||||
TStatisticsDatasets,
|
||||
TStatisticsFromApi,
|
||||
} from '@/types/statistics'
|
||||
import { incrementDate, startDate } from '@/utils/dates'
|
||||
import { incrementDate, getStartDate } from '@/utils/dates'
|
||||
import { sportColors } from '@/utils/sports'
|
||||
|
||||
const dateFormats: Record<string, Record<string, string>> = {
|
||||
@ -53,7 +53,7 @@ export const getDateKeys = (
|
||||
): Date[] => {
|
||||
const days = []
|
||||
for (
|
||||
let day = startDate(params.duration, params.start, weekStartingMonday);
|
||||
let day = getStartDate(params.duration, params.start, weekStartingMonday);
|
||||
day <= params.end;
|
||||
day = incrementDate(params.duration, day)
|
||||
) {
|
||||
|
@ -3,7 +3,7 @@ import { assert, expect } from 'chai'
|
||||
import {
|
||||
getCalendarStartAndEnd,
|
||||
incrementDate,
|
||||
startDate,
|
||||
getStartDate,
|
||||
formatWorkoutDate,
|
||||
} from '@/utils/dates'
|
||||
|
||||
@ -34,7 +34,7 @@ describe('startDate (week starting Sunday)', () => {
|
||||
const day: Date = new Date(testParams.inputDate)
|
||||
const expected: Date = new Date(testParams.expectedDate)
|
||||
assert.deepEqual(
|
||||
startDate(testParams.inputDuration, day, false),
|
||||
getStartDate(testParams.inputDuration, day, false),
|
||||
expected
|
||||
)
|
||||
})
|
||||
@ -67,7 +67,10 @@ describe('startDate (week starting Monday)', () => {
|
||||
it(testParams.description, () => {
|
||||
const day: Date = new Date(testParams.inputDate)
|
||||
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)', () => {
|
||||
it('it throws an exception if duration is invalid', () => {
|
||||
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"'
|
||||
)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user