Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Mathieson committed Aug 8, 2013
0 parents commit 7b7d0d7
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
components
build
5 changes: 5 additions & 0 deletions .npmignore
@@ -0,0 +1,5 @@
components
build
test
component.json
Makefile
4 changes: 4 additions & 0 deletions History.md
@@ -0,0 +1,4 @@

# 0.1.0

- initial release
11 changes: 11 additions & 0 deletions Makefile
@@ -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
22 changes: 22 additions & 0 deletions Readme.md
@@ -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
14 changes: 14 additions & 0 deletions component.json
@@ -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"
]
}
23 changes: 23 additions & 0 deletions index.js
@@ -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();
};
27 changes: 27 additions & 0 deletions package.json
@@ -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": {}
}
32 changes: 32 additions & 0 deletions test/index.js
@@ -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);
});
});

0 comments on commit 7b7d0d7

Please sign in to comment.