Comparing version 0.1.0 to 0.2.0
21
index.js
@@ -31,3 +31,4 @@ var moment = require('moment'); | ||
day: moment.day(), | ||
year: moment.year() | ||
year: moment.year(), | ||
dayOfYear: moment.dayOfYear() | ||
}; | ||
@@ -46,2 +47,6 @@ }; | ||
if (opts.withStaticLength === undefined) { | ||
opts.withStaticLength = false; | ||
} | ||
// we will fill in this array | ||
@@ -91,3 +96,15 @@ var weeks = []; | ||
} | ||
weeks[weeks.length-1] = w; | ||
weeks[weeks.length - 1] = w; | ||
// if 5 weeks have been constructed, add one more | ||
// to keep consistency with other months with 6 | ||
// weeks constructed | ||
if (weeks.length === 5 && opts.withStaticLength) { | ||
w = [] | ||
while (w.length < 7) { | ||
w.push(this.createDay(m)); | ||
m.add(1, 'day'); | ||
} | ||
weeks.push(w); | ||
} | ||
} | ||
@@ -94,0 +111,0 @@ |
{ | ||
"name": "calendarjs", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Javascript component to creating calendars.", | ||
@@ -21,3 +21,3 @@ "main": "index.js", | ||
"assert": "^1.1.1", | ||
"mocha": "^1.20.0" | ||
"mocha": "^5.0.0" | ||
}, | ||
@@ -24,0 +24,0 @@ "dependencies": { |
@@ -9,39 +9,39 @@ ## calendarjs | ||
You will get something like this: | ||
[ [ { month: 6, date: 1, day: 0, year: 2014 }, | ||
{ month: 6, date: 2, day: 1, year: 2014 }, | ||
{ month: 6, date: 3, day: 2, year: 2014 }, | ||
{ month: 6, date: 4, day: 3, year: 2014 }, | ||
{ month: 6, date: 5, day: 4, year: 2014 }, | ||
{ month: 6, date: 6, day: 5, year: 2014 }, | ||
{ month: 6, date: 7, day: 6, year: 2014 } ], | ||
[ { month: 6, date: 8, day: 0, year: 2014 }, | ||
{ month: 6, date: 9, day: 1, year: 2014 }, | ||
{ month: 6, date: 10, day: 2, year: 2014 }, | ||
{ month: 6, date: 11, day: 3, year: 2014 }, | ||
{ month: 6, date: 12, day: 4, year: 2014 }, | ||
{ month: 6, date: 13, day: 5, year: 2014 }, | ||
{ month: 6, date: 14, day: 6, year: 2014 } ], | ||
[ { month: 6, date: 15, day: 0, year: 2014 }, | ||
{ month: 6, date: 16, day: 1, year: 2014 }, | ||
{ month: 6, date: 17, day: 2, year: 2014 }, | ||
{ month: 6, date: 18, day: 3, year: 2014 }, | ||
{ month: 6, date: 19, day: 4, year: 2014 }, | ||
{ month: 6, date: 20, day: 5, year: 2014 }, | ||
{ month: 6, date: 21, day: 6, year: 2014 } ], | ||
[ { month: 6, date: 22, day: 0, year: 2014 }, | ||
{ month: 6, date: 23, day: 1, year: 2014 }, | ||
{ month: 6, date: 24, day: 2, year: 2014 }, | ||
{ month: 6, date: 25, day: 3, year: 2014 }, | ||
{ month: 6, date: 26, day: 4, year: 2014 }, | ||
{ month: 6, date: 27, day: 5, year: 2014 }, | ||
{ month: 6, date: 28, day: 6, year: 2014 } ], | ||
[ { month: 6, date: 29, day: 0, year: 2014 }, | ||
{ month: 6, date: 30, day: 1, year: 2014 }, | ||
{ month: 7, date: 1, day: 2, year: 2014 }, | ||
{ month: 7, date: 2, day: 3, year: 2014 }, | ||
{ month: 7, date: 3, day: 4, year: 2014 }, | ||
{ month: 7, date: 4, day: 5, year: 2014 }, | ||
{ month: 7, date: 5, day: 6, year: 2014 } ] ] | ||
``` | ||
[ [ { month: 4, date: 30, day: 0, year: 2017, dayOfYear: 120 }, | ||
{ month: 5, date: 1, day: 1, year: 2017, dayOfYear: 121 }, | ||
{ month: 5, date: 2, day: 2, year: 2017, dayOfYear: 122 }, | ||
{ month: 5, date: 3, day: 3, year: 2017, dayOfYear: 123 }, | ||
{ month: 5, date: 4, day: 4, year: 2017, dayOfYear: 124 }, | ||
{ month: 5, date: 5, day: 5, year: 2017, dayOfYear: 125 }, | ||
{ month: 5, date: 6, day: 6, year: 2017, dayOfYear: 126 } ], | ||
[ { month: 5, date: 7, day: 0, year: 2017, dayOfYear: 127 }, | ||
{ month: 5, date: 8, day: 1, year: 2017, dayOfYear: 128 }, | ||
{ month: 5, date: 9, day: 2, year: 2017, dayOfYear: 129 }, | ||
{ month: 5, date: 10, day: 3, year: 2017, dayOfYear: 130 }, | ||
{ month: 5, date: 11, day: 4, year: 2017, dayOfYear: 131 }, | ||
{ month: 5, date: 12, day: 5, year: 2017, dayOfYear: 132 }, | ||
{ month: 5, date: 13, day: 6, year: 2017, dayOfYear: 133 } ], | ||
[ { month: 5, date: 14, day: 0, year: 2017, dayOfYear: 134 }, | ||
{ month: 5, date: 15, day: 1, year: 2017, dayOfYear: 135 }, | ||
{ month: 5, date: 16, day: 2, year: 2017, dayOfYear: 136 }, | ||
{ month: 5, date: 17, day: 3, year: 2017, dayOfYear: 137 }, | ||
{ month: 5, date: 18, day: 4, year: 2017, dayOfYear: 138 }, | ||
{ month: 5, date: 19, day: 5, year: 2017, dayOfYear: 139 }, | ||
{ month: 5, date: 20, day: 6, year: 2017, dayOfYear: 140 } ], | ||
[ { month: 5, date: 21, day: 0, year: 2017, dayOfYear: 141 }, | ||
{ month: 5, date: 22, day: 1, year: 2017, dayOfYear: 142 }, | ||
{ month: 5, date: 23, day: 2, year: 2017, dayOfYear: 143 }, | ||
{ month: 5, date: 24, day: 3, year: 2017, dayOfYear: 144 }, | ||
{ month: 5, date: 25, day: 4, year: 2017, dayOfYear: 145 }, | ||
{ month: 5, date: 26, day: 5, year: 2017, dayOfYear: 146 }, | ||
{ month: 5, date: 27, day: 6, year: 2017, dayOfYear: 147 } ], | ||
[ { month: 5, date: 28, day: 0, year: 2017, dayOfYear: 148 }, | ||
{ month: 5, date: 29, day: 1, year: 2017, dayOfYear: 149 }, | ||
{ month: 5, date: 30, day: 2, year: 2017, dayOfYear: 150 }, | ||
{ month: 5, date: 31, day: 3, year: 2017, dayOfYear: 151 }, | ||
{ month: 6, date: 1, day: 4, year: 2017, dayOfYear: 152 }, | ||
{ month: 6, date: 2, day: 5, year: 2017, dayOfYear: 153 }, | ||
{ month: 6, date: 3, day: 6, year: 2017, dayOfYear: 154 } ] ] | ||
``` | ||
### Install | ||
@@ -66,2 +66,2 @@ | ||
MIT. | ||
MIT. |
@@ -6,6 +6,5 @@ var Calendar = require('../index'); | ||
var calendar = new Calendar(2014, 6); // June 2014 | ||
var calendar = new Calendar(2017, 2); // Feb 2017 | ||
var cal = calendar.generate(); | ||
it('should give me a calendar', function() { | ||
@@ -29,2 +28,21 @@ assert.notEqual(cal.length, 0); | ||
}); | ||
it('should return a proper first day', function() { | ||
assert.equal(cal[0][0].year, 2017) | ||
assert.equal(cal[0][0].month, 1) | ||
assert.equal(cal[0][0].date, 29) | ||
assert.equal(cal[0][0].dayOfYear, 29) | ||
}); | ||
it('should return a proper last day', function() { | ||
assert.equal(cal[4][6].year, 2017) | ||
assert.equal(cal[4][6].month, 3) | ||
assert.equal(cal[4][6].date, 4) | ||
assert.equal(cal[4][6].dayOfYear, 63) | ||
}); | ||
it('should have 6 weeks of data', function () { | ||
var cal2 = calendar.generate({ withStaticLength: true }); | ||
assert.equal(cal2.length, 6) | ||
}); | ||
}); |
7370
131
66
5