mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-21 21:34:15 +00:00
Renamed variables for clarity.
Moved calculation to actually change lastcron into its own function.
Changed validation errormessage to run: if ( dayStart != Math.floor(dayStart) || dayStart < 0 || dayStart > 24 ) {error message}.
Created new calculation for daystart because daystart could never be
future to the current timestamp. This "fix" has broken the whole endeavor,
though, because cron runs immedately when newlastcron > now and now >
oldlastcron.
This commit is contained in:
parent
3fa3b491dc
commit
9fe96b7f94
3 changed files with 28 additions and 14 deletions
|
|
@ -66,6 +66,13 @@ api.startOfDay = (options={}) ->
|
|||
dayStart.subtract({days:1})
|
||||
dayStart
|
||||
|
||||
|
||||
api.startOfDayAllowsFuture = (options={}) ->
|
||||
# Use this version to use if you need the result even if the offset would cause today's day start to be in the future.
|
||||
o = sanitizeOptions(options)
|
||||
moment(o.now).startOf('day').add({hours:o.dayStart})
|
||||
|
||||
|
||||
api.dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s'}
|
||||
|
||||
###
|
||||
|
|
|
|||
|
|
@ -66,24 +66,31 @@ habitrpg.controller('SettingsCtrl',
|
|||
User.set({'flags.newStuff':true});
|
||||
}
|
||||
|
||||
$scope.passDayStart = User.user.preferences.dayStart;
|
||||
$scope.dayStart = User.user.preferences.dayStart;
|
||||
|
||||
$scope.saveDayStart = function(newDayStart){
|
||||
var oldDayStart = User.user.preferences.dayStart;
|
||||
var dayStart = newDayStart;
|
||||
function updateLastCron(oldDayStart, newDayStart){
|
||||
var getOldStart = Shared.startOfDayAllowsFuture({ dayStart: oldDayStart});
|
||||
var getNewStart = Shared.startOfDayAllowsFuture({ dayStart: newDayStart});
|
||||
var lastCron = User.user.lastCron;
|
||||
var getOldStart = Shared.startOfDay({ dayStart: oldDayStart});
|
||||
var getNewStart = Shared.startOfDay({ dayStart: dayStart});
|
||||
var momentLastCron = Shared.momentTimestamp(lastCron);
|
||||
var isoNewStart = Shared.isoTimestamp(getNewStart);
|
||||
|
||||
if (dayStart == undefined || _.isNaN(dayStart) || dayStart < 0 || dayStart > 24) {
|
||||
dayStart = 0;
|
||||
return alert(window.env.t('enterNumber'));
|
||||
}
|
||||
if (Shared.momentTimestamp(getOldStart) <= Shared.momentTimestamp(lastCron) && Shared.momentTimestamp(lastCron) < Shared.momentTimestamp(getNewStart)) {
|
||||
alert('Times are oldstart'+Shared.friendlyTimestamp(getOldStart)+' lastcron '+Shared.friendlyTimestamp(lastCron)+' and newstart '+Shared.friendlyTimestamp(getNewStart));
|
||||
if (getOldStart < momentLastCron && momentLastCron < getNewStart) {
|
||||
alert('Setting lastcron to '+Shared.friendlyTimestamp(getNewStart));
|
||||
User.set({ 'lastCron' : isoNewStart});
|
||||
}
|
||||
User.set({'preferences.dayStart': dayStart});
|
||||
};
|
||||
|
||||
$scope.saveDayStart = function(varDayStart){
|
||||
var oldDayStart = User.user.preferences.dayStart;
|
||||
var newDayStart = varDayStart;
|
||||
|
||||
if ( newDayStart != Math.floor(newDayStart) || newDayStart < 0 || newDayStart > 24 ) {
|
||||
newDayStart = 0;
|
||||
return alert(window.env.t('enterNumber'));
|
||||
}
|
||||
updateLastCron( oldDayStart, newDayStart);
|
||||
User.set({'preferences.dayStart': Math.floor(newDayStart)});
|
||||
}
|
||||
|
||||
$scope.language = window.env.language;
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ script(type='text/ng-template', id='partials/options.settings.settings.html')
|
|||
h5(ng-if='showCustomDayStartInfo')!=env.t('customDayStartInfo4')
|
||||
.form-group
|
||||
.input-group
|
||||
input.form-control(type='number', min='0', max='23', ng-model='passDayStart', ng-blur='saveDayStart(passDayStart)')
|
||||
input.form-control(type='number', min='0', max='23', ng-model='dayStart', ng-blur='saveDayStart(dayStart)')
|
||||
span.input-group-addon= ':00 (' + env.t('24HrClock') + ')'
|
||||
|
||||
.personal-options.col-md-6
|
||||
|
|
|
|||
Loading…
Reference in a new issue