json-calendar
Advanced tools
Comparing version 1.2.2 to 1.3.0
35
index.js
@@ -29,10 +29,9 @@ "use strict"; | ||
class Calendar { | ||
constructor(options) { | ||
options = options || {}; | ||
constructor(params) { | ||
params = params || {}; | ||
const today = new Date(); | ||
const today = params.today || new Date(); | ||
this.monthNames = MONTHNAMES; | ||
this.weeks = []; | ||
this.data = {}; | ||
this.today = new Date( | ||
@@ -44,3 +43,3 @@ today.getFullYear(), | ||
var data = this.data; | ||
var data = {}; | ||
@@ -58,16 +57,6 @@ var defaults = { | ||
var options = Object.assign({}, defaults, params); | ||
var classNames, date, day, firstDate, lastDate, monthDays, week; | ||
for (var prop in defaults) { | ||
if ( | ||
defaults.hasOwnProperty(prop) && | ||
!options.hasOwnProperty(prop) && | ||
defaults[prop] | ||
) { | ||
options[prop] = defaults[prop]; | ||
} | ||
} | ||
// options["month_name_text"] ||= Date::MONTHNAMES[options["month"]] | ||
firstDate = new Date(options.year, options.monthIndex, 1); | ||
@@ -78,12 +67,2 @@ lastDate = new Date(options.year, options.monthIndex + 1, 0); | ||
// firstDayOfWeek = options.firstDayOfWeek; | ||
// lastDayOfWeek = this.getLastDayOfWeek(options.firstDayOfWeek); | ||
// Shift the day names array if the first day of the week isn't Sunday. | ||
// if (options.firstDayOfWeek < 0) { | ||
// for (i = 0; i < firstDayOfWeek; i++) { | ||
// DAYNAMES.push(DAYNAMES.shift()); | ||
// } | ||
// } | ||
// Start storing the JSON data into an object. | ||
@@ -167,2 +146,4 @@ data.dayNames = []; | ||
data.currentMonth = this.getMonthName(firstDate.getMonth()); | ||
this.data = data; | ||
} | ||
@@ -169,0 +150,0 @@ |
{ | ||
"name": "json-calendar", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "A data model for displaying dates and date ranges on a calendar interface.", | ||
@@ -22,3 +22,3 @@ "keywords": [ | ||
"lint": "eslint index.js", | ||
"test": "jest", | ||
"test": "TZ=America/Phoenix jest", | ||
"verify": "npm run lint && npm t" | ||
@@ -25,0 +25,0 @@ }, |
16
test.js
@@ -14,2 +14,5 @@ var JsonCalendar = require("./"); | ||
test("has today's date", () => { | ||
const today = new Date(); | ||
expect(subject.today instanceof Date).toBe(true); | ||
expect(subject.today.getFullYear()).toBe(today.getFullYear()); | ||
expect(subject.today.getHours()).toBe(0); | ||
@@ -20,4 +23,13 @@ expect(subject.today.getMinutes()).toBe(0); | ||
test("has date for today", () => { | ||
expect(subject.today instanceof Date).toBe(true); | ||
test("has given date", () => { | ||
var today = new Date(2018, 12, 31, 0, 0); | ||
console.log("today >> ", today); | ||
var calendar = new JsonCalendar({ today }); | ||
console.log("cal >>", calendar.today); | ||
expect(calendar.today instanceof Date).toBe(true); | ||
expect(calendar.today.getFullYear()).toBe(today.getFullYear()); | ||
expect(calendar.today.getMonth()).toBe(today.getMonth()); | ||
expect(calendar.today.getHours()).toBe(0); | ||
expect(calendar.today.getMinutes()).toBe(0); | ||
expect(calendar.today.getHours()).toBe(0); | ||
}); | ||
@@ -24,0 +36,0 @@ |
220215
6273