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') {
|
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,
|
||||||
|
|
Loading…
Reference in New Issue