into days orderly

This commit is contained in:
Radek Stepan 2013-08-13 16:49:52 +01:00
parent bb3ce0fcc2
commit 36f3c1cff5
2 changed files with 6 additions and 3 deletions

View File

@ -54,7 +54,7 @@ module.exports =
catch err
return cb err, warnings
# Map a collection of closed issues into days.
# Map a collection of closed issues into days (does not assume coll to be sorted).
'into_days': (collection, cb) ->
days = {}
for issue in collection
@ -63,8 +63,11 @@ module.exports =
return "Issue ##{number} does not have a `closed_at` parameter" unless closed_at
unless matches = closed_at.match /^(\d{4}-\d{2}-\d{2})T(.*)/
return "Issue ##{number} does not match the `closed_at` pattern"
# Explode the matches.
[ date, time ] = matches[1...]
# Init the date?
days[date] ?= []
days[date].push issue
# Insert into an already sorted array.
days[date].splice _.sortedIndex(days[date], issue, 'closed_at'), 0, issue
cb null, days

View File

@ -192,8 +192,8 @@ module.exports =
assert.ifError err
assert.deepEqual data,
'2013-05-09': [
{ number: 1, closed_at: '2013-05-09T10:04:53Z' }
{ number: 2, closed_at: '2013-05-09T09:04:53Z' }
{ number: 1, closed_at: '2013-05-09T10:04:53Z' }
]
'2013-05-10': [
{ number: 3, closed_at: '2013-05-10T09:04:53Z' }