X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Ftimeserie.ts;h=08b12129afa45045027228db9683e1dad8b49938;hb=6bcb854cdea8688a32240bc5719c7d139806e00b;hp=bd3d1c1caed105a1f4a2270df5a4dbb4ecd078c6;hpb=3eda9b775ae700ac544e8c5588514627796b83cd;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/timeserie.ts b/server/lib/timeserie.ts index bd3d1c1ca..08b12129a 100644 --- a/server/lib/timeserie.ts +++ b/server/lib/timeserie.ts @@ -9,7 +9,10 @@ function buildGroupByAndBoundaries (startDateString: string, endDateString: stri logger.debug('Found "%s" group interval.', groupInterval, { startDate, endDate }) // Remove parts of the date we don't need - if (groupInterval.endsWith(' day') || groupInterval.endsWith(' days')) { + if (groupInterval.endsWith(' month') || groupInterval.endsWith(' months')) { + startDate.setDate(1) + startDate.setHours(0, 0, 0, 0) + } else if (groupInterval.endsWith(' day') || groupInterval.endsWith(' days')) { startDate.setHours(0, 0, 0, 0) } else if (groupInterval.endsWith(' hour') || groupInterval.endsWith(' hours')) { startDate.setMinutes(0, 0, 0) @@ -33,16 +36,25 @@ export { // --------------------------------------------------------------------------- function buildGroupInterval (startDate: Date, endDate: Date): string { + const aYear = 31536000 + const aMonth = 2678400 const aDay = 86400 const anHour = 3600 const aMinute = 60 const diffSeconds = (endDate.getTime() - startDate.getTime()) / 1000 + if (diffSeconds >= 6 * aYear) return '6 months' + if (diffSeconds >= 2 * aYear) return '1 month' + if (diffSeconds >= 6 * aMonth) return '7 days' + if (diffSeconds >= 2 * aMonth) return '2 days' + if (diffSeconds >= 15 * aDay) return '1 day' if (diffSeconds >= 8 * aDay) return '12 hours' if (diffSeconds >= 4 * aDay) return '6 hours' + if (diffSeconds >= 15 * anHour) return '1 hour' + if (diffSeconds >= 180 * aMinute) return '10 minutes' return '1 minute'