calendar-month
Advanced tools
Comparing version 1.0.4 to 1.0.5
32
month.js
@@ -6,6 +6,2 @@ | ||
function getDayOfWeek(year, month, day) { | ||
return parseInt(getDate(year, month, day).getUTCDay(), 10); | ||
} | ||
function addPreviousDays (list, i, n, month, year) { | ||
@@ -72,3 +68,2 @@ for(; i <= n ; i++ ) list.push({ | ||
year: year, | ||
day: getDayOfWeek(year, month, i), | ||
current: true | ||
@@ -127,13 +122,24 @@ }); | ||
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); | ||
var columns = [], column; | ||
for( var c = 0; c < 7; c++ ) { | ||
column = []; | ||
columns.push(column); | ||
for( var r = 0; r < 6; r++ ) { | ||
column.push( this.days[ r*7 + c ] ); | ||
} | ||
} | ||
return bins; | ||
return columns; | ||
// 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.4", | ||
"version": "1.0.5", | ||
"description": "vanillajs month data handler", | ||
@@ -5,0 +5,0 @@ "main": "month.js", |
@@ -19,3 +19,3 @@ | ||
> example: | ||
#### Examples | ||
@@ -92,3 +92,3 @@ ``` js | ||
> example: return dates grouped by day of week | ||
##### `previous()`, `next()` | ||
@@ -98,2 +98,20 @@ ``` js | ||
// months from 0 (january) ... to 11 (december) | ||
var m = new Month(2017, 5); | ||
m.previous(); | ||
// return equivalent to `new Month(2017, 4)` | ||
m.next(); | ||
// return equivalent to `new Month(2017, 6)` | ||
``` | ||
##### `getColumns()` | ||
> dates grouped by day of week | ||
``` js | ||
var Month = require('./month'); | ||
// startDay to set Sunday as first week day (default) | ||
@@ -100,0 +118,0 @@ Month.setFirstWeekDay(0); |
@@ -6,2 +6,6 @@ /* global describe it beforeEach */ | ||
function _monthDay2Slash (d) { | ||
return d.year + '/' + ( d.month + 1 ) + '/' + d.date; | ||
} | ||
function testMonthDates (m, result, sufix) { | ||
@@ -16,3 +20,3 @@ | ||
m.days.forEach(function (d, i) { | ||
assert.strictEqual( dates[i], d.year + '/' + ( d.month + 1 ) + '/' + d.date, 'dates[i]' + ( sufix ? ('-' + sufix) : '' ) ); | ||
assert.strictEqual( dates[i], _monthDay2Slash(d), 'dates[' + i + ']' + ( sufix ? ('-' + sufix) : '' ) ); | ||
}); | ||
@@ -120,22 +124,14 @@ | ||
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 ); | ||
assert.deepStrictEqual( new Month(2017, 5).getColumns().map(function (column) { | ||
return column.map(_monthDay2Slash); | ||
}), [ | ||
[ '2017/5/28', '2017/6/4', '2017/6/11', '2017/6/18', '2017/6/25', '2017/7/2' ], | ||
[ '2017/5/29', '2017/6/5', '2017/6/12', '2017/6/19', '2017/6/26', '2017/7/3' ], | ||
[ '2017/5/30', '2017/6/6', '2017/6/13', '2017/6/20', '2017/6/27', '2017/7/4' ], | ||
[ '2017/5/31', '2017/6/7', '2017/6/14', '2017/6/21', '2017/6/28', '2017/7/5' ], | ||
[ '2017/6/1', '2017/6/8', '2017/6/15', '2017/6/22', '2017/6/29', '2017/7/6' ], | ||
[ '2017/6/2', '2017/6/9', '2017/6/16', '2017/6/23', '2017/6/30', '2017/7/7' ], | ||
[ '2017/6/3', '2017/6/10', '2017/6/17', '2017/6/24', '2017/7/1', '2017/7/8' ] | ||
] ); | ||
}); | ||
@@ -258,22 +254,13 @@ | ||
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 ); | ||
assert.deepStrictEqual( new Month(2017, 5).getColumns().map(function (column) { | ||
return column.map(_monthDay2Slash); | ||
}), [ | ||
[ '2017/5/29', '2017/6/5', '2017/6/12', '2017/6/19', '2017/6/26', '2017/7/3' ], | ||
[ '2017/5/30', '2017/6/6', '2017/6/13', '2017/6/20', '2017/6/27', '2017/7/4' ], | ||
[ '2017/5/31', '2017/6/7', '2017/6/14', '2017/6/21', '2017/6/28', '2017/7/5' ], | ||
[ '2017/6/1', '2017/6/8', '2017/6/15', '2017/6/22', '2017/6/29', '2017/7/6' ], | ||
[ '2017/6/2', '2017/6/9', '2017/6/16', '2017/6/23', '2017/6/30', '2017/7/7' ], | ||
[ '2017/6/3', '2017/6/10', '2017/6/17', '2017/6/24', '2017/7/1', '2017/7/8' ], | ||
[ '2017/6/4', '2017/6/11', '2017/6/18', '2017/6/25', '2017/7/2', '2017/7/9' ], | ||
] ); | ||
@@ -280,0 +267,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
183
24863
9
414