calendar-month
Advanced tools
Comparing version 1.0.1 to 1.0.2
73
month.js
function getDate(year, month, day) { | ||
return new Date(Date.UTC(year, month, day)); | ||
} | ||
function addPreviousDays (list, i, n, month, year) { | ||
for(; i <= n ; i++ ) list.push({ | ||
date: i, | ||
month: month, | ||
year: year, | ||
previous: true | ||
}); | ||
} | ||
function addNextDays (list, i, n, month, year) { | ||
for(; i <= n ; i++ ) list.push({ | ||
date: i, | ||
month: month, | ||
year: year, | ||
next: true | ||
}); | ||
} | ||
function monthInformation(year, month, m, start_day){ | ||
@@ -7,11 +29,11 @@ | ||
var i, n, | ||
d = new Date(year, month, 1), | ||
previous_month_d = new Date(year, month, 0), | ||
month_last_day = new Date(year, month + 1, 0), | ||
next_month_d = new Date(year, month + 1, 1); | ||
d = getDate(year, month, 1), | ||
previous_month_d = getDate(year, month, 0), | ||
month_last_day = getDate(year, month + 1, 0), | ||
next_month_d = getDate(year, month + 1, 1); | ||
start_day = start_day || 0; | ||
var last_day = previous_month_d.getDate(); | ||
var last_week_day = previous_month_d.getDay(); | ||
var last_day = previous_month_d.getUTCDate(); | ||
var last_week_day = previous_month_d.getUTCDay(); | ||
@@ -22,7 +44,8 @@ m.meta = { | ||
last_week_day: last_week_day, | ||
week_day: d.getDay(), | ||
week_day: d.getUTCDay(), | ||
month_last_day: month_last_day | ||
}; | ||
m.year = d.getFullYear(); | ||
m.month = d.getMonth(); | ||
m.year = d.getUTCFullYear(); | ||
m.month = d.getUTCMonth(); | ||
@@ -32,11 +55,12 @@ var list = [], lastMonthFirstWeekDay = last_day - last_week_day + start_day; | ||
// previous month days | ||
for( i = 0, n = last_week_day + 1 - start_day ; i < n ; i++ ) list.push({ | ||
date: lastMonthFirstWeekDay + i, | ||
month: previous_month_d.getMonth(), | ||
year: previous_month_d.getFullYear(), | ||
previous: true | ||
}); | ||
addPreviousDays( | ||
list, | ||
lastMonthFirstWeekDay, | ||
last_week_day - start_day + lastMonthFirstWeekDay, | ||
previous_month_d.getUTCMonth(), | ||
previous_month_d.getUTCFullYear() | ||
); | ||
// current month days | ||
for( i = 1, n = month_last_day.getDate() ; i <= n ; i++ ) list.push({ | ||
for( i = 1, n = month_last_day.getUTCDate() ; i <= n ; i++ ) list.push({ | ||
date: i, | ||
@@ -49,8 +73,9 @@ month: month, | ||
// next month days | ||
for( i = 1, n = 42 - list.length ; i <= n ; i++ ) list.push({ | ||
date: i, | ||
month: next_month_d.getMonth(), | ||
year: next_month_d.getFullYear(), | ||
next: true | ||
}); | ||
addNextDays( | ||
list, | ||
1, | ||
42 - list.length, | ||
next_month_d.getUTCMonth(), | ||
next_month_d.getUTCFullYear() | ||
); | ||
@@ -69,4 +94,4 @@ m.days = list; | ||
if( year instanceof Date ) { | ||
month = year.getMonth(); | ||
year = year.getFullYear(); | ||
month = year.getUTCMonth(); | ||
year = year.getUTCFullYear(); | ||
} | ||
@@ -73,0 +98,0 @@ |
{ | ||
"name": "calendar-month", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "vanillajs month data handler", | ||
"main": "month.js", | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "make test" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
calendar-month | ||
============== | ||
[![](https://img.shields.io/npm/v/calendar-month.svg)](https://www.npmjs.com/package/calendar-month) [![](https://img.shields.io/bower/v/calendar-month.svg)](http://bower.io/search/?q=calendar-month) | ||
[![npm](https://img.shields.io/npm/v/calendar-month.svg)](https://www.npmjs.com/package/calendar-month) | ||
[![Build Status](https://travis-ci.org/kiltjs/month.svg?branch=master)](https://travis-ci.org/kiltjs/month) | ||
@@ -35,10 +36,11 @@ > node | ||
meta: { | ||
date: '2017-05-31T22:00:00.000Z', | ||
date: '2017-06-01T00:00:00.000Z', | ||
last_day: 31, | ||
last_week_day: 3, | ||
week_day: 4 | ||
week_day: 4, | ||
month_last_day: '2017-06-30T00:00:00.000Z' | ||
}, | ||
year: 2017, | ||
month: 5, | ||
list: [ | ||
days: [ | ||
{ date: 29, month: 4, year: 2017, previous: true }, | ||
@@ -45,0 +47,0 @@ { date: 30, month: 4, year: 2017, previous: true }, |
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
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
11613
10
216
90