aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-06-04 10:28:19 +0200
committerChocobozzz <me@florianbigard.com>2019-06-06 11:43:00 +0200
commit93aa85521ae105476cf3122950813593d9105333 (patch)
tree26f014d507fd0f3ba43fec93c48ba4353a0bbe31 /shared
parent4e0c179365461e9f1f04339b3d5b32d538fea0c4 (diff)
downloadPeerTube-93aa85521ae105476cf3122950813593d9105333.tar.gz
PeerTube-93aa85521ae105476cf3122950813593d9105333.tar.zst
PeerTube-93aa85521ae105476cf3122950813593d9105333.zip
Prefer using last week/last month
Diffstat (limited to 'shared')
-rw-r--r--shared/core-utils/miscs/date.ts20
1 files changed, 19 insertions, 1 deletions
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
34function isLastMonth (d: Date) {
35 const now = new Date()
36
37 return getDaysDifferences(now, d) <= 30
38}
39
40function isLastWeek (d: Date) {
41 const now = new Date()
42
43 return getDaysDifferences(now, d) <= 7
44}
45
34// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
35 47
36export { 48export {
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
65function getDaysDifferences (d1: Date, d2: Date) {
66 return (d1.getTime() - d2.getTime()) / (86400000)
67}