Minor refactorings and function extractions

This commit is contained in:
Alejandro Celaya
2022-11-26 09:11:46 +01:00
parent a3f5095dce
commit 165afa436d
6 changed files with 26 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
import { subDays, startOfDay, endOfDay } from 'date-fns';
import { cond, filter, isEmpty, T } from 'ramda';
import { DateOrString, formatInternational, isBeforeOrEqual, parseISO } from '../../helpers/date';
import { dateOrNull, DateOrString, formatInternational, isBeforeOrEqual, parseISO } from '../../helpers/date';
export interface DateRange {
startDate?: Date | null;
@@ -28,6 +28,11 @@ const INTERVAL_TO_STRING_MAP: Record<DateInterval, string | undefined> = {
export const DATE_INTERVALS = Object.keys(INTERVAL_TO_STRING_MAP).filter((value) => value !== 'all') as DateInterval[];
export const datesToDateRange = (startDate?: string, endDate?: string): DateRange => ({
startDate: dateOrNull(startDate),
endDate: dateOrNull(endDate),
});
const dateRangeToString = (range?: DateRange): string | undefined => {
if (!range || dateRangeIsEmpty(range)) {
return undefined;