calendar-month
Advanced tools
Comparing version 1.0.3 to 1.0.4
17
month.js
@@ -6,2 +6,6 @@ | ||
function getDayOfWeek(year, month, day) { | ||
return parseInt(getDate(year, month, day).getUTCDay(), 10); | ||
} | ||
function addPreviousDays (list, i, n, month, year) { | ||
@@ -68,2 +72,3 @@ for(; i <= n ; i++ ) list.push({ | ||
year: year, | ||
day: getDayOfWeek(year, month, i), | ||
current: true | ||
@@ -121,2 +126,14 @@ }); | ||
Month.prototype.getColumns = function() { | ||
var bins = Array.apply(null, new Array(7)).map(function() { | ||
return []; | ||
}); | ||
for (var i = 0; i < this.days.length; i++) { | ||
var day = this.days[i]; | ||
var dow = getDayOfWeek(day.year, day.month, day.date); | ||
bins[dow].push(day); | ||
} | ||
return bins; | ||
}; | ||
module.exports = Month; |
{ | ||
"name": "calendar-month", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "vanillajs month data handler", | ||
@@ -5,0 +5,0 @@ "main": "month.js", |
@@ -90,1 +90,76 @@ | ||
``` | ||
> example: return dates grouped by day of week | ||
``` js | ||
var Month = require('./month'); | ||
// startDay to set Sunday as first week day (default) | ||
Month.setFirstWeekDay(0); | ||
// months from 0 (january) ... to 11 (december) | ||
new Month(2017, 5).getColumns(); | ||
``` | ||
> returns: | ||
``` js | ||
[ | ||
[ | ||
{ date: 28, month: 4, year: 2017, previous: true }, | ||
{ date: 4, month: 5, year: 2017, current: true }, | ||
{ date: 11, month: 5, year: 2017, current: true }, | ||
{ date: 18, month: 5, year: 2017, current: true }, | ||
{ date: 25, month: 5, year: 2017, current: true }, | ||
{ date: 2, month: 6, year: 2017, next: true } | ||
], | ||
[ | ||
{ date: 29, month: 4, year: 2017, previous: true }, | ||
{ date: 5, month: 5, year: 2017, current: true }, | ||
{ date: 12, month: 5, year: 2017, current: true }, | ||
{ date: 19, month: 5, year: 2017, current: true }, | ||
{ date: 26, month: 5, year: 2017, current: true }, | ||
{ date: 3, month: 6, year: 2017, next: true } | ||
], | ||
[ | ||
{ date: 30, month: 4, year: 2017, previous: true }, | ||
{ date: 6, month: 5, year: 2017, current: true }, | ||
{ date: 13, month: 5, year: 2017, current: true }, | ||
{ date: 20, month: 5, year: 2017, current: true }, | ||
{ date: 27, month: 5, year: 2017, current: true }, | ||
{ date: 4, month: 6, year: 2017, next: true } | ||
], | ||
[ | ||
{ date: 31, month: 4, year: 2017, previous: true }, | ||
{ date: 7, month: 5, year: 2017, current: true }, | ||
{ date: 14, month: 5, year: 2017, current: true }, | ||
{ date: 21, month: 5, year: 2017, current: true }, | ||
{ date: 28, month: 5, year: 2017, current: true }, | ||
{ date: 5, month: 6, year: 2017, next: true } | ||
], | ||
[ | ||
{ date: 1, month: 5, year: 2017, current: true }, | ||
{ date: 8, month: 5, year: 2017, current: true }, | ||
{ date: 15, month: 5, year: 2017, current: true }, | ||
{ date: 22, month: 5, year: 2017, current: true }, | ||
{ date: 29, month: 5, year: 2017, current: true }, | ||
{ date: 6, month: 6, year: 2017, next: true } | ||
], | ||
[ | ||
{ date: 2, month: 5, year: 2017, current: true }, | ||
{ date: 9, month: 5, year: 2017, current: true }, | ||
{ date: 16, month: 5, year: 2017, current: true }, | ||
{ date: 23, month: 5, year: 2017, current: true }, | ||
{ date: 30, month: 5, year: 2017, current: true }, | ||
{ date: 7, month: 6, year: 2017, next: true } | ||
], | ||
[ | ||
{ date: 3, month: 5, year: 2017, current: true }, | ||
{ date: 10, month: 5, year: 2017, current: true }, | ||
{ date: 17, month: 5, year: 2017, current: true }, | ||
{ date: 24, month: 5, year: 2017, current: true }, | ||
{ date: 1, month: 6, year: 2017, next: true }, | ||
{ date: 8, month: 6, year: 2017, next: true } | ||
] | ||
] | ||
``` |
@@ -116,2 +116,26 @@ /* global describe it beforeEach */ | ||
it('june 2017 getColumns()', function () { | ||
var m = new Month(2017, 5); | ||
m = m.getColumns(); | ||
var expected = { | ||
'0': [ '2017/4/28', '2017/5/4', '2017/5/11', '2017/5/18', '2017/5/25', '2017/6/2' ], | ||
'1': [ '2017/4/29', '2017/5/5', '2017/5/12', '2017/5/19', '2017/5/26', '2017/6/3' ], | ||
'2': [ '2017/4/30', '2017/5/6', '2017/5/13', '2017/5/20', '2017/5/27', '2017/6/4' ], | ||
'3': [ '2017/4/31', '2017/5/7', '2017/5/14', '2017/5/21', '2017/5/28', '2017/6/5' ], | ||
'4': [ '2017/5/1', '2017/5/8', '2017/5/15', '2017/5/22', '2017/5/29', '2017/6/6' ], | ||
'5': [ '2017/5/2', '2017/5/9', '2017/5/16', '2017/5/23', '2017/5/30', '2017/6/7' ], | ||
'6': [ '2017/5/3', '2017/5/10', '2017/5/17', '2017/5/24', '2017/6/1', '2017/6/8' ] | ||
}; | ||
var actual = {}; | ||
var days = Object.keys(m); | ||
days.forEach(function(day) { | ||
var arr = m[day].map(function(d) { | ||
return d.year + '/' + d.month + '/' + d.date; | ||
}); | ||
actual[day] = arr; | ||
}); | ||
assert.deepStrictEqual( actual, expected ); | ||
}); | ||
it('january 2018', function () { | ||
@@ -227,5 +251,30 @@ | ||
testMonthCounters(m, test_data['2017-12'].counters, 'previous' ); | ||
}); | ||
it('june 2017 getColumns()', function () { | ||
var m = new Month(2017, 5); | ||
m = m.getColumns(); | ||
var expected = { | ||
'0': [ '2017/5/4', '2017/5/11', '2017/5/18', '2017/5/25', '2017/6/2', '2017/6/9' ], | ||
'1': [ '2017/4/29', '2017/5/5', '2017/5/12', '2017/5/19', '2017/5/26', '2017/6/3' ], | ||
'2': [ '2017/4/30', '2017/5/6', '2017/5/13', '2017/5/20', '2017/5/27', '2017/6/4' ], | ||
'3': [ '2017/4/31', '2017/5/7', '2017/5/14', '2017/5/21', '2017/5/28', '2017/6/5' ], | ||
'4': [ '2017/5/1', '2017/5/8', '2017/5/15', '2017/5/22', '2017/5/29', '2017/6/6' ], | ||
'5': [ '2017/5/2', '2017/5/9', '2017/5/16', '2017/5/23', '2017/5/30', '2017/6/7' ], | ||
'6': [ '2017/5/3', '2017/5/10', '2017/5/17', '2017/5/24', '2017/6/1', '2017/6/8' ] | ||
}; | ||
var actual = {}; | ||
var days = Object.keys(m); | ||
days.forEach(function(day) { | ||
var arr = m[day].map(function(d) { | ||
return d.year + '/' + d.month + '/' + d.date; | ||
}); | ||
actual[day] = arr; | ||
}); | ||
assert.deepStrictEqual( actual, expected ); | ||
}); | ||
it('june 2018', function () { | ||
@@ -232,0 +281,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
69377
11
1747
165
1