mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-23 23:54:13 +08:00
fix(date-utils): Stop mutating the moment prototype
This commit is contained in:
parent
7bc335c28b
commit
48131468f0
1 changed files with 13 additions and 13 deletions
|
@ -12,16 +12,16 @@ const Days = {
|
|||
ThisWeekend: 6,
|
||||
}
|
||||
|
||||
moment.prototype.oclock = function oclock() {
|
||||
return this.minute(0).second(0)
|
||||
function oclock(momentDate) {
|
||||
return momentDate.minute(0).second(0)
|
||||
}
|
||||
|
||||
moment.prototype.morning = function morning(morningHour = Hours.Morning) {
|
||||
return this.hour(morningHour).oclock()
|
||||
function morning(momentDate, morningHour = Hours.Morning) {
|
||||
return oclock(momentDate.hour(morningHour))
|
||||
}
|
||||
|
||||
moment.prototype.evening = function evening(eveningHour = Hours.Evening) {
|
||||
return this.hour(eveningHour).oclock()
|
||||
function evening(momentDate, eveningHour = Hours.Evening) {
|
||||
return oclock(momentDate.hour(eveningHour))
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,34 +50,34 @@ const DateUtils = {
|
|||
},
|
||||
|
||||
laterToday(now = moment()) {
|
||||
return now.add(3, 'hours').oclock();
|
||||
return oclock(now.add(3, 'hours'));
|
||||
},
|
||||
|
||||
tonight(now = moment()) {
|
||||
if (now.hour() >= Hours.Evening) {
|
||||
return DateUtils.tomorrowEvening();
|
||||
}
|
||||
return now.evening();
|
||||
return evening(now)
|
||||
},
|
||||
|
||||
tomorrow(now = moment()) {
|
||||
return now.add(1, 'day').morning();
|
||||
return morning(now.add(1, 'day'));
|
||||
},
|
||||
|
||||
tomorrowEvening(now = moment()) {
|
||||
return now.add(1, 'day').evening()
|
||||
return evening(now.add(1, 'day'));
|
||||
},
|
||||
|
||||
thisWeekend(now = moment()) {
|
||||
return now.day(Days.ThisWeekend).morning()
|
||||
return morning(now.day(Days.ThisWeekend))
|
||||
},
|
||||
|
||||
nextWeek(now = moment()) {
|
||||
return now.day(Days.NextMonday).morning()
|
||||
return morning(now.day(Days.NextMonday))
|
||||
},
|
||||
|
||||
nextMonth(now = moment()) {
|
||||
return now.add(1, 'month').date(1).morning()
|
||||
return morning(now.add(1, 'month').date(1))
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue