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