mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
If user's cron will happen later today, start the task yesterday. (#10783)
* If user's cron will happen later today, start the task yesterday. * Added default dayStart to taskDefaults. * Removed the need to call shouldDo twice to calculate nextDue. * Revert "Removed the need to call shouldDo twice to calculate nextDue." This reverts commit e1467f2fc33cfb11e6a4fc667460df6a48b69d45. * Removed defaults from taskDefault arguments. * Got user from $store in copyAsTodoModal.vue. * Fixed tests for taskDefaults to include mock user. * Fix shouldDo tests when run in GMT timezone. * Added test to taskDefault; added utcOffset to taskDefault. * Replaced utcOffset with zone. * Removed erroneous import.
This commit is contained in:
committed by
Matteo Pagliazzi
parent
12aef475c8
commit
a48a6a292d
@@ -9,7 +9,7 @@ import moment from 'moment';
|
||||
|
||||
const tasksTypes = ['habit', 'daily', 'todo', 'reward'];
|
||||
|
||||
module.exports = function taskDefaults (task = {}) {
|
||||
module.exports = function taskDefaults (task, user) {
|
||||
if (!task.type || tasksTypes.indexOf(task.type) === -1) {
|
||||
task.type = 'habit';
|
||||
}
|
||||
@@ -65,6 +65,14 @@ module.exports = function taskDefaults (task = {}) {
|
||||
}
|
||||
|
||||
if (task.type === 'daily') {
|
||||
let now = moment().zone(user.preferences.timezoneOffset);
|
||||
let startOfDay = now.clone().startOf('day');
|
||||
let startOfDayWithCDSTime = startOfDay
|
||||
.clone()
|
||||
.add({
|
||||
hours: user.preferences.dayStart,
|
||||
});
|
||||
|
||||
defaults(task, {
|
||||
streak: 0,
|
||||
repeat: {
|
||||
@@ -76,7 +84,10 @@ module.exports = function taskDefaults (task = {}) {
|
||||
s: true,
|
||||
su: true,
|
||||
},
|
||||
startDate: moment().startOf('day').toDate(),
|
||||
// If cron will happen today, start the daily yesterday
|
||||
startDate: startOfDayWithCDSTime.isAfter(now) ?
|
||||
startOfDay.clone().subtract(1, 'day').toDate() :
|
||||
startOfDay.toDate(),
|
||||
everyX: 1,
|
||||
frequency: 'weekly',
|
||||
daysOfMonth: [],
|
||||
|
||||
Reference in New Issue
Block a user