diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-26 14:12:39 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-26 14:12:50 +0200 |
commit | 9162fdd36300d2478f13d6ad346ec2c323f40faa (patch) | |
tree | dea0ca43f3ea2fb72a73ca77338f5b7c990acdd7 /shared/core-utils/miscs/date.ts | |
parent | 764b1a14fc494f2cfd7ea590d2f07b01df65c7ad (diff) | |
download | PeerTube-9162fdd36300d2478f13d6ad346ec2c323f40faa.tar.gz PeerTube-9162fdd36300d2478f13d6ad346ec2c323f40faa.tar.zst PeerTube-9162fdd36300d2478f13d6ad346ec2c323f40faa.zip |
Refactor video links building
Diffstat (limited to 'shared/core-utils/miscs/date.ts')
-rw-r--r-- | shared/core-utils/miscs/date.ts | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/shared/core-utils/miscs/date.ts b/shared/core-utils/miscs/date.ts deleted file mode 100644 index 4f92f758f..000000000 --- a/shared/core-utils/miscs/date.ts +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | function isToday (d: Date) { | ||
2 | const today = new Date() | ||
3 | |||
4 | return areDatesEqual(d, today) | ||
5 | } | ||
6 | |||
7 | function isYesterday (d: Date) { | ||
8 | const yesterday = new Date() | ||
9 | yesterday.setDate(yesterday.getDate() - 1) | ||
10 | |||
11 | return areDatesEqual(d, yesterday) | ||
12 | } | ||
13 | |||
14 | function 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 | |||
28 | function isThisMonth (d: Date) { | ||
29 | const thisMonth = new Date().getMonth() | ||
30 | |||
31 | return d.getMonth() === thisMonth | ||
32 | } | ||
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 | |||
46 | // --------------------------------------------------------------------------- | ||
47 | |||
48 | export { | ||
49 | isYesterday, | ||
50 | isThisWeek, | ||
51 | isThisMonth, | ||
52 | isToday, | ||
53 | isLastMonth, | ||
54 | isLastWeek | ||
55 | } | ||
56 | |||
57 | // --------------------------------------------------------------------------- | ||
58 | |||
59 | function areDatesEqual (d1: Date, d2: Date) { | ||
60 | return d1.getFullYear() === d2.getFullYear() && | ||
61 | d1.getMonth() === d2.getMonth() && | ||
62 | d1.getDate() === d2.getDate() | ||
63 | } | ||
64 | |||
65 | function getDaysDifferences (d1: Date, d2: Date) { | ||
66 | return (d1.getTime() - d2.getTime()) / (86400000) | ||
67 | } | ||