mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-05-25 23:25:51 +00:00
startOfDay: if between midnight and custom day start, jump back to previous day
This commit is contained in:
parent
d9e8c53d9a
commit
3bd81abda3
2 changed files with 6 additions and 2 deletions
|
|
@ -31,7 +31,10 @@ api.startOfWeek = api.startOfWeek = (options={}) ->
|
|||
|
||||
api.startOfDay = (options={}) ->
|
||||
o = sanitizeOptions(options)
|
||||
moment(o.now).startOf('day').add('h', o.dayStart)
|
||||
dayStart = moment(o.now).startOf('day').add('h', o.dayStart)
|
||||
# if between midnight and Custom Day Start, jump back to previous day
|
||||
dayStart.subtract('day', 1) if moment(o.now).isBefore(dayStart)
|
||||
return dayStart
|
||||
|
||||
dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s'}
|
||||
|
||||
|
|
@ -1239,4 +1242,3 @@ api.wrap = (user, main=true) ->
|
|||
get: ->
|
||||
tasks = user.habits.concat(user.dailys).concat(user.todos).concat(user.rewards)
|
||||
_.object(_.pluck(tasks, "id"), tasks)
|
||||
|
||||
|
|
|
|||
|
|
@ -487,6 +487,8 @@ describe 'Helper', ->
|
|||
expect(shared.startOfDay({now: new Date(2013, 0, 1, 0)}).format('YYYY-MM-DD HH:mm')).to.eql '2013-01-01 00:00'
|
||||
expect(shared.startOfDay({now: new Date(2013, 0, 1, 5)}).format('YYYY-MM-DD HH:mm')).to.eql '2013-01-01 00:00'
|
||||
expect(shared.startOfDay({now: new Date(2013, 0, 1, 23, 59, 59)}).format('YYYY-MM-DD HH:mm')).to.eql '2013-01-01 00:00'
|
||||
# between midnight and custom day start
|
||||
expect(shared.startOfDay({now: new Date(2013, 0, 2, 2), dayStart: 4}).format('YYYY-MM-DD HH:mm')).to.eql '2013-01-01 04:00'
|
||||
|
||||
it 'counts pets', ->
|
||||
pets = {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue