aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-05-06 14:23:02 +0200
committerChocobozzz <me@florianbigard.com>2022-05-06 14:23:02 +0200
commitf40712abbbb74e51f06037ef02757c42736bccf8 (patch)
tree4b130c6387f9687d52d570907eb1bbac6bc04b61 /server/lib
parent49f0468d44468528c2fb2c8b0efd19cdaeeec43d (diff)
downloadPeerTube-f40712abbbb74e51f06037ef02757c42736bccf8.tar.gz
PeerTube-f40712abbbb74e51f06037ef02757c42736bccf8.tar.zst
PeerTube-f40712abbbb74e51f06037ef02757c42736bccf8.zip
Add ability to filter overall video stats by date
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/timeserie.ts14
1 files changed, 13 insertions, 1 deletions
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
9 logger.debug('Found "%s" group interval.', groupInterval, { startDate, endDate }) 9 logger.debug('Found "%s" group interval.', groupInterval, { startDate, endDate })
10 10
11 // Remove parts of the date we don't need 11 // Remove parts of the date we don't need
12 if (groupInterval.endsWith(' day') || groupInterval.endsWith(' days')) { 12 if (groupInterval.endsWith(' month') || groupInterval.endsWith(' months')) {
13 startDate.setDate(1)
14 startDate.setHours(0, 0, 0, 0)
15 } else if (groupInterval.endsWith(' day') || groupInterval.endsWith(' days')) {
13 startDate.setHours(0, 0, 0, 0) 16 startDate.setHours(0, 0, 0, 0)
14 } else if (groupInterval.endsWith(' hour') || groupInterval.endsWith(' hours')) { 17 } else if (groupInterval.endsWith(' hour') || groupInterval.endsWith(' hours')) {
15 startDate.setMinutes(0, 0, 0) 18 startDate.setMinutes(0, 0, 0)
@@ -33,16 +36,25 @@ export {
33// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
34 37
35function buildGroupInterval (startDate: Date, endDate: Date): string { 38function buildGroupInterval (startDate: Date, endDate: Date): string {
39 const aYear = 31536000
40 const aMonth = 2678400
36 const aDay = 86400 41 const aDay = 86400
37 const anHour = 3600 42 const anHour = 3600
38 const aMinute = 60 43 const aMinute = 60
39 44
40 const diffSeconds = (endDate.getTime() - startDate.getTime()) / 1000 45 const diffSeconds = (endDate.getTime() - startDate.getTime()) / 1000
41 46
47 if (diffSeconds >= 6 * aYear) return '6 months'
48 if (diffSeconds >= 2 * aYear) return '1 month'
49 if (diffSeconds >= 6 * aMonth) return '7 days'
50 if (diffSeconds >= 2 * aMonth) return '2 days'
51
42 if (diffSeconds >= 15 * aDay) return '1 day' 52 if (diffSeconds >= 15 * aDay) return '1 day'
43 if (diffSeconds >= 8 * aDay) return '12 hours' 53 if (diffSeconds >= 8 * aDay) return '12 hours'
44 if (diffSeconds >= 4 * aDay) return '6 hours' 54 if (diffSeconds >= 4 * aDay) return '6 hours'
55
45 if (diffSeconds >= 15 * anHour) return '1 hour' 56 if (diffSeconds >= 15 * anHour) return '1 hour'
57
46 if (diffSeconds >= 180 * aMinute) return '10 minutes' 58 if (diffSeconds >= 180 * aMinute) return '10 minutes'
47 59
48 return '1 minute' 60 return '1 minute'