mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Refactor video links building
This commit is contained in:
parent
764b1a14fc
commit
9162fdd363
22 changed files with 136 additions and 67 deletions
67
shared/core-utils/common/date.ts
Normal file
67
shared/core-utils/common/date.ts
Normal file
|
@ -0,0 +1,67 @@
|
|||
function isToday (d: Date) {
|
||||
const today = new Date()
|
||||
|
||||
return areDatesEqual(d, today)
|
||||
}
|
||||
|
||||
function isYesterday (d: Date) {
|
||||
const yesterday = new Date()
|
||||
yesterday.setDate(yesterday.getDate() - 1)
|
||||
|
||||
return areDatesEqual(d, yesterday)
|
||||
}
|
||||
|
||||
function isThisWeek (d: Date) {
|
||||
const minDateOfThisWeek = new Date()
|
||||
minDateOfThisWeek.setHours(0, 0, 0)
|
||||
|
||||
// getDay() -> Sunday - Saturday : 0 - 6
|
||||
// We want to start our week on Monday
|
||||
let dayOfWeek = minDateOfThisWeek.getDay() - 1
|
||||
if (dayOfWeek < 0) dayOfWeek = 6 // Sunday
|
||||
|
||||
minDateOfThisWeek.setDate(minDateOfThisWeek.getDate() - dayOfWeek)
|
||||
|
||||
return d >= minDateOfThisWeek
|
||||
}
|
||||
|
||||
function isThisMonth (d: Date) {
|
||||
const thisMonth = new Date().getMonth()
|
||||
|
||||
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,
|
||||
isLastMonth,
|
||||
isLastWeek
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function areDatesEqual (d1: Date, d2: Date) {
|
||||
return d1.getFullYear() === d2.getFullYear() &&
|
||||
d1.getMonth() === d2.getMonth() &&
|
||||
d1.getDate() === d2.getDate()
|
||||
}
|
||||
|
||||
function getDaysDifferences (d1: Date, d2: Date) {
|
||||
return (d1.getTime() - d2.getTime()) / (86400000)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue