ability to use custom dates everywhere

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-02-26 16:40:09 +01:00
parent 94a0ac7bd0
commit 6a8656da3d
19 changed files with 254 additions and 95 deletions

View File

@@ -1,3 +1,5 @@
import { isSameDay, isSameMonth } from 'date-fns';
export const NOT_SET_VALUE = '(not set)';
export const operators = {
@@ -100,3 +102,19 @@ export function getDefaultIntervalByRange(
}
return 'month';
}
export function getDefaultIntervalByDates(
startDate: string | null,
endDate: string | null
): null | keyof typeof intervals {
if (startDate && endDate) {
if (isSameDay(startDate, endDate)) {
return 'hour';
} else if (isSameMonth(startDate, endDate)) {
return 'day';
}
return 'month';
}
return null;
}

View File

@@ -11,6 +11,7 @@
"@mixan/eslint-config": "workspace:*",
"@mixan/prettier-config": "workspace:*",
"@mixan/tsconfig": "workspace:*",
"date-fns": "^3.3.1",
"eslint": "^8.48.0",
"prettier": "^3.0.3",
"prisma": "^5.1.1",