custom dayStart
This commit is contained in:
@@ -99,7 +99,7 @@ userSchema =
|
||||
stats: { gp: 0, exp: 0, lvl: 1, hp: 50 }
|
||||
party: { current: null, invitation: null }
|
||||
items: { weapon: 0, armor: 0, head: 0, shield: 0 }
|
||||
preferences: { gender: 'm', skin: 'white', hair: 'blond', armorSet: 'v1' }
|
||||
preferences: { gender: 'm', skin: 'white', hair: 'blond', armorSet: 'v1', dayStart:0 }
|
||||
habitIds: []
|
||||
dailyIds: []
|
||||
todoIds: []
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
moment = require('moment')
|
||||
|
||||
# Absolute diff between two dates, based on 12am for both days
|
||||
module.exports.daysBetween = (a, b) ->
|
||||
Math.abs(moment(a).startOf('day').diff(moment(b).startOf('day'), 'days'))
|
||||
# Absolute diff between two dates
|
||||
module.exports.daysBetween = (yesterday, now, dayStart) ->
|
||||
#sanity-check reset-time (is it 24h time?)
|
||||
dayStart = 0 unless (dayStart? and (dayStart = parseInt(dayStart)) and dayStart >= 0 and dayStart <= 24)
|
||||
Math.abs moment(yesterday).startOf('day').add('h', dayStart).diff(moment(now), 'days')
|
||||
|
||||
module.exports.dayMapping = dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s',7:'su'}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ updateStats = (model, newStats, batch) ->
|
||||
cron = (model) ->
|
||||
user = model.at '_user'
|
||||
today = +new Date
|
||||
daysPassed = helpers.daysBetween(today, user.get('lastCron'))
|
||||
daysPassed = helpers.daysBetween(user.get('lastCron'), today, user.get('preferences.dayStart'))
|
||||
if daysPassed > 0
|
||||
batch = new character.BatchUpdate(model)
|
||||
batch.startTransaction()
|
||||
|
||||
Reference in New Issue
Block a user