aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-05-31 11:14:38 +0200
committerChocobozzz <me@florianbigard.com>2019-05-31 11:15:50 +0200
commit34c7f429e411fb911dfa56a816b638fd665717a4 (patch)
treeaf6b7658788a2304301a4793b7e9a293c8d2e1e6 /shared/core-utils
parente6b04e0e796c1b36d15fbe732e89ef4820dcabd9 (diff)
downloadPeerTube-34c7f429e411fb911dfa56a816b638fd665717a4.tar.gz
PeerTube-34c7f429e411fb911dfa56a816b638fd665717a4.tar.zst
PeerTube-34c7f429e411fb911dfa56a816b638fd665717a4.zip
Group videos on chronological order
Diffstat (limited to 'shared/core-utils')
-rw-r--r--shared/core-utils/miscs/date.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/shared/core-utils/miscs/date.ts b/shared/core-utils/miscs/date.ts
new file mode 100644
index 000000000..7f0b4443b
--- /dev/null
+++ b/shared/core-utils/miscs/date.ts
@@ -0,0 +1,49 @@
1function isToday (d: Date) {
2 const today = new Date()
3
4 return areDatesEqual(d, today)
5}
6
7function isYesterday (d: Date) {
8 const yesterday = new Date()
9 yesterday.setDate(yesterday.getDate() - 1)
10
11 return areDatesEqual(d, yesterday)
12}
13
14function isThisWeek (d: Date) {
15 const minDateOfThisWeek = new Date()
16 minDateOfThisWeek.setHours(0, 0, 0)
17
18 // getDay() -> Sunday - Saturday : 0 - 6
19 // We want to start our week on Monday
20 let dayOfWeek = minDateOfThisWeek.getDay() - 1
21 if (dayOfWeek < 0) dayOfWeek = 6 // Sunday
22
23 minDateOfThisWeek.setDate(minDateOfThisWeek.getDate() - dayOfWeek)
24
25 return d >= minDateOfThisWeek
26}
27
28function isThisMonth (d: Date) {
29 const thisMonth = new Date().getMonth()
30
31 return d.getMonth() === thisMonth
32}
33
34// ---------------------------------------------------------------------------
35
36export {
37 isYesterday,
38 isThisWeek,
39 isThisMonth,
40 isToday
41}
42
43// ---------------------------------------------------------------------------
44
45function areDatesEqual (d1: Date, d2: Date) {
46 return d1.getFullYear() === d2.getFullYear() &&
47 d1.getMonth() === d2.getMonth() &&
48 d1.getDate() === d2.getDate()
49}