Fix display of years.

This commit is contained in:
Mike Cao 2020-09-13 01:38:14 -07:00
parent 84a8b51790
commit a0cb278463
3 changed files with 6 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import {
addHours, addHours,
addDays, addDays,
addMonths, addMonths,
addYears,
subHours, subHours,
subDays, subDays,
startOfHour, startOfHour,
@ -19,6 +20,7 @@ import {
differenceInHours, differenceInHours,
differenceInCalendarDays, differenceInCalendarDays,
differenceInCalendarMonths, differenceInCalendarMonths,
differenceInCalendarYears,
} from 'date-fns'; } from 'date-fns';
export function getTimezone() { export function getTimezone() {
@ -90,7 +92,7 @@ export function getDateRangeValues(startDate, endDate) {
return { startDate: startOfHour(startDate), endDate: endOfHour(endDate), unit: 'hour' }; return { startDate: startOfHour(startDate), endDate: endOfHour(endDate), unit: 'hour' };
} else if (differenceInCalendarDays(endDate, startDate) <= 90) { } else if (differenceInCalendarDays(endDate, startDate) <= 90) {
return { startDate: startOfDay(startDate), endDate: endOfDay(endDate), unit: 'day' }; return { startDate: startOfDay(startDate), endDate: endOfDay(endDate), unit: 'day' };
} else if (differenceInCalendarMonths(endDate, startDate) <= 12) { } else if (differenceInCalendarMonths(endDate, startDate) <= 24) {
return { startDate: startOfMonth(startDate), endDate: endOfMonth(endDate), unit: 'month' }; return { startDate: startOfMonth(startDate), endDate: endOfMonth(endDate), unit: 'month' };
} }
return { startDate: startOfYear(startDate), endDate: endOfYear(endDate), unit: 'year' }; return { startDate: startOfYear(startDate), endDate: endOfYear(endDate), unit: 'year' };
@ -100,6 +102,7 @@ const dateFuncs = {
hour: [differenceInHours, addHours, startOfHour], hour: [differenceInHours, addHours, startOfHour],
day: [differenceInCalendarDays, addDays, startOfDay], day: [differenceInCalendarDays, addDays, startOfDay],
month: [differenceInCalendarMonths, addMonths, startOfMonth], month: [differenceInCalendarMonths, addMonths, startOfMonth],
year: [differenceInCalendarYears, addYears, startOfYear],
}; };
export function getDateArray(data, startDate, endDate, unit) { export function getDateArray(data, startDate, endDate, unit) {

View File

@ -1,6 +1,6 @@
{ {
"name": "umami", "name": "umami",
"version": "0.30.0", "version": "0.31.0",
"description": "A simple, fast, website analytics alternative to Google Analytics. ", "description": "A simple, fast, website analytics alternative to Google Analytics. ",
"author": "Mike Cao <mike@mikecao.com>", "author": "Mike Cao <mike@mikecao.com>",
"license": "MIT", "license": "MIT",

View File

@ -3,7 +3,7 @@ import { getPageviews } from 'lib/queries';
import { ok, badRequest, methodNotAllowed } from 'lib/response'; import { ok, badRequest, methodNotAllowed } from 'lib/response';
import { useAuth } from 'lib/middleware'; import { useAuth } from 'lib/middleware';
const unitTypes = ['month', 'hour', 'day']; const unitTypes = ['year', 'month', 'hour', 'day'];
export default async (req, res) => { export default async (req, res) => {
await useAuth(req, res); await useAuth(req, res);