From 282e105ea3c318b6128277318a073af6f9fa20a8 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Fri, 29 Nov 2013 17:15:41 -0700 Subject: [PATCH] [https://github.com/HabitRPG/habitrpg/issues/1057] don't exit-early when attempting to detect if they've switched timezones. Also, don't need to sanitize user.lastCron in shared, do it in Mongoose --- dist/habitrpg-shared.js | 5 ----- script/algos.coffee | 13 ++++++++----- script/helpers.coffee | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/dist/habitrpg-shared.js b/dist/habitrpg-shared.js index 0929822d63..234cd5515d 100644 --- a/dist/habitrpg-shared.js +++ b/dist/habitrpg-shared.js @@ -9172,11 +9172,6 @@ var global=self;/** options = {}; } _ref1 = [options.paths || {}, +options.now || +(new Date)], paths = _ref1[0], now = _ref1[1]; - if ((user.lastCron == null) || user.lastCron === 'new' || moment(user.lastCron).isAfter(now)) { - user.lastCron = now; - paths['lastCron'] = true; - return; - } daysMissed = helpers.daysSince(user.lastCron, _.defaults({ now: now }, user.preferences)); diff --git a/script/algos.coffee b/script/algos.coffee index efcc8531db..66d1bd76c2 100644 --- a/script/algos.coffee +++ b/script/algos.coffee @@ -361,11 +361,14 @@ updateStats = (user, newStats, options={}) -> obj.cron = (user, options={}) -> [paths, now] = [options.paths || {}, +options.now || +new Date] - # New user (!lastCron, lastCron==new) or it got busted somehow, maybe they went to a different timezone - # FIXME move this to pre-save in mongoose - if !user.lastCron? or user.lastCron is 'new' or moment(user.lastCron).isAfter(now) - user.lastCron = now; paths['lastCron'] = true - return + # They went to a different timezone + # FIXME: + # (1) This exit-early code isn't taking timezone into consideration!! + # (2) Won't switching timezones be handled automatically client-side anyway? (aka, can we just remove this code?) + # (3) And if not, is this the correct way to handle switching timezones +# if moment(user.lastCron).isAfter(now) +# user.lastCron = now +# return daysMissed = helpers.daysSince user.lastCron, _.defaults({now}, user.preferences) return unless daysMissed > 0 diff --git a/script/helpers.coffee b/script/helpers.coffee index db86af1293..0976243ede 100644 --- a/script/helpers.coffee +++ b/script/helpers.coffee @@ -105,7 +105,7 @@ module.exports = preferences: { gender: 'm', skin: 'white', hair: 'blond', armorSet: 'v1', dayStart:0, showHelm: true } apiToken: uuid() # set in newUserObject below - lastCron: +new Date #this will be replaced with `+new Date` on first run + lastCron: +new Date balance: 0 flags: partyEnabled: false