X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fcore-utils%2Fmiscs%2Fdate.ts;h=4f92f758ff665600d5b392d614e4366c0b18522a;hb=67ed6552b831df66713bac9e672738796128d33f;hp=7f0b4443b7c0533b42402d70c84bea62a20b7760;hpb=34c7f429e411fb911dfa56a816b638fd665717a4;p=github%2FChocobozzz%2FPeerTube.git 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) { return d.getMonth() === thisMonth } +function isLastMonth (d: Date) { + const now = new Date() + + return getDaysDifferences(now, d) <= 30 +} + +function isLastWeek (d: Date) { + const now = new Date() + + return getDaysDifferences(now, d) <= 7 +} + // --------------------------------------------------------------------------- export { isYesterday, isThisWeek, isThisMonth, - isToday + isToday, + isLastMonth, + isLastWeek } // --------------------------------------------------------------------------- @@ -47,3 +61,7 @@ function areDatesEqual (d1: Date, d2: Date) { d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate() } + +function getDaysDifferences (d1: Date, d2: Date) { + return (d1.getTime() - d2.getTime()) / (86400000) +}