aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
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}