Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stephen Mathieson
committed
Aug 8, 2013
0 parents
commit 7b7d0d7
Showing
9 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
components | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
components | ||
build | ||
test | ||
component.json | ||
Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
# 0.1.0 | ||
|
||
- initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
build: components index.js | ||
@component build --dev | ||
|
||
components: component.json | ||
@component install --dev | ||
|
||
clean: | ||
rm -fr build components template.js | ||
|
||
.PHONY: clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
# days-in-month | ||
|
||
get the number of days in the given month (gregorian calander) | ||
|
||
## Installation | ||
|
||
Install with [component(1)](http://component.io): | ||
|
||
$ component install stephenmathieson/days-in-month | ||
|
||
## API | ||
|
||
### `days(new Date())` | ||
|
||
### `days(8)` | ||
|
||
### `days(2013, 8)` | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "days-in-month", | ||
"repo": "stephenmathieson/days-in-month", | ||
"description": "get the number of days in the given month (gregorian calander)", | ||
"version": "0.0.1", | ||
"keywords": [], | ||
"dependencies": {}, | ||
"development": {}, | ||
"license": "MIT", | ||
"main": "index.js", | ||
"scripts": [ | ||
"index.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
/** | ||
* Get the number of days in a month | ||
* | ||
* @api private | ||
* @param {Date|Number} year | ||
* @param {Number} [month] | ||
* @return {Number} | ||
*/ | ||
module.exports = function (year, month) { | ||
|
||
var date; | ||
|
||
if (year instanceof Date) { | ||
date = new Date(year.getFullYear(), year.getMonth() + 1, 0); | ||
} else if (arguments.length === 1) { | ||
date = new Date(new Date().getFullYear(), year, 0); | ||
} else { | ||
date = new Date(year, month, 0); | ||
} | ||
|
||
return date.getDate(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "days-in-month", | ||
"version": "0.0.0", | ||
"description": "get the number of days in the given month", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/stephenmathieson/days-in-month.git" | ||
}, | ||
"keywords": [ | ||
"date", | ||
"days", | ||
"month" | ||
], | ||
"author": "stephen mathieson", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/stephenmathieson/days-in-month/issues" | ||
}, | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
var days, | ||
assert = require('assert'); | ||
|
||
try { | ||
// component | ||
days = require('days-in-month'); | ||
} catch (e) { | ||
// node | ||
days = require('..'); | ||
} | ||
|
||
describe('days-in-month', function () { | ||
it('should work when provided a Date', function () { | ||
assert(days(new Date(2013, 7, 8)) === 31); | ||
}); | ||
|
||
it('should assume the current year when only provided a month', function () { | ||
assert(days(8) === 31); | ||
}); | ||
|
||
it('should work when provided a year and month', function () { | ||
assert(days(2013, 8) === 31); | ||
}); | ||
|
||
it('should account for leap years', function () { | ||
assert(days(2000, 2) === 29); | ||
assert(days(2076, 2) === 29); | ||
assert(days(1804, 2) === 29); | ||
assert(days(new Date(2000, 1, 1)) === 29); | ||
}); | ||
}); |