diff options
author | Chocobozzz <me@florianbigard.com> | 2019-06-04 10:28:19 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-06-06 11:43:00 +0200 |
commit | 93aa85521ae105476cf3122950813593d9105333 (patch) | |
tree | 26f014d507fd0f3ba43fec93c48ba4353a0bbe31 | |
parent | 4e0c179365461e9f1f04339b3d5b32d538fea0c4 (diff) | |
download | PeerTube-93aa85521ae105476cf3122950813593d9105333.tar.gz PeerTube-93aa85521ae105476cf3122950813593d9105333.tar.zst PeerTube-93aa85521ae105476cf3122950813593d9105333.zip |
Prefer using last week/last month
-rw-r--r-- | client/src/app/shared/video/abstract-video-list.ts | 22 | ||||
-rw-r--r-- | shared/core-utils/miscs/date.ts | 20 |
2 files changed, 30 insertions, 12 deletions
diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index 8cf21e9d4..dc8f9cda9 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts | |||
@@ -12,14 +12,14 @@ import { Syndication } from '@app/shared/video/syndication.model' | |||
12 | import { Notifier, ServerService } from '@app/core' | 12 | import { Notifier, ServerService } from '@app/core' |
13 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' | 13 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' |
14 | import { I18n } from '@ngx-translate/i18n-polyfill' | 14 | import { I18n } from '@ngx-translate/i18n-polyfill' |
15 | import { isThisMonth, isThisWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' | 15 | import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' |
16 | 16 | ||
17 | enum GroupDate { | 17 | enum GroupDate { |
18 | UNKNOWN = 0, | 18 | UNKNOWN = 0, |
19 | TODAY = 1, | 19 | TODAY = 1, |
20 | YESTERDAY = 2, | 20 | YESTERDAY = 2, |
21 | THIS_WEEK = 3, | 21 | LAST_WEEK = 3, |
22 | THIS_MONTH = 4, | 22 | LAST_MONTH = 4, |
23 | OLDER = 5 | 23 | OLDER = 5 |
24 | } | 24 | } |
25 | 25 | ||
@@ -84,8 +84,8 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor | |||
84 | [GroupDate.UNKNOWN]: null, | 84 | [GroupDate.UNKNOWN]: null, |
85 | [GroupDate.TODAY]: this.i18n('Today'), | 85 | [GroupDate.TODAY]: this.i18n('Today'), |
86 | [GroupDate.YESTERDAY]: this.i18n('Yesterday'), | 86 | [GroupDate.YESTERDAY]: this.i18n('Yesterday'), |
87 | [GroupDate.THIS_WEEK]: this.i18n('This week'), | 87 | [GroupDate.LAST_WEEK]: this.i18n('Last week'), |
88 | [GroupDate.THIS_MONTH]: this.i18n('This month'), | 88 | [GroupDate.LAST_MONTH]: this.i18n('Last month'), |
89 | [GroupDate.OLDER]: this.i18n('Older') | 89 | [GroupDate.OLDER]: this.i18n('Older') |
90 | } | 90 | } |
91 | 91 | ||
@@ -183,18 +183,18 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor | |||
183 | continue | 183 | continue |
184 | } | 184 | } |
185 | 185 | ||
186 | if (currentGroupedDate <= GroupDate.THIS_WEEK && isThisWeek(publishedDate)) { | 186 | if (currentGroupedDate <= GroupDate.LAST_WEEK && isLastWeek(publishedDate)) { |
187 | if (currentGroupedDate === GroupDate.THIS_WEEK) continue | 187 | if (currentGroupedDate === GroupDate.LAST_WEEK) continue |
188 | 188 | ||
189 | currentGroupedDate = GroupDate.THIS_WEEK | 189 | currentGroupedDate = GroupDate.LAST_WEEK |
190 | this.groupedDates[ video.id ] = currentGroupedDate | 190 | this.groupedDates[ video.id ] = currentGroupedDate |
191 | continue | 191 | continue |
192 | } | 192 | } |
193 | 193 | ||
194 | if (currentGroupedDate <= GroupDate.THIS_MONTH && isThisMonth(publishedDate)) { | 194 | if (currentGroupedDate <= GroupDate.LAST_MONTH && isLastMonth(publishedDate)) { |
195 | if (currentGroupedDate === GroupDate.THIS_MONTH) continue | 195 | if (currentGroupedDate === GroupDate.LAST_MONTH) continue |
196 | 196 | ||
197 | currentGroupedDate = GroupDate.THIS_MONTH | 197 | currentGroupedDate = GroupDate.LAST_MONTH |
198 | this.groupedDates[ video.id ] = currentGroupedDate | 198 | this.groupedDates[ video.id ] = currentGroupedDate |
199 | continue | 199 | continue |
200 | } | 200 | } |
diff --git a/shared/core-utils/miscs/date.ts b/shared/core-utils/miscs/date.ts index 7f0b4443b..4f92f758f 100644 --- a/shared/core-utils/miscs/date.ts +++ b/shared/core-utils/miscs/date.ts | |||
@@ -31,13 +31,27 @@ function isThisMonth (d: Date) { | |||
31 | return d.getMonth() === thisMonth | 31 | return d.getMonth() === thisMonth |
32 | } | 32 | } |
33 | 33 | ||
34 | function isLastMonth (d: Date) { | ||
35 | const now = new Date() | ||
36 | |||
37 | return getDaysDifferences(now, d) <= 30 | ||
38 | } | ||
39 | |||
40 | function isLastWeek (d: Date) { | ||
41 | const now = new Date() | ||
42 | |||
43 | return getDaysDifferences(now, d) <= 7 | ||
44 | } | ||
45 | |||
34 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
35 | 47 | ||
36 | export { | 48 | export { |
37 | isYesterday, | 49 | isYesterday, |
38 | isThisWeek, | 50 | isThisWeek, |
39 | isThisMonth, | 51 | isThisMonth, |
40 | isToday | 52 | isToday, |
53 | isLastMonth, | ||
54 | isLastWeek | ||
41 | } | 55 | } |
42 | 56 | ||
43 | // --------------------------------------------------------------------------- | 57 | // --------------------------------------------------------------------------- |
@@ -47,3 +61,7 @@ function areDatesEqual (d1: Date, d2: Date) { | |||
47 | d1.getMonth() === d2.getMonth() && | 61 | d1.getMonth() === d2.getMonth() && |
48 | d1.getDate() === d2.getDate() | 62 | d1.getDate() === d2.getDate() |
49 | } | 63 | } |
64 | |||
65 | function getDaysDifferences (d1: Date, d2: Date) { | ||
66 | return (d1.getTime() - d2.getTime()) / (86400000) | ||
67 | } | ||