https://github.com/indexzero/month-ends
Purposefully simple and dependency free functions for calendar months
https://github.com/indexzero/month-ends
Last synced: about 1 year ago
JSON representation
Purposefully simple and dependency free functions for calendar months
- Host: GitHub
- URL: https://github.com/indexzero/month-ends
- Owner: indexzero
- License: mit
- Created: 2017-10-11T05:05:55.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-18T19:12:31.000Z (over 8 years ago)
- Last Synced: 2024-10-18T21:04:11.817Z (over 1 year ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# month-ends
Purposefully simple and dependency free functions for calendar months
## Usage
#### `monthEnds`
``` js
const monthEnds = require('month-ends');
const start = new Date('2015-01-02');
const end = new Date('2015-04-12');
console.dir(monthEnds(start, end));
// [ [ 2015-01-01T05:00:00.000Z, 2015-01-31T05:00:00.000Z ],
// [ 2015-02-01T05:00:00.000Z, 2015-02-28T05:00:00.000Z ],
// [ 2015-03-01T05:00:00.000Z, 2015-03-31T04:00:00.000Z ],
// [ 2015-04-01T04:00:00.000Z, 2015-04-30T04:00:00.000Z ] ]
```
#### `lastDayOfMonth`
``` js
const { lastDayOfMonth } = require('month-ends');
let anyDay = new Date('2015-06-07');
let end = lastDayOfMonth(anyDay);
console.dir(end.toDateString());
// 'Tue Jun 30 2015'
```
#### `firstDayOfMonth`
``` js
const { firstDayOfMonth } = require('month-ends');
let anyDay = new Date('2015-06-07');
let end = firstDayOfMonth(anyDay);
console.dir(end.toDateString());
// 'Mon Jun 01 2015'
```
#### `firstDayOfNextMonth`
``` js
const { firstDayOfNextMonth } = require('month-ends');
let anyDay = new Date('2015-06-07');
let end = firstDayOfNextMonth(anyDay);
console.dir(end.toDateString());
// 'Wed Jul 01 2015'
```
## Tests
Tests are written with `mocha`, `assume`, and `nyc`. They can be run with
`npm`:
``` sh
npm test
// ...
// ...
// ...
11 passing (25ms)
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | 95.45 | 83.33 | 100 | 100 | |
index.js | 95.45 | 83.33 | 100 | 100 | 43 |
----------|----------|----------|----------|----------|----------------|
```
##### AUTHOR: [Charlie Robbins](https://github.com/indexzero)
##### LICENSE: MIT