Move all time breakpoints to constant

pull/882/head
Chris Walsh 2021-12-04 14:10:01 -08:00
parent cbe41b0e24
commit 56767cf36d
No known key found for this signature in database
GPG Key ID: 28EE0CCA6032019E
1 changed files with 12 additions and 5 deletions

View File

@ -41,31 +41,37 @@ export function getDateRange(value, locale = 'en-US', createdAt = null) {
if (value === 'all') { if (value === 'all') {
createdAt = new Date(createdAt); createdAt = new Date(createdAt);
const diff = Math.abs(differenceInCalendarDays(createdAt, now)); const diff = Math.abs(differenceInCalendarDays(createdAt, now));
const breakpoints = {
day: 1,
month: 90,
year: 1095,
};
if (createdAt) { if (createdAt) {
if (diff <= 1) { if (diff <= breakpoints.day) {
return { return {
startDate: startOfDay(createdAt), startDate: startOfDay(createdAt),
endDate: endOfDay(now), endDate: endOfDay(now),
unit: 'hour', unit: 'hour',
value, value,
}; };
} else if (diff <= 90 && diff > 1) { } else if (diff <= breakpoints.month && diff > breakpoints.day) {
return { return {
startDate: startOfWeek(createdAt), startDate: startOfWeek(createdAt),
endDate: endOfWeek(now), endDate: endOfWeek(now),
unit: 'day', unit: 'day',
value, value,
}; };
} else if (diff <= 1095 && diff > 90) { } else if (diff <= breakpoints.year && diff > breakpoints.month) {
return { return {
startDate: startOfMonth(createdAt), startDate: startOfMonth(createdAt),
endDate: endOfMonth(now), endDate: endOfMonth(now),
unit: 'month', unit: 'month',
value, value,
}; };
} else if (diff > 1095) { } else if (diff > breakpoints.year) {
return { return {
startDate: startOfYear(createdAt), startDate: startOfYear(createdAt),
endDate: endOfYear(now), endDate: endOfYear(now),
@ -74,8 +80,9 @@ export function getDateRange(value, locale = 'en-US', createdAt = null) {
}; };
} }
} }
return { return {
startDate: startOfYear(createdAt), startDate: startOfYear(now),
endDate: endOfYear(now), endDate: endOfYear(now),
unit: 'year', unit: 'year',
value, value,