Move all time breakpoints to constant
parent
cbe41b0e24
commit
56767cf36d
17
lib/date.js
17
lib/date.js
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue