Calendar updates. Responsive CSS updates.

This commit is contained in:
Mike Cao 2020-09-13 11:33:57 -07:00
parent a0cb278463
commit f59594e4cd
18 changed files with 127 additions and 42 deletions

View file

@ -88,14 +88,16 @@ export function getDateRange(value) {
}
export function getDateRangeValues(startDate, endDate) {
if (differenceInHours(endDate, startDate) <= 48) {
return { startDate: startOfHour(startDate), endDate: endOfHour(endDate), unit: 'hour' };
let unit = 'year';
if (differenceInHours(endDate, startDate) <= 72) {
unit = 'hour';
} else if (differenceInCalendarDays(endDate, startDate) <= 90) {
return { startDate: startOfDay(startDate), endDate: endOfDay(endDate), unit: 'day' };
unit = 'day';
} else if (differenceInCalendarMonths(endDate, startDate) <= 24) {
return { startDate: startOfMonth(startDate), endDate: endOfMonth(endDate), unit: 'month' };
unit = 'month';
}
return { startDate: startOfYear(startDate), endDate: endOfYear(endDate), unit: 'year' };
return { startDate: startOfDay(startDate), endDate: endOfDay(endDate), unit };
}
const dateFuncs = {
@ -112,11 +114,12 @@ export function getDateArray(data, startDate, endDate, unit) {
function findData(t) {
const x = data.find(e => {
if (unit === 'day') {
const [year, month, day] = e.t.split('-');
return normalize(new Date(year, month - 1, day)).getTime() === t.getTime();
if (unit === 'hour') {
return normalize(new Date(e.t)).getTime() === t.getTime();
}
return normalize(new Date(e.t)).getTime() === t.getTime();
const [year, month, day] = e.t.split('-');
return normalize(new Date(year, month - 1, day)).getTime() === t.getTime();
});
return x?.y || 0;