Socket
Socket
Sign inDemoInstall

date-fns

Package Overview
Dependencies
0
Maintainers
3
Versions
200
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.17.0 to 1.0.0-alpha1

.codeclimate.yml

4

bower.json
{
"name": "date-fns",
"version": "0.17.0",
"homepage": "https://github.com/kossnocorp/date-fns",
"version": "1.0.0-alpha1",
"homepage": "https://github.com/date-fns/date-fns",
"authors": ["Sasha Koss <kossnocorp@gmail.com>"],

@@ -6,0 +6,0 @@ "description": "Date helpers",

var webpackConfig = require('./webpack')
var browserStackLaunchers = {
chrome: {
'base': 'BrowserStack',
'browser': 'chrome',
'browser_version': '44',
'os': 'Windows',
'os_version': '8.1',
},
firefox: {
'base': 'BrowserStack',
'browser': 'firefox',
'browser_version': '40',
'os': 'Windows',
'os_version': '8.1',
},
ie8: {
'base': 'BrowserStack',
'browser': 'ie',
'browser_version': '8.0',
'os': 'Windows',
'os_version': '7'
},
ie9: {
'base': 'BrowserStack',
'browser': 'ie',
'browser_version': '9.0',
'os': 'Windows',
'os_version': '7'
},
ie10: {
'base': 'BrowserStack',
'browser': 'ie',
'browser_version': '10.0',
'os': 'Windows',
'os_version': '7'
},
ie11: {
'base': 'BrowserStack',
'browser': 'ie',
'browser_version': '11.0',
'os': 'Windows',
'os_version': '8.1'
},
edge: {
'base': 'BrowserStack',
'browser': 'edge',
'browser_version': '12.0',
'os': 'Windows',
'os_version': '10'
}
}
var config = function(config) {
config.set({
frameworks: ['mocha', 'chai-sinon'],
files: ['../test.js'],
preprocessors: {'../test.js': ['webpack']},
frameworks: ['mocha', 'sinon', 'es5-shim'],
files: process.env.USE_STATIC_TESTS ? ['../tmp/tests.js'] : ['../test.js'],
preprocessors: process.env.USE_STATIC_TESTS ? {'../tmp/tests.js': ['sourcemap']} : {'../test.js': ['webpack', 'sourcemap']},
webpack: webpackConfig,

@@ -18,7 +76,15 @@ webpackMiddleware: {

},
browsers: ['PhantomJS'],
reporters: ['mocha'],
// We are limited in the number of parallel VMs in BrowserStack (2)
// and Karma don't know how to limit parallel browser instances
// so waiting time must be insanely high.
browserNoActivityTimeout: process.env.TEST_BROWSERSTACK ? 60 * 60 * 1000 : 10000,
mochaReporter: {
output: process.env.TEST_TZ ? 'minimal' : 'full'
}
},
customLaunchers: process.env.TEST_BROWSERSTACK ? browserStackLaunchers : {},
browsers: process.env.TEST_BROWSERSTACK ? Object.keys(browserStackLaunchers) : ['PhantomJS'],
reporters: process.env.TEST_BROWSERSTACK ? ['dots'] : ['mocha']
})

@@ -25,0 +91,0 @@ }

@@ -5,14 +5,46 @@ var path = require('path')

cache: true,
entry: {
'date_fns': './index.js'
},
output: process.env.NODE_ENV == 'test' ? {path: '/'} : {
path: path.join(process.cwd(), 'dist'),
filename: '[name].js',
library: 'dateFns',
libraryTarget: 'umd'
devtool: process.env.NODE_ENV == 'production' ? 'source-map' : 'inline-source-map',
entry: getEntryConfig(),
output: getOutputConfig(),
module: {
loaders: [
{test: /\.js$/, loader: 'webpack-espower', exclude: /node_modules/},
{test: /\.json$/, loader: 'json'}
]
}
}
function getEntryConfig() {
if (process.env.BUILD_TESTS) {
return {
'tests': './test.js'
}
} else {
return {
'date_fns': './index.js'
}
}
}
function getOutputConfig() {
if (process.env.BUILD_TESTS) {
return {
path: path.join(process.cwd(), 'tmp'),
filename: '[name].js'
}
} else if (process.env.NODE_ENV == 'test') {
return {
path: '/'
}
} else {
return {
path: path.join(process.cwd(), 'dist'),
filename: '[name].js',
library: 'dateFns',
libraryTarget: 'umd'
}
}
}
module.exports = config
module.exports = {
addDays: require('./src/add_days'),
addHours: require('./src/add_hours'),
addISOYears: require('./src/add_iso_years'),
addMilliseconds: require('./src/add_milliseconds'),

@@ -11,2 +12,3 @@ addMinutes: require('./src/add_minutes'),

addYears: require('./src/add_years'),
closestTo: require('./src/closest_to'),
compareAsc: require('./src/compare_asc'),

@@ -18,2 +20,4 @@ compareDesc: require('./src/compare_desc'),

endOfHour: require('./src/end_of_hour'),
endOfISOWeek: require('./src/end_of_iso_week'),
endOfISOYear: require('./src/end_of_iso_year'),
endOfMinute: require('./src/end_of_minute'),

@@ -30,6 +34,7 @@ endOfMonth: require('./src/end_of_month'),

getDaysInMonth: require('./src/get_days_in_month'),
getDaysInYear: require('./src/get_days_in_year'),
getHours: require('./src/get_hours'),
getIsoWeek: require('./src/get_iso_week'),
getIsoWeeksInYear: require('./src/get_iso_weeks_in_year'),
getIsoYear: require('./src/get_iso_year'),
getISOWeek: require('./src/get_iso_week'),
getISOWeeksInYear: require('./src/get_iso_weeks_in_year'),
getISOYear: require('./src/get_iso_year'),
getMilliseconds: require('./src/get_milliseconds'),

@@ -40,3 +45,2 @@ getMinutes: require('./src/get_minutes'),

getSeconds: require('./src/get_seconds'),
getTimeSinceMidnight: require('./src/get_time_since_midnight'),
getYear: require('./src/get_year'),

@@ -53,2 +57,4 @@ isAfter: require('./src/is_after'),

isSameHour: require('./src/is_same_hour'),
isSameISOWeek: require('./src/is_same_iso_week'),
isSameISOYear: require('./src/is_same_iso_year'),
isSameMinute: require('./src/is_same_minute'),

@@ -60,5 +66,19 @@ isSameMonth: require('./src/is_same_month'),

isSameYear: require('./src/is_same_year'),
isThisHour: require('./src/is_this_hour'),
isThisISOWeek: require('./src/is_this_iso_week'),
isThisISOYear: require('./src/is_this_iso_year'),
isThisMinute: require('./src/is_this_minute'),
isThisMonth: require('./src/is_this_month'),
isThisQuarter: require('./src/is_this_quarter'),
isThisSecond: require('./src/is_this_second'),
isThisWeek: require('./src/is_this_week'),
isThisYear: require('./src/is_this_year'),
isToday: require('./src/is_today'),
isTomorrow: require('./src/is_tomorrow'),
isValid: require('./src/is_valid'),
isWeekend: require('./src/is_weekend'),
isWithinRange: require('./src/is_within_range'),
isYesterday: require('./src/is_yesterday'),
lastDayOfISOWeek: require('./src/last_day_of_iso_week'),
lastDayOfISOYear: require('./src/last_day_of_iso_year'),
lastDayOfMonth: require('./src/last_day_of_month'),

@@ -75,4 +95,4 @@ lastDayOfQuarter: require('./src/last_day_of_quarter'),

setHours: require('./src/set_hours'),
setIsoWeek: require('./src/set_iso_week'),
setIsoYear: require('./src/set_iso_year'),
setISOWeek: require('./src/set_iso_week'),
setISOYear: require('./src/set_iso_year'),
setMilliseconds: require('./src/set_milliseconds'),

@@ -86,3 +106,4 @@ setMinutes: require('./src/set_minutes'),

startOfHour: require('./src/start_of_hour'),
startOfIsoYear: require('./src/start_of_iso_year'),
startOfISOWeek: require('./src/start_of_iso_week'),
startOfISOYear: require('./src/start_of_iso_year'),
startOfMinute: require('./src/start_of_minute'),

@@ -96,2 +117,3 @@ startOfMonth: require('./src/start_of_month'),

subHours: require('./src/sub_hours'),
subISOYears: require('./src/sub_iso_years'),
subMilliseconds: require('./src/sub_milliseconds'),

@@ -98,0 +120,0 @@ subMinutes: require('./src/sub_minutes'),

{
"name": "date-fns",
"version": "0.17.0",
"version": "1.0.0-alpha1",
"author": "Sasha Koss <kossnocorp@gmail.com>",
"description": "Date helpers",
"repository": "https://github.com/js-fns/date-fns",
"repository": "https://github.com/date-fns/date-fns",
"engine": {

@@ -17,20 +17,31 @@ "node": ">= 0.11"

"js-beautify": "^1.5.10",
"jsdoc-parse": "^1.1.1",
"json-loader": "^0.5.3",
"karma": "^0.13.9",
"karma-chai-sinon": "^0.1.3",
"karma-browserstack-launcher": "^0.1.5",
"karma-cli": "^0.1.1",
"karma-es5-shim": "0.0.4",
"karma-mocha": "^0.1.9",
"karma-mocha-reporter": "^1.1.1",
"karma-phantomjs-launcher": "^0.1.4",
"karma-phantomjs-launcher": "^0.2.1",
"karma-sinon": "^1.0.4",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.7.0",
"webpack": "^1.12.0"
"power-assert": "^1.0.0",
"webpack": "^1.12.0",
"webpack-espower-loader": "^1.0.1"
},
"scripts": {
"test": "karma start config/karma.js",
"build": "webpack --config ./config/webpack.js",
"test-ci": "npm test -- --single-run",
"test-cross-browser": "env TEST_BROWSERSTACK=true npm test -- --single-run",
"test-tz": "npm run build-tests && ./scripts/test_tz.sh",
"test-tz-extended": "npm run build-tests && ./scripts/test_tz_extended.sh",
"build": "env NODE_ENV=production webpack --config ./config/webpack.js",
"build-tests": "env BUILD_TESTS=true webpack --config ./config/webpack.js",
"lint": "eslint .",
"test-single-run": "./scripts/test_single_run.sh",
"test-tz": "env TEST_TZ=true ./scripts/test_tz.sh",
"test-tz-extended": "env TEST_TZ=true ./scripts/test_tz_extended.sh",
"generate-index": "babel-node ./scripts/generate_index",
"sync-versions": "babel-node ./scripts/sync_versions"
"sync-versions": "babel-node ./scripts/sync_versions",
"docs": "babel-node ./scripts/generate_docs"
}
}
# date-fns
[![](http://img.shields.io/npm/v/date-fns.svg)](https://www.npmjs.org/package/date-fns)
[![Build Status](https://travis-ci.org/js-fns/date-fns.svg)](https://travis-ci.org/js-fns/date-fns)
[![Build Status](https://travis-ci.org/date-fns/date-fns.svg?branch=master)](https://travis-ci.org/date-fns/date-fns)
Date helpers in function-per-file style.
Date helpers in the function-per-file style.
## Installation
### npm
```
npm install --save date-fns
npm install date-fns --save
```
### Bower
```
bower install date-fns
```
## Usage

@@ -24,130 +31,158 @@

Code is fully documented, checkout source for reference.
Code is fully documented, check the source for the reference.
### Common helpers
* [`format`](./src/format.js) - format date.
* [`isFuture`](./src/is_future.js) - is passed date future?
* [`isPast`](./src/is_future.js) - is passed date past?
* [`isEqual`](./src/is_equal.js) - are passed dates equal?
* [`isBefore`](./src/is_before.js) - is first date before second one?
* [`isAfter`](./src/is_after.js) - is first date after second one?
* [`compareAsc`](./src/compare_asc.js) - compares the two dates and returns -1, 0 or 1.
* [`compareDesc`](./src/compare_desc.js) - compares the two dates reverse chronologicaly and returns -1, 0 or 1.
* [`max`]('./src/max') - returns latest date.
* [`min`]('./src/min') - returns earliest date.
* [`parse`](./src/parse.js) - parse ISO-8601-formatted date.
* [`format`](./src/format.js) - format the date.
* [`isFuture`](./src/is_future.js) - is the given date in the future?
* [`isPast`](./src/is_future.js) - is the given date in the past?
* [`isEqual`](./src/is_equal.js) - are the given dates equal?
* [`isBefore`](./src/is_before.js) - is the first date before the second one?
* [`isAfter`](./src/is_after.js) - is the first date after the second one?
* [`compareAsc`](./src/compare_asc.js) - compare the two dates and return -1, 0 or 1.
* [`compareDesc`](./src/compare_desc.js) - compare the two dates reverse chronologically and return -1, 0 or 1.
* [`max`]('./src/max') - return the latest of the given dates.
* [`min`]('./src/min') - return the earliest of the given dates.
* [`closestTo`](./src/closest_to.js) - return a date from the array closest to the given date.
* [`parse`](./src/parse.js) - parse the ISO-8601-formatted date.
* [`isValid`](./src/is_valid.js) - is the given date valid?
### Range helpers
* [`isWithinRange`](./src/is_within_range.js) - is passed date within range?
* [`isWithinRange`](./src/is_within_range.js) - is the given date within the range?
### Milliseconds helpers
* [`getMilliseconds`](./src/get_milliseconds.js) - returns seconds.
* [`setMilliseconds`](./src/set_milliseconds.js) - sets seconds.
* [`addMilliseconds`](./src/add_milliseconds.js) - add milliseconds to passed date.
* [`subMilliseconds`](./src/sub_milliseconds.js) - subtracts milliseconds from passed date.
* [`getTimeSinceMidnight`](./src/get_time_since_midnight.js) - returns time since midnight in milliseconds.
* [`getMilliseconds`](./src/get_milliseconds.js) - get the seconds.
* [`setMilliseconds`](./src/set_milliseconds.js) - set the seconds.
* [`addMilliseconds`](./src/add_milliseconds.js) - add the milliseconds to the given date.
* [`subMilliseconds`](./src/sub_milliseconds.js) - subtract the milliseconds from the given date.
### Seconds helpers
* [`getSeconds`](./src/get_seconds.js) - returns seconds.
* [`setSeconds`](./src/set_seconds.js) - sets seconds.
* [`startOfSecond`](./src/start_of_second.js) - returns start of a second for passed date.
* [`endOfSecond`](./src/end_of_second.js) - returns end of a second for passed date.
* [`addSeconds`](./src/add_seconds.js) - add seconds to passed date.
* [`subSeconds`](./src/sub_seconds.js) - subtracts seconds from passed date.
* [`isSameSecond`](./src/is_same_second.js) - are passed dates have the same second?
* [`getSeconds`](./src/get_seconds.js) - get the seconds.
* [`setSeconds`](./src/set_seconds.js) - set the seconds.
* [`startOfSecond`](./src/start_of_second.js) - return the start of a second for the given date.
* [`endOfSecond`](./src/end_of_second.js) - return the end of a second for the given date.
* [`addSeconds`](./src/add_seconds.js) - add the seconds to the given date.
* [`subSeconds`](./src/sub_seconds.js) - subtract the seconds from the given date.
* [`isSameSecond`](./src/is_same_second.js) - are the given dates in the same second?
* [`isThisSecond`](./src/is_this_second.js) - is the given date in the same second as the current date?
### Minutes helpers
* [`getMinutes`](./src/get_minutes.js) - returns minutes.
* [`setMinutes`](./src/set_minutes.js) - sets minutes.
* [`startOfMinute`](./src/start_of_minute.js) - returns start of a minute for passed date.
* [`endOfMinute`](./src/end_of_minute.js) - returns end of a minute for passed date.
* [`addMinutes`](./src/add_minutes.js) - add minutes to passed date.
* [`subMinutes`](./src/sub_minutes.js) - subtracts minutes from passed date.
* [`isSameMinute`](./src/is_same_minute.js) - are passed dates have the same minute?
* [`getMinutes`](./src/get_minutes.js) - get the minutes.
* [`setMinutes`](./src/set_minutes.js) - set the minutes.
* [`startOfMinute`](./src/start_of_minute.js) - return the start of a minute for the given date.
* [`endOfMinute`](./src/end_of_minute.js) - return the end of a minute for the given date.
* [`addMinutes`](./src/add_minutes.js) - add the minutes to the given date.
* [`subMinutes`](./src/sub_minutes.js) - subtract the minutes from the given date.
* [`isSameMinute`](./src/is_same_minute.js) - are the given dates in the same minute?
* [`isThisMinute`](./src/is_this_minute.js) - is the given date in the same minute as the current date?
### Hours helpers
* [`getHours`](./src/get_hours.js) - returns hours.
* [`setHours`](./src/set_hours.js) - sets hours.
* [`startOfHour`](./src/start_of_hour.js) - returns start of an hour for passed date.
* [`endOfHour`](./src/end_of_hour.js) - returns end of an hour for passed date.
* [`addHours`](./src/add_hours.js) - add hours to passed date.
* [`subHours`](./src/sub_hours.js) - subtracts hours from passed date.
* [`isSameHour`](./src/is_same_hour.js) - are passed dates have the same hour?
* [`getHours`](./src/get_hours.js) - get the hours.
* [`setHours`](./src/set_hours.js) - set the hours.
* [`startOfHour`](./src/start_of_hour.js) - return the start of an hour for the given date.
* [`endOfHour`](./src/end_of_hour.js) - return the end of an hour for the given date.
* [`addHours`](./src/add_hours.js) - add hours to the given date.
* [`subHours`](./src/sub_hours.js) - subtract hours from the given date.
* [`isSameHour`](./src/is_same_hour.js) - are the given dates in the same hour?
* [`isThisHour`](./src/is_this_hour.js) - is the given date in the same hour as the current date?
### Day helpers
* [`getDate`](./src/get_date.js) - returns day of month.
* [`setDate`](./src/set_date.js) - sets day of month.
* [`getDay`](./src/get_day.js) - returns day of week.
* [`setDay`](./src/set_day.js) - sets day of week.
* [`getDayOfYear`](./src/get_day_of_year.js) - returns day of year.
* [`setDayOfYear`](./src/set_day_of_year.js) - sets day of year.
* [`startOfDay`](./src/start_of_day.js) - returns start of a day for passed date.
* [`endOfDay`](./src/end_of_day.js) - returns end of a day for passed date.
* [`addDays`](./src/add_days.js) - add specified number of days to passed date.
* [`subDays`](./src/sub_days.js) - subtract specified number of days from passed date.
* [`isSameDay`](./src/is_same_day.js) - are passed dates has the same day?
* [`isWeekend`](./src/is_weekend.js) - is passed date weekend?
* [`isToday`](./src/is_today.js) - is passed date today?
* [`eachDay`](./src/each_day.js) - returns array of dates within specified range.
* [`differenceInDays`](./src/difference_in_days.js) - returns number of days between dates.
* [`getDate`](./src/get_date.js) - get the day of the month.
* [`setDate`](./src/set_date.js) - set the day of the month.
* [`getDay`](./src/get_day.js) - get the day of the week.
* [`setDay`](./src/set_day.js) - set the day of the week.
* [`getDayOfYear`](./src/get_day_of_year.js) - get the day of the year.
* [`setDayOfYear`](./src/set_day_of_year.js) - set the day of the year.
* [`startOfDay`](./src/start_of_day.js) - return the start of a day for the given date.
* [`endOfDay`](./src/end_of_day.js) - return the end of a day for the given date.
* [`addDays`](./src/add_days.js) - add the specified number of days to the given date.
* [`subDays`](./src/sub_days.js) - subtract the specified number of days from the given date.
* [`isSameDay`](./src/is_same_day.js) - are the given dates in the same day?
* [`isWeekend`](./src/is_weekend.js) - is the given date in a weekend?
* [`isYesterday`](./src/is_yesterday.js) - is the given date yesterday?
* [`isToday`](./src/is_today.js) - is the given date today?
* [`isTomorrow`](./src/is_tomorrow.js) - is the given date tomorrow?
* [`eachDay`](./src/each_day.js) - return the array of dates within the specified range.
* [`differenceInDays`](./src/difference_in_days.js) - return the number of full days between the given dates.
### Week helpers
* [`getISOWeek`](./src/get_iso_week.js) - returns ISO week index.
* [`setISOWeek`](./src/set_iso_week.js) - sets ISO week index.
* [`startOfWeek`](./src/start_of_week.js) - returns start of a week for passed date.
* [`endOfWeek`](./src/end_of_week.js) - returns end of a week for passed date.
* [`lastDayOfWeek`](./src/last_day_of_week.js) - returns last day of week for passed date.
* [`addWeeks`](./src/add_weeks.js) - add specified number of weeks to passed date.
* [`subWeeks`](./src/sub_weeks.js) - subtract specified number of weeks from passed date.
* [`isSameWeek`](./src/is_same_week.js) - returns true if passed dates belongs to the same week.
* [`startOfWeek`](./src/start_of_week.js) - return the start of a week for the given date.
* [`endOfWeek`](./src/end_of_week.js) - return the end of a week for the given date.
* [`lastDayOfWeek`](./src/last_day_of_week.js) - return the last day of a week for the given date.
* [`addWeeks`](./src/add_weeks.js) - add specified number of weeks to the given date.
* [`subWeeks`](./src/sub_weeks.js) - subtract specified number of weeks from the given date.
* [`isSameWeek`](./src/is_same_week.js) - are the given dates in the same week?
* [`isThisWeek`](./src/is_this_week.js) - is the given date in the same week as the current date?
### [ISO week](http://en.wikipedia.org/wiki/ISO_week_date) helpers
* [`getISOWeek`](./src/get_iso_week.js) - get the ISO week.
* [`setISOWeek`](./src/set_iso_week.js) - set the ISO week.
* [`startOfISOWeek`](./src/start_of_iso_week.js) - return the start of an ISO week for the given date.
* [`endOfISOWeek`](./src/end_of_iso_week.js) - return the end of an ISO week for the given date.
* [`lastDayOfISOWeek`](./src/last_day_of_iso_week.js) - return the last day of an ISO week for the given date.
* [`isSameISOWeek`](./src/is_same_iso_week.js) - are the given dates in the same ISO week?
* [`isThisISOWeek`](./src/is_this_iso_week.js) - is the given date in the same ISO week as the current date?
### Month helpers
* [`getMonth`](./src/get_month.js) - returns month index.
* [`setMonth`](./src/set_month.js) - sets month index.
* [`startOfMonth`](./src/start_of_month.js) - returns start of a month for passed date.
* [`endOfMonth`](./src/end_of_month.js) - returns end of a month for passed date.
* [`lastDayOfMonth`](./src/last_day_of_month.js) - returns last day of month for passed date.
* [`addMonths`](./src/add_months.js) - add specified number of months to passed date.
* [`subMonths`](./src/sub_months.js) - subtract specified number of months from passed date.
* [`isSameMonth`](./src/is_same_month.js) - returns true if passed dates have same month (and year).
* [`isFirstDayOfMonth`](./src/is_first_day_of_month.js) - return true if passed date is first day of month.
* [`isLastDayOfMonth`](./src/is_last_day_of_month.js) - return true if passed date is last day of month.
* [`getDaysInMonth`](./src/get_days_in_month.js) - returns number of days in month.
* [`getMonth`](./src/get_month.js) - get the month.
* [`setMonth`](./src/set_month.js) - set the month.
* [`startOfMonth`](./src/start_of_month.js) - return the start of a month for the given date.
* [`endOfMonth`](./src/end_of_month.js) - return the end of a month for the given date.
* [`lastDayOfMonth`](./src/last_day_of_month.js) - return the last day of a month for the given date.
* [`addMonths`](./src/add_months.js) - add the specified number of months to the given date.
* [`subMonths`](./src/sub_months.js) - subtract the specified number of months from the given date.
* [`isSameMonth`](./src/is_same_month.js) - are the given dates in the same month?
* [`isThisMonth`](./src/is_this_month.js) - is the given date in the same month as the current date?
* [`isFirstDayOfMonth`](./src/is_first_day_of_month.js) - is the given date the first day of a month?
* [`isLastDayOfMonth`](./src/is_last_day_of_month.js) - is the given date the last day of a month?
* [`getDaysInMonth`](./src/get_days_in_month.js) - get the number of days in a month of the given date.
### Quarter helpers
* [`getQuarter`](./src/get_quarter.js) - returns year quarter.
* [`setQuarter`](./src/set_quarter.js) - sets year quarter.
* [`startOfQuarter`](./src/start_of_quarter.js) - returns start of year quarter for passed date.
* [`endOfQuarter`](./src/end_of_quarter.js) - returns end of year quarter for passed date.
* [`lastDayOfQuarter`](./src/last_day_of_quarter.js) - returns last day of year quarter for passed date.
* [`addQuarters`](./src/add_quarters.js) - add specified number of year quarters to passed date.
* [`subQuarters`](./src/sub_quarters.js) - subtract specified number of year quarters from passed date.
* [`isSameQuarter`](./src/is_same_quarter.js) - are passed dates have the same year quarter?
* [`getQuarter`](./src/get_quarter.js) - get the year quarter.
* [`setQuarter`](./src/set_quarter.js) - set the year quarter.
* [`startOfQuarter`](./src/start_of_quarter.js) - return the start of a year quarter for the given date.
* [`endOfQuarter`](./src/end_of_quarter.js) - return the end of a year quarter for the given date.
* [`lastDayOfQuarter`](./src/last_day_of_quarter.js) - return the last day of a year quarter for the given date.
* [`addQuarters`](./src/add_quarters.js) - add the specified number of year quarters to the given date.
* [`subQuarters`](./src/sub_quarters.js) - subtract the specified number of year quarters from the given date.
* [`isSameQuarter`](./src/is_same_quarter.js) - are the given dates in the same year quarter?
* [`isThisQuarter`](./src/is_this_quarter.js) - is the given date in the same quarter as the current date?
### Year helpers
* [`getYear`](./src/set_year.js) - returns full year.
* [`setYear`](./src/set_year.js) - sets full year.
* [`getISOYear`](./src/get_iso_year.js) - returns ISO week-numbering year.
* [`setISOYear`](./src/set_iso_year.js) - sets ISO week-numbering year.
* [`startOfYear`](./src/start_of_year.js) - returns start of year for passed date.
* [`startOfISOYear`](./src/start_of_iso_year.js) - returns start of ISO week-numbering year for passed date.
* [`endOfYear`](./src/end_of_year.js) - returns end of year for passed date.
* [`lastDayOfYear`](./src/last_day_of_year.js) - returns last day of year for passed date.
* [`addYears`](./src/add_years.js) - add specified number of years to passed date.
* [`subYears`](./src/sub_years.js) - subtract specified number of years from passed date.
* [`isSameYear`](./src/is_same_year.js) - are passed dates have the same year?
* [`isLeapYear`](./src/is_leap_year.js) - returns true is passed date is in the leap year.
* [`getISOWeeksInYear`]('./src/get_iso_weeks_in_year') - returns number of weeks in ISO week-numbering year.
* [`getYear`](./src/set_year.js) - get the year.
* [`setYear`](./src/set_year.js) - set the year.
* [`startOfYear`](./src/start_of_year.js) - return the start of a year for the given date.
* [`endOfYear`](./src/end_of_year.js) - return the end of a year for the given date.
* [`lastDayOfYear`](./src/last_day_of_year.js) - return the last day of a year for the given date.
* [`addYears`](./src/add_years.js) - add the specified number of years to the given date.
* [`subYears`](./src/sub_years.js) - subtract the specified number of years from the given date.
* [`isSameYear`](./src/is_same_year.js) - are the given dates in the same year?
* [`isThisYear`](./src/is_this_year.js) - is the given date in the same year as the current date?
* [`isLeapYear`](./src/is_leap_year.js) - is the given date in the leap year?
* [`getDaysInYear`](./src/get_days_in_year.js) - get the number of days in a year of the given date.
### [ISO week-numbering year](http://en.wikipedia.org/wiki/ISO_week_date) helpers
* [`getISOYear`](./src/get_iso_year.js) - get the ISO week-numbering year.
* [`setISOYear`](./src/set_iso_year.js) - set the ISO week-numbering year.
* [`startOfISOYear`](./src/start_of_iso_year.js) - return the start of an ISO week-numbering year for the given date.
* [`endOfISOYear`](./src/end_of_iso_year.js) - return the end of an ISO week-numbering year for the given date.
* [`lastDayOfISOYear`](./src/last_day_of_iso_year.js) - return the last day of an ISO week-numbering year for the given date.
* [`addISOYears`](./src/add_iso_years.js) - add the specified number of ISO week-numbering years to the given date.
* [`subISOYears`](./src/sub_iso_years.js) - subtract the specified number of ISO week-numbering years from the given date.
* [`isSameISOYear`](./src/is_same_iso_year.js) - are the given dates in the same ISO week-numbering year?
* [`isThisISOYear`](./src/is_this_iso_year.js) - is the given date in the same ISO week-numbering year as the current date?
* [`getISOWeeksInYear`]('./src/get_iso_weeks_in_year') - get the number of weeks in the ISO week-numbering year.
### I18n

@@ -157,1 +192,6 @@

## Tests
Kudos to [BrowserStack](https://www.browserstack.com) for the provided
Automate API. Thereby we run cross-browser tests on every push!

@@ -0,11 +1,8 @@

import fs from 'fs'
import path from 'path'
import fs from 'fs'
import listFunctions from './_lib/list_functions'
const files = fs.readdirSync(path.join(process.cwd(), 'src'))
const propertyRequireLines = listFunctions()
.map((fn) => ` ${fn.name}: require('${fn.path.replace(/\.js$/, '')}')`)
const propertyRequireLines = files
.filter((file) => file.match(/\.js/))
.map((file) => file.replace(/\.js/, ''))
.map((file) => ` ${camelize(file)}: require('./src/${file}')`)
const indexLines = ['module.exports = {']

@@ -16,5 +13,1 @@ .concat(propertyRequireLines.join(',\n'))

fs.writeFileSync(path.join(process.cwd(), 'index.js'), `${indexLines.join('\n')}\n`)
function camelize(str) {
return str.replace(/[-_\s]+(.)?/g, (match, c) => c ? c.toUpperCase() : '')
}

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var addDays = require('../add_days')
describe('addDays', function() {
it('adds number of passed days', function() {
it('adds given number of days', function() {
var result = addDays(new Date(2014, 8 /* Sep */, 1), 10)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 11))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 11))
})

@@ -11,3 +12,3 @@

var result = addDays(new Date(2014, 8 /* Sep */, 1).toISOString(), 10)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 11))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 11))
})

@@ -17,3 +18,3 @@

var result = addDays(new Date(2014, 8 /* Sep */, 1).getTime(), 10)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 11))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 11))
})

@@ -24,5 +25,5 @@

addDays(date, 11)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var addHours = require('../add_hours')
describe('addHours', function() {
it('adds numbers of passed hours', function() {
it('adds given numbers of hours', function() {
var result = addHours(new Date(2014, 6 /* Jul */, 10, 23, 0), 2)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 11, 1, 0))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 11, 1, 0))
})

@@ -13,3 +14,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 12, 1, 0))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 12, 1, 0))
})

@@ -21,3 +22,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 12, 1, 0))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 12, 1, 0))
})

@@ -28,5 +29,5 @@

addHours(date, 10)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 10, 23, 0))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 10, 23, 0))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var addMilliseconds = require('../add_milliseconds')
describe('addMilliseconds', function() {
it('adds number of passed milliseconds', function() {
it('adds given number of milliseconds', function() {
var result = addMilliseconds(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0), 750)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 750))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 750))
})

@@ -13,3 +14,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 500))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 500))
})

@@ -21,3 +22,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 500))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 500))
})

@@ -28,5 +29,5 @@

addMilliseconds(date, 250)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var addMinutes = require('../add_minutes')
describe('addMinutes', function() {
it('adds number of passed minutes', function() {
it('adds given number of minutes', function() {
var result = addMinutes(new Date(2014, 6 /* Jul */, 10, 12, 0), 30)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 30))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 30))
})

@@ -13,3 +14,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 20))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 20))
})

@@ -21,3 +22,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 20))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 20))
})

@@ -28,5 +29,5 @@

addMinutes(date, 25)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 0))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 10, 12, 0))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var addMonths = require('../add_months')
describe('addMonths', function() {
it('adds number of passed months', function() {
it('adds given number of months', function() {
var result = addMonths(new Date(2014, 8 /* Sep */, 1), 5)
expect(result).to.be.eql(new Date(2015, 1 /* Feb */, 1))
assert.deepEqual(result, new Date(2015, 1 /* Feb */, 1))
})

@@ -11,3 +12,3 @@

var result = addMonths(new Date(2014, 8 /* Sep */, 1).toISOString(), 12)
expect(result).to.be.eql(new Date(2015, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2015, 8 /* Sep */, 1))
})

@@ -17,3 +18,3 @@

var result = addMonths(new Date(2014, 8 /* Sep */, 1).getTime(), 12)
expect(result).to.be.eql(new Date(2015, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2015, 8 /* Sep */, 1))
})

@@ -24,11 +25,11 @@

addMonths(date, 12)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
it('works well when desired month have less days and provided date is on the last day of month', function() {
it('works well if desired month have less days and provided date is in the last day of month', function() {
var date = new Date(2014, 11 /* Dec */, 31)
var result = addMonths(date, 2)
expect(result).to.be.eql(new Date(2015, 1 /* Feb */, 28))
assert.deepEqual(result, new Date(2015, 1 /* Feb */, 28))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var addQuarters = require('../add_quarters')
describe('addQuarters', function() {
it('adds number of passed quarters', function() {
it('adds given number of quarters', function() {
var result = addQuarters(new Date(2014, 8 /* Sep */, 1), 1)
expect(result).to.be.eql(new Date(2014, 11 /* Dec */, 1))
assert.deepEqual(result, new Date(2014, 11 /* Dec */, 1))
})

@@ -11,3 +12,3 @@

var result = addQuarters(new Date(2014, 8 /* Sep */, 1).toISOString(), 4)
expect(result).to.be.eql(new Date(2015, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2015, 8 /* Sep */, 1))
})

@@ -17,3 +18,3 @@

var result = addQuarters(new Date(2014, 8 /* Sep */, 1).getTime(), 4)
expect(result).to.be.eql(new Date(2015, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2015, 8 /* Sep */, 1))
})

@@ -24,11 +25,11 @@

addQuarters(date, 4)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
it('works well when desired month have less days and provided date is on the last day of month', function() {
it('works well if desired month have less days and provided date is in the last day of month', function() {
var date = new Date(2014, 11 /* Dec */, 31)
var result = addQuarters(date, 3)
expect(result).to.be.eql(new Date(2015, 8 /* Sep */, 30))
assert.deepEqual(result, new Date(2015, 8 /* Sep */, 30))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var addSeconds = require('../add_seconds')
describe('addSeconds', function() {
it('adds number of passed seconds', function() {
it('adds given number of seconds', function() {
var result = addSeconds(new Date(2014, 6 /* Jul */, 10, 12, 45, 0), 30)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 30))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 45, 30))
})

@@ -13,3 +14,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 20))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 45, 20))
})

@@ -21,3 +22,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 20))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 45, 20))
})

@@ -28,5 +29,5 @@

addSeconds(date, 15)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 0))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 10, 12, 45, 0))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var addWeeks = require('../add_weeks')
describe('addWeeks', function() {
it('adds number of passed days', function() {
it('adds given number of weeks', function() {
var result = addWeeks(new Date(2014, 8 /* Sep */, 1), 4)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 29))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 29))
})

@@ -11,3 +12,3 @@

var result = addWeeks(new Date(2014, 8 /* Sep */, 1).toISOString(), 2)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 15))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 15))
})

@@ -17,3 +18,3 @@

var result = addWeeks(new Date(2014, 8 /* Sep */, 1).getTime(), 1)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 8))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 8))
})

@@ -24,5 +25,5 @@

addWeeks(date, 2)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var addYears = require('../add_years')
describe('addYears', function() {
it('adds number of passed years', function() {
it('adds given number of years', function() {
var result = addYears(new Date(2014, 8 /* Sep */, 1), 5)
expect(result).to.be.eql(new Date(2019, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2019, 8 /* Sep */, 1))
})

@@ -11,3 +12,3 @@

var result = addYears(new Date(2014, 8 /* Sep */, 1).toISOString(), 12)
expect(result).to.be.eql(new Date(2026, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2026, 8 /* Sep */, 1))
})

@@ -17,3 +18,3 @@

var result = addYears(new Date(2014, 8 /* Sep */, 1).getTime(), 12)
expect(result).to.be.eql(new Date(2026, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2026, 8 /* Sep */, 1))
})

@@ -24,5 +25,5 @@

addYears(date, 12)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var compareAsc = require('../compare_asc')
describe('compareAsc', function() {
it('returns 0 if passed dates are equal', function() {
it('returns 0 if given dates are equal', function() {
var result = compareAsc(

@@ -9,3 +10,3 @@ new Date(1989, 6 /* Jul */, 10),

)
expect(result).to.equal(0)
assert(result === 0)
})

@@ -18,3 +19,3 @@

)
expect(result).to.equal(-1)
assert(result === -1)
})

@@ -27,3 +28,3 @@

)
expect(result).to.equal(1)
assert(result === 1)
})

@@ -46,6 +47,6 @@

expect(result).to.eql(sortedArray)
assert.deepEqual(result, sortedArray)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = compareAsc(

@@ -55,6 +56,6 @@ new Date(1987, 1 /* Feb */, 11).toISOString(),

)
expect(result).to.equal(-1)
assert(result === -1)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = compareAsc(

@@ -64,5 +65,5 @@ new Date(1987, 1 /* Feb */, 11).getTime(),

)
expect(result).to.equal(-1)
assert(result === -1)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var compareDesc = require('../compare_desc')
describe('compareDesc', function() {
it('returns 0 if passed dates are equal', function() {
it('returns 0 if given dates are equal', function() {
var result = compareDesc(

@@ -9,3 +10,3 @@ new Date(1989, 6 /* Jul */, 10),

)
expect(result).to.equal(0)
assert(result === 0)
})

@@ -18,3 +19,3 @@

)
expect(result).to.equal(1)
assert(result === 1)
})

@@ -27,3 +28,3 @@

)
expect(result).to.equal(-1)
assert(result === -1)
})

@@ -46,6 +47,6 @@

expect(result).to.eql(sortedArray)
assert.deepEqual(result, sortedArray)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = compareDesc(

@@ -55,6 +56,6 @@ new Date(1987, 1 /* Feb */, 11).toISOString(),

)
expect(result).to.equal(1)
assert(result === 1)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = compareDesc(

@@ -64,5 +65,5 @@ new Date(1987, 1 /* Feb */, 11).getTime(),

)
expect(result).to.equal(1)
assert(result === 1)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var differenceInDays = require('../difference_in_days')

@@ -9,6 +10,6 @@

)
expect(result).to.be.equal(366)
assert(result === 366)
})
it('allows to pass strings', function() {
it('accepts strings', function() {
var result = differenceInDays(

@@ -18,6 +19,6 @@ new Date(2014, 6 /* Jul */, 1, 23, 59, 59, 999).toISOString(),

)
expect(result).to.be.equal(181)
assert(result === 181)
})
it('allows to pass timestamps', function() {
it('accepts timestamps', function() {
var result = differenceInDays(

@@ -27,5 +28,5 @@ new Date(2014, 8 /* Sep */, 5, 18, 0).getTime(),

)
expect(result).to.be.equal(1)
assert(result === 1)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var eachDay = require('../each_day')
describe('eachDay', function() {
it('returns array of dates within specefied range', function() {
it('returns array of dates within specified range', function() {
var result = eachDay(

@@ -9,3 +10,3 @@ new Date(2014, 9 /* Oct */, 6),

)
expect(result).to.be.eql([
assert.deepEqual(result, [
new Date(2014, 9 /* Oct */, 6),

@@ -26,3 +27,3 @@ new Date(2014, 9 /* Oct */, 7),

)
expect(result).to.be.eql([
assert.deepEqual(result, [
new Date(2014, 9 /* Oct */, 6),

@@ -38,3 +39,3 @@ new Date(2014, 9 /* Oct */, 7),

it('accepts timestamp', function() {
it('accepts timestamps', function() {
var result = eachDay(

@@ -44,3 +45,3 @@ new Date(2014, 9 /* Oct */, 6).getTime(),

)
expect(result).to.be.eql([
assert.deepEqual(result, [
new Date(2014, 9 /* Oct */, 6),

@@ -55,3 +56,12 @@ new Date(2014, 9 /* Oct */, 7),

})
it('throws exception if start date is after end date', function() {
var block = eachDay.bind(
null,
new Date(2014, 9 /* Oct */, 12),
new Date(2014, 9 /* Oct */, 6)
)
assert.throws(block)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var endOfDay = require('../end_of_day')

@@ -7,3 +8,3 @@

var result = endOfDay(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 2, 23, 59, 59, 999)

@@ -16,3 +17,3 @@ )

var result = endOfDay(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 2, 23, 59, 59, 999)

@@ -25,3 +26,3 @@ )

var result = endOfDay(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 2, 23, 59, 59, 999)

@@ -34,5 +35,5 @@ )

endOfDay(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})
})

@@ -0,19 +1,20 @@

var assert = require('power-assert')
var endOfHour = require('../end_of_hour')
describe('endOfHour', function() {
it('returns date with time setted to last millisecond before the hour ends', function() {
it('returns date with time setted to last millisecond before hour ends', function() {
var date = new Date(2014, 11, 1, 22, 15)
var result = endOfHour(date)
expect(result).to.be.eql(new Date(2014, 11, 1, 22, 59, 59, 999))
assert.deepEqual(result, new Date(2014, 11, 1, 22, 59, 59, 999))
})
it('supports string as a date', function() {
it('accepts string', function() {
var date = new Date(2014, 11, 1, 13).toISOString()
var result = endOfHour(date)
expect(result).to.be.eql(new Date(2014, 11, 1, 13, 59, 59, 999))
assert.deepEqual(result, new Date(2014, 11, 1, 13, 59, 59, 999))
})
it('supports timestamp as a date', function() {
it('accepts timestamp', function() {
var result = endOfHour(new Date(2014, 11, 1, 22, 15).getTime())
expect(result).to.be.eql(new Date(2014, 11, 1, 22, 59, 59, 999))
assert.deepEqual(result, new Date(2014, 11, 1, 22, 59, 59, 999))
})

@@ -24,5 +25,5 @@

endOfHour(date)
expect(date).to.be.eql(new Date(2014, 11, 1, 22, 15))
assert.deepEqual(date, new Date(2014, 11, 1, 22, 15))
})
})

@@ -0,18 +1,19 @@

var assert = require('power-assert')
var endOfMinute = require('../end_of_minute')
describe('endOfMinute', function() {
it('returns date with time setted to last millisecond before the minute ends', function() {
it('returns date with time setted to last millisecond before minute ends', function() {
var date = new Date(2014, 11, 1, 22, 15)
var result = endOfMinute(date)
expect(result).to.be.eql(new Date(2014, 11, 1, 22, 15, 59, 999))
assert.deepEqual(result, new Date(2014, 11, 1, 22, 15, 59, 999))
})
it('supports string as a date', function() {
it('accepts string', function() {
var result = endOfMinute('2014-12-01T13:00:00.000Z')
expect(result).to.be.eql(new Date(Date.UTC(2014, 11, 1, 13, 00, 59, 999)))
assert.deepEqual(result, new Date(Date.UTC(2014, 11, 1, 13, 00, 59, 999)))
})
it('supports timestamp as a date', function() {
it('accepts timestamp', function() {
var result = endOfMinute(new Date(2014, 11, 1, 22, 15).getTime())
expect(result).to.be.eql(new Date(2014, 11, 1, 22, 15, 59, 999))
assert.deepEqual(result, new Date(2014, 11, 1, 22, 15, 59, 999))
})

@@ -23,5 +24,5 @@

endOfMinute(date)
expect(date).to.be.eql(new Date(2014, 11, 1, 22, 15))
assert.deepEqual(date, new Date(2014, 11, 1, 22, 15))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var endOfMonth = require('../end_of_month')

@@ -7,3 +8,3 @@

var result = endOfMonth(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 30, 23, 59, 59, 999)

@@ -16,3 +17,3 @@ )

var result = endOfMonth(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 30, 23, 59, 59, 999)

@@ -25,3 +26,3 @@ )

var result = endOfMonth(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 30, 23, 59, 59, 999)

@@ -34,3 +35,3 @@ )

endOfMonth(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})

@@ -42,3 +43,3 @@

var result = endOfMonth(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 11 /* Dec */, 31, 23, 59, 59, 999)

@@ -51,3 +52,3 @@ )

var result = endOfMonth(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 9 /* Oct */, 31, 23, 59, 59, 999)

@@ -54,0 +55,0 @@ )

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var endOfQuarter = require('../end_of_quarter')

@@ -7,3 +8,3 @@

var result = endOfQuarter(date)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 30, 23, 59, 59, 999))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 30, 23, 59, 59, 999))
})

@@ -14,3 +15,3 @@

var result = endOfQuarter(date)
expect(result).to.be.eql(new Date(2014, 2 /* Mar */, 31, 23, 59, 59, 999))
assert.deepEqual(result, new Date(2014, 2 /* Mar */, 31, 23, 59, 59, 999))
})

@@ -21,3 +22,3 @@

var result = endOfQuarter(date)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 30, 23, 59, 59, 999))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 30, 23, 59, 59, 999))
})

@@ -28,5 +29,5 @@

endOfQuarter(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})
})

@@ -0,18 +1,19 @@

var assert = require('power-assert')
var endOfSecond = require('../end_of_second')
describe('endOfSecond', function() {
it('returns date with time setted to last millisecond before the second ends', function() {
it('returns date with time setted to last millisecond before second ends', function() {
var date = new Date(2014, 11, 1, 22, 15, 30)
var result = endOfSecond(date)
expect(result).to.be.eql(new Date(2014, 11, 1, 22, 15, 30, 999))
assert.deepEqual(result, new Date(2014, 11, 1, 22, 15, 30, 999))
})
it('supports string as a date', function() {
it('accepts string', function() {
var result = endOfSecond('2014-12-01T13:00:00.000Z')
expect(result).to.be.eql(new Date(Date.UTC(2014, 11, 1, 13, 00, 0, 999)))
assert.deepEqual(result, new Date(Date.UTC(2014, 11, 1, 13, 00, 0, 999)))
})
it('supports timestamp as a date', function() {
it('accepts timestamp', function() {
var result = endOfSecond(new Date(2014, 11, 1, 22, 15, 45).getTime())
expect(result).to.be.eql(new Date(2014, 11, 1, 22, 15, 45, 999))
assert.deepEqual(result, new Date(2014, 11, 1, 22, 15, 45, 999))
})

@@ -23,5 +24,5 @@

endOfSecond(date)
expect(date).to.be.eql(new Date(2014, 11, 1, 22, 15, 15, 300))
assert.deepEqual(date, new Date(2014, 11, 1, 22, 15, 15, 300))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var endOfWeek = require('../end_of_week')

@@ -7,3 +8,3 @@

var result = endOfWeek(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 6, 23, 59, 59, 999)

@@ -16,3 +17,3 @@ )

var result = endOfWeek(date, 1)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 7, 23, 59, 59, 999)

@@ -25,3 +26,3 @@ )

var result = endOfWeek(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 6, 23, 59, 59, 999)

@@ -34,3 +35,3 @@ )

var result = endOfWeek(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 6, 23, 59, 59, 999)

@@ -43,3 +44,3 @@ )

endOfWeek(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})

@@ -52,3 +53,3 @@

var result = endOfWeek(date, 3)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 7, 23, 59, 59, 999))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 7, 23, 59, 59, 999))
})

@@ -61,3 +62,3 @@ })

var result = endOfWeek(date, 3)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 14, 23, 59, 59, 999))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 14, 23, 59, 59, 999))
})

@@ -70,3 +71,3 @@ })

var result = endOfWeek(date, 3)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 14, 23, 59, 59, 999))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 14, 23, 59, 59, 999))
})

@@ -78,3 +79,3 @@ })

var result = endOfWeek(date, 5)
expect(result).to.be.eql(new Date(2015, 0 /* Jan */, 1, 23, 59, 59, 999))
assert.deepEqual(result, new Date(2015, 0 /* Jan */, 1, 23, 59, 59, 999))
})

@@ -81,0 +82,0 @@ })

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var endOfYear = require('../end_of_year')

@@ -7,3 +8,3 @@

var result = endOfYear(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 11 /* Dec */, 31, 23, 59, 59, 999)

@@ -16,3 +17,3 @@ )

var result = endOfYear(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 11 /* Dec */, 31, 23, 59, 59, 999)

@@ -25,3 +26,3 @@ )

var result = endOfYear(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 11 /* Dec */, 31, 23, 59, 59, 999)

@@ -34,5 +35,5 @@ )

endOfYear(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var format = require('../format')

@@ -5,8 +6,26 @@

beforeEach(function() {
this._date = new Date(1986, 3, 4, 10, 32, 0, 900)
})
this._date = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900)
it('simple YY', function() {
var b = new Date(2009, 1, 14, 15, 25, 50, 125)
expect(format(b, 'YY')).to.equal('09')
this._timezone = {
'-840': '+14:00', '-810': '+13:30', '-780': '+13:00', '-750': '+12:30',
'-720': '+12:00', '-690': '+11:30', '-660': '+11:00', '-630': '+10:30',
'-600': '+10:00', '-570': '+09:30', '-540': '+09:00', '-510': '+08:30',
'-480': '+08:00', '-450': '+07:30', '-420': '+07:00', '-390': '+06:30',
'-360': '+06:00', '-330': '+05:30', '-300': '+05:00', '-270': '+04:30',
'-240': '+04:00', '-210': '+03:30', '-180': '+03:00', '-150': '+02:30',
'-120': '+02:00', '-90': '+01:30', '-60': '+01:00', '-30': '+00:30',
'0': '+00:00', '30': '-00:30', '60': '-01:00', '90': '-01:30', '120': '-02:00',
'150': '-02:30', '180': '-03:00', '210': '-03:30', '240': '-04:00',
'270': '-04:30', '300': '-05:00', '330': '-05:30', '360': '-06:00',
'390': '-06:30', '420': '-07:00', '450': '-07:30', '480': '-08:00',
'510': '-08:30', '540': '-09:00', '570': '-09:30', '600': '-10:00',
'630': '-10:30', '660': '-11:00', '690': '-11:30', '720': '-12:00',
'750': '-12:30', '780': '-13:00', '810': '-13:30', '840': '-14:00',
'-825': '+13:45', '-765': '+12:45', '-525': '+08:45', '-345': '+05:45',
'345': '-05:45', '525': '-08:45', '765': '-12:45'
}[this._date.getTimezoneOffset().toString()]
this._timezoneShort = this._timezone.replace(':', '')
this._timestamp = this._date.getTime().toString()
this._secondsTimestamp = Math.floor(this._date.getTime() / 1000).toString()
})

@@ -16,3 +35,3 @@

var date = new Date(2014, 3, 4).toISOString()
expect(format(date, 'YYYY-MM-DD')).to.be.equal('2014-04-04')
assert(format(date, 'YYYY-MM-DD') === '2014-04-04')
})

@@ -22,23 +41,21 @@

var date = new Date(2014, 3, 4).getTime()
expect(format(date, 'YYYY-MM-DD')).to.be.equal('2014-04-04')
assert(format(date, 'YYYY-MM-DD') === '2014-04-04')
})
it('return default ISO string format if format is unknown', function() {
expect(format(this._date)).to.be.equal('1986-04-04T10:32:00.900Z')
it('returns default ISO string format if format is unknown', function() {
assert(format(this._date) === '1986-04-04T10:32:00.900' + this._timezone)
})
describe('format escape brackets', function() {
it('should ignore escaped chars that in [] brackets', function() {
var result = format(this._date, '[not a date] MM')
expect(result).to.be.equal('not a date 04')
})
it('escapes characters inside square brackets', function() {
var result = format(this._date, '[YYYY-]MM-DD[THH:mm:ss.SSSZ] YYYY-[MM-DD]')
assert(result === 'YYYY-04-04THH:mm:ss.SSSZ 1986-MM-DD')
})
describe('ordinal', function() {
it('should return 1st', function() {
var date = format(this._date, 'Do of t[h][e] Mo in YYYY')
expect(date).to.be.equal('4th of the 4th in 1986')
it('ordinal day of ordinal month', function() {
var result = format(this._date, 'Do of t[h][e] Mo in YYYY')
assert(result === '4th of the 4th in 1986')
})
it('should return proper ordinal', function() {
it('should return correct ordinal number', function() {
var result = []

@@ -48,128 +65,241 @@ for (var i = 1; i <= 31; i++) {

}
var expected = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th', '11th', '12th', '13th', '14th', '15th', '16th', '17th', '18th', '19th', '20th', '21st', '22nd', '23rd', '24th', '25th', '26th', '27th', '28th', '29th', '30th', '31st']
expect(result).to.deep.equal(expected)
var expected = [
'1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th',
'11th', '12th', '13th', '14th', '15th', '16th', '17th', '18th', '19th', '20th',
'21st', '22nd', '23rd', '24th', '25th', '26th', '27th', '28th', '29th', '30th', '31st'
]
assert.deepEqual(result, expected)
})
})
describe('Months', function() {
it('return months names', function() {
var date = format(this._date, 'MMM MMMM')
expect(date).to.equal('Apr April')
describe('month', function() {
it('cardinal number', function() {
assert(format(this._date, 'M') === '4')
})
it('return months names reverse parse', function() {
var date = format(this._date, 'MMMM MMM')
expect(date).to.equal('April Apr')
it('cardinal number with leading zeros', function() {
assert(format(this._date, 'MM') === '04')
})
it('all month variants', function() {
it('ordinal number', function() {
assert(format(this._date, 'Mo') === '4th')
})
it('short name', function() {
assert(format(this._date, 'MMM') === 'Apr')
})
it('full name', function() {
assert(format(this._date, 'MMMM') === 'April')
})
it('all variants', function() {
var date = format(this._date, 'M Mo MM MMM MMMM')
expect(date).to.equal('4 4th 04 Apr April')
assert(date === '4 4th 04 Apr April')
})
})
describe('formatting day', function() {
describe('with DDD', function() {
context('for first day of a year', function() {
it('returns correct day number', function() {
var result = format(new Date(1992, 0, 1, 0, 0, 0, 0), 'DDD')
expect(result).to.be.equal('1')
})
describe('quarter', function() {
it('returns correct quarter', function() {
var result = []
for (var i = 0; i <= 11; i++) {
result.push(format(new Date(1986, i, 1), 'Q'))
}
var expected = ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4', '4', '4']
assert.deepEqual(result, expected)
})
it('all variants', function() {
assert(format(this._date, 'Q Qo') === '2 2nd')
})
})
describe('day of month', function() {
it('all variants', function() {
assert(format(this._date, 'D Do DD') === '4 4th 04')
})
})
describe('day of year', function() {
context('for first day of a year', function() {
it('returns correct day number', function() {
var result = format(new Date(1992, 0 /* Jan */, 1), 'DDD')
assert(result === '1')
})
})
context('for last day of a common year', function() {
it('returns correct day number', function() {
var lastDay = format(new Date(1986, 11, 31, 23, 59, 59, 999), 'DDD')
expect(lastDay).to.be.equal('365')
})
context('for last day of a common year', function() {
it('returns correct day number', function() {
var result = format(new Date(1986, 11 /* Dec */, 31, 23, 59, 59, 999), 'DDD')
assert(result === '365')
})
})
context('for last day of a leap year', function() {
it('returns correct day number', function() {
var result = format(new Date(1992, 11, 31, 23, 59, 59, 999), 'DDD')
expect(result).to.be.equal('366')
})
context('for last day of a leap year', function() {
it('returns correct day number', function() {
var result = format(new Date(1992, 11 /* Dec */, 31, 23, 59, 59, 999), 'DDD')
assert(result === '366')
})
})
it('return ordinal day of the year', function() {
var firstDay = format(new Date(1992, 0, 1, 0, 0, 0, 0), 'DDDo')
expect(firstDay).to.be.equal('1st')
it('ordinal number', function() {
var result = format(new Date(1992, 0 /* Jan */, 1), 'DDDo')
assert(result === '1st')
})
it('return zero filled day of year', function() {
var firstDay = format(new Date(1992, 0, 1, 0, 0, 0, 0), 'DDDD')
expect(firstDay).to.be.equal('001')
it('cardinal number with leading zeros', function() {
var result = format(new Date(1992, 0 /* Jan */, 1), 'DDDD')
assert(result === '001')
})
})
describe('Quartal', function() {
it('right quartal', function() {
describe('day of week', function() {
it('all variants', function() {
var result = format(this._date, 'd do dd ddd dddd')
assert(result === '5 5th Fr Fri Friday')
})
})
describe('day of ISO week', function() {
it('returns correct day of ISO week', function() {
var result = []
for (var i = 0; i != 12; i++) {
result.push(format(new Date(1986, i, 1), 'Q'))
for (var i = 1; i <= 7; i++) {
result.push(format(new Date(1986, 8 /* Sep */, i), 'E'))
}
expect(result).to.deep.equal(
['1','1','1', '2', '2', '2', '3', '3', '3', '4', '4', '4']
)
var expected = ['1', '2', '3', '4', '5', '6', '7']
assert.deepEqual(result, expected)
})
})
describe('day of week', function() {
it('display', function() {
var result = format(this._date, 'd do dd ddd dddd')
expect(result).to.be.equal('5 5th Fr Fri Friday')
describe('ISO week', function() {
it('cardinal number with leading zeros', function() {
var result = format(new Date(1992, 0 /* Jan */, 5), 'Wo')
assert(result === '1st')
})
it('ISO', function() {
expect(format(this._date, 'E')).to.be.equal('6')
it('all variants', function() {
var result = format(this._date, 'W Wo WW')
assert(result === '14 14th 14')
})
})
it('parses ok for different variants', function() {
var firstDay = format(this._date, 'dddd ddd d do [d] do dd ddd dddd')
expect(firstDay).to.be.equal('Friday Fri 5 5th d 5th Fr Fri Friday')
describe('year', function() {
it('all variants', function() {
var result = format(this._date, 'YY YYYY')
assert(result === '86 1986')
})
})
describe('hours', function() {
describe('ISO week-numbering year', function() {
it('first week of next year', function() {
var result = format(new Date(2013, 11 /* Dec */, 30), 'GGGG')
assert(result === '2014')
})
it('last week of previous year', function() {
var result = format(new Date(2016, 0 /* Jan */, 1), 'GGGG')
assert(result === '2015')
})
it('all variants', function() {
var result = format(this._date, 'GG GGGG')
assert(result === '86 1986')
})
})
describe('hours and am/pm', function() {
it('am/pm', function() {
expect(format(this._date, 'hh:mm a')).to.be.equal('10:32 am')
assert(format(this._date, 'hh:mm a') === '10:32 am')
})
it('12 pm', function() {
var date = new Date(1986, 3, 4, 12, 00, 0, 900)
expect(format(date, 'hh:mm a')).to.be.equal('12:00 pm')
var date = new Date(1986, 3 /* Apr */, 4, 12, 00, 0, 900)
assert(format(date, 'hh:mm a') === '12:00 pm')
})
it('12 am', function() {
var date = new Date(1986, 3, 4, 00, 00, 0, 900)
expect(format(date, 'h:mm a')).to.be.equal('12:00 am')
var date = new Date(1986, 3 /* Apr */, 4, 00, 00, 0, 900)
assert(format(date, 'h:mm a') === '12:00 am')
})
it('12 a.m.', function() {
var date = new Date(1986, 3, 4, 00, 00, 0, 900)
expect(format(date, 'h:mm aa')).to.be.equal('12:00 a.m.')
var date = new Date(1986, 3 /* Apr */, 4, 00, 00, 0, 900)
assert(format(date, 'h:mm aa') === '12:00 a.m.')
})
it('12 p.m.', function() {
var date = new Date(1986, 3, 4, 12, 00, 0, 900)
expect(format(date, 'hh:mm aa')).to.be.equal('12:00 p.m.')
var date = new Date(1986, 3 /* Apr */, 4, 12, 00, 0, 900)
assert(format(date, 'hh:mm aa') === '12:00 p.m.')
})
it('12PM', function() {
var date = new Date(1986, 3, 4, 12, 00, 0, 900)
expect(format(date, 'hh:mmA')).to.be.equal('12:00PM')
var date = new Date(1986, 3 /* Apr */, 4, 12, 00, 0, 900)
assert(format(date, 'hh:mmA') === '12:00PM')
})
it('cardinal numbers with leading zeros', function() {
var date = new Date(1986, 3 /* Apr */, 4, 1, 0, 0, 900)
assert(format(date, 'HH hh') === '01 01')
})
it('all hour variants', function() {
assert(format(this._date, 'H HH h hh') === '10 10 10 10')
})
})
describe('seconds', function() {
it('show', function() {
expect(format(this._date, 's ss')).to.be.equal('0 00')
describe('minute', function() {
it('cardinal number with leading zeros', function() {
var date = new Date(1986, 3 /* Apr */, 4, 12, 00, 0, 900)
assert(format(date, 'mm') === '00')
})
it('all variants', function() {
assert(format(this._date, 'm mm') === '32 32')
})
})
describe('timezones', function() {
it('should parse dates without timezones', function() {
expect(format('2015-01-01', 'YYYY-MM-DD')).to.be.equal('2015-01-01')
describe('second', function() {
it('all variants', function() {
assert(format(this._date, 's ss') === '0 00')
})
})
describe('fractions of second', function() {
it('1/10 of second', function() {
var date = new Date(1986, 3 /* Apr */, 4, 12, 00, 0, 859)
assert(format(date, 'S') === '8')
})
it('1/100 of second', function() {
var date = new Date(1986, 3 /* Apr */, 4, 12, 00, 0, 859)
assert(format(date, 'SS') === '85')
})
it('millisecond', function() {
var date = new Date(1986, 3 /* Apr */, 4, 12, 00, 0, 859)
assert(format(date, 'SSS') === '859')
})
})
describe('timezone', function() {
it('should parse date in local timezone', function() {
assert(format('2015-01-01', 'YYYY-MM-DD') === '2015-01-01')
})
it('all variants', function() {
var result = format(this._date, 'Z ZZ')
assert(result === this._timezone + ' ' + this._timezoneShort)
})
})
describe('timestamp', function() {
it('unix seconds timestamp', function() {
assert(format(this._date, 'X') === this._secondsTimestamp)
})
it('unix milliseconds timestamp', function() {
assert(format(this._date, 'x') === this._timestamp)
})
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var getDate = require('../get_date')

@@ -6,3 +7,3 @@

var result = getDate(new Date(2012, 1 /* Feb */, 29))
expect(result).to.be.equal(29)
assert(result === 29)
})

@@ -12,3 +13,3 @@

var result = getDate(new Date(2014, 6 /* Jul */, 2).toISOString())
expect(result).to.be.equal(2)
assert(result === 2)
})

@@ -18,5 +19,5 @@

var result = getDate(new Date(2014, 11 /* Dec */, 31).getTime())
expect(result).to.be.equal(31)
assert(result === 31)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var getDayOfYear = require('../get_day_of_year')

@@ -6,3 +7,3 @@

var result = getDayOfYear(new Date(2014, 6 /* Jul */, 2))
expect(result).to.be.equal(183)
assert(result === 183)
})

@@ -12,3 +13,3 @@

var result = getDayOfYear(new Date(2014, 0 /* Jan */, 2).toISOString())
expect(result).to.be.equal(2)
assert(result === 2)
})

@@ -18,5 +19,5 @@

var result = getDayOfYear(new Date(2014, 0 /* Jan */, 2).getTime())
expect(result).to.be.equal(2)
assert(result === 2)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var getDay = require('../get_day')

@@ -6,3 +7,3 @@

var result = getDay(new Date(2012, 1 /* Feb */, 29))
expect(result).to.be.equal(3)
assert(result === 3)
})

@@ -12,3 +13,3 @@

var result = getDay(new Date(2014, 6 /* Jul */, 2).toISOString())
expect(result).to.be.equal(3)
assert(result === 3)
})

@@ -18,5 +19,5 @@

var result = getDay(new Date(2014, 5 /* Jun */, 1).getTime())
expect(result).to.be.equal(0)
assert(result === 0)
})
})

@@ -0,26 +1,27 @@

var assert = require('power-assert')
var getDaysInMonth = require('../get_days_in_month')
describe('getDaysInMonth', function() {
it('returns number of days in month of passed date', function() {
it('returns number of days in month of given date', function() {
var result = getDaysInMonth(new Date(2100, 1 /* Feb */, 11))
expect(result).to.be.equal(28)
assert(result === 28)
})
it('works for February of a leap year', function() {
it('works for February of leap year', function() {
var result = getDaysInMonth(new Date(2000, 1 /* Feb */, 11))
expect(result).to.be.equal(29)
assert(result === 29)
})
it('allows to pass string', function() {
it('accepts string', function() {
var date = new Date(2014, 6 /* Jul */, 2).toISOString()
var result = getDaysInMonth(date)
expect(result).to.be.equal(31)
assert(result === 31)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var date = new Date(2014, 6 /* Jul */, 2).getTime()
var result = getDaysInMonth(date)
expect(result).to.be.equal(31)
assert(result === 31)
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var getHours = require('../get_hours')
describe('getHours', function() {
it('returns amount of hours of given date', function() {
it('returns hours of given date', function() {
var result = getHours(new Date(2012, 1 /* Feb */, 29, 11, 45))
expect(result).to.be.equal(11)
assert(result === 11)
})

@@ -11,3 +12,3 @@

var result = getHours(new Date(2014, 6 /* Jul */, 2, 5).toISOString())
expect(result).to.be.equal(5)
assert(result === 5)
})

@@ -17,5 +18,5 @@

var result = getHours(new Date(2014, 3 /* Apr */, 2, 23, 30).getTime())
expect(result).to.be.equal(23)
assert(result === 23)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var getISOWeek = require('../get_iso_week')

@@ -6,15 +7,15 @@

var result = getISOWeek(new Date(2005, 0 /* Jan */, 2))
expect(result).to.equal(53)
assert(result === 53)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = getISOWeek(new Date(2008, 11 /* Dec */, 29).toISOString())
expect(result).to.equal(1)
assert(result === 1)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = getISOWeek(new Date(2008, 11 /* Dec */, 29).getTime())
expect(result).to.equal(1)
assert(result === 1)
})
})

@@ -0,21 +1,22 @@

var assert = require('power-assert')
var getISOWeeksInYear = require('../get_iso_weeks_in_year')
describe('getISOWeeksInYear', function() {
it('returns number of days in month of passed date', function() {
it('returns number of days in month of given date', function() {
var result = getISOWeeksInYear(new Date(2015, 1 /* Feb */, 11))
expect(result).to.be.equal(53)
assert(result === 53)
})
it('allows to pass string', function() {
it('accepts string', function() {
var date = new Date(2014, 1 /* Feb */, 11).toISOString()
var result = getISOWeeksInYear(date)
expect(result).to.be.equal(52)
assert(result === 52)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var date = new Date(2003, 11 /* Dec */, 30).getTime()
var result = getISOWeeksInYear(date)
expect(result).to.be.equal(53)
assert(result === 53)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var getISOYear = require('../get_iso_year')

@@ -6,15 +7,15 @@

var result = getISOYear(new Date(2007, 11 /* Dec */, 31))
expect(result).to.equal(2008)
assert(result === 2008)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = getISOYear(new Date(2005, 0 /* Jan */, 1).toISOString())
expect(result).to.equal(2004)
assert(result === 2004)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = getISOYear(new Date(2005, 0 /* Jan */, 1).getTime())
expect(result).to.equal(2004)
assert(result === 2004)
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var getMilliseconds = require('../get_milliseconds')
describe('getMilliseconds', function() {
it('returns amount of milliseconds of given date', function() {
it('returns milliseconds of given date', function() {
var result = getMilliseconds(new Date(2012, 1 /* Feb */, 29, 11, 45, 5, 123))
expect(result).to.be.equal(123)
assert(result === 123)
})

@@ -11,3 +12,3 @@

var result = getMilliseconds(new Date(2014, 6 /* Jul */, 2, 5, 15).toISOString())
expect(result).to.be.equal(0)
assert(result === 0)
})

@@ -17,5 +18,5 @@

var result = getMilliseconds(new Date(2014, 3 /* Apr */, 2, 23, 30, 42, 500).getTime())
expect(result).to.be.equal(500)
assert(result === 500)
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var getMinutes = require('../get_minutes')
describe('getMinutes', function() {
it('returns amount of minutes of given date', function() {
it('returns minutes of given date', function() {
var result = getMinutes(new Date(2012, 1 /* Feb */, 29, 11, 45, 5))
expect(result).to.be.equal(45)
assert(result === 45)
})

@@ -11,3 +12,3 @@

var result = getMinutes(new Date(2014, 6 /* Jul */, 2, 5).toISOString())
expect(result).to.be.equal(0)
assert(result === 0)
})

@@ -17,5 +18,5 @@

var result = getMinutes(new Date(2014, 3 /* Apr */, 2, 23, 30).getTime())
expect(result).to.be.equal(30)
assert(result === 30)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var getMonth = require('../get_month')

@@ -6,3 +7,3 @@

var result = getMonth(new Date(2012, 1 /* Feb */, 29))
expect(result).to.be.equal(1)
assert(result === 1)
})

@@ -12,3 +13,3 @@

var result = getMonth(new Date(2014, 6 /* Jul */, 2).toISOString())
expect(result).to.be.equal(6)
assert(result === 6)
})

@@ -18,5 +19,5 @@

var result = getMonth(new Date(2014, 3 /* Apr */, 2).getTime())
expect(result).to.be.equal(3)
assert(result === 3)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var getQuarter = require('../get_quarter')

@@ -6,3 +7,3 @@

var result = getQuarter(new Date(2014, 6 /* Jul */, 2))
expect(result).to.be.equal(3)
assert(result === 3)
})

@@ -12,3 +13,3 @@

var result = getQuarter(new Date(2014, 3 /* Apr */, 2).toISOString())
expect(result).to.be.equal(2)
assert(result === 2)
})

@@ -18,5 +19,5 @@

var result = getQuarter(new Date(2014, 3 /* Apr */, 2).getTime())
expect(result).to.be.equal(2)
assert(result === 2)
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var getSeconds = require('../get_seconds')
describe('getSeconds', function() {
it('returns amount of seconds of given date', function() {
it('returns seconds of given date', function() {
var result = getSeconds(new Date(2012, 1 /* Feb */, 29, 11, 45, 5, 123))
expect(result).to.be.equal(5)
assert(result === 5)
})

@@ -11,3 +12,3 @@

var result = getSeconds(new Date(2014, 6 /* Jul */, 2, 5, 15).toISOString())
expect(result).to.be.equal(0)
assert(result === 0)
})

@@ -17,5 +18,5 @@

var result = getSeconds(new Date(2014, 3 /* Apr */, 2, 23, 30, 42).getTime())
expect(result).to.be.equal(42)
assert(result === 42)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var getYear = require('../get_year')

@@ -6,3 +7,3 @@

var result = getYear(new Date(2014, 6 /* Jul */, 2))
expect(result).to.be.equal(2014)
assert(result === 2014)
})

@@ -12,10 +13,10 @@

var result = getYear(new Date(700, 6 /* Jul */, 2).toISOString())
expect(result).to.be.equal(700)
assert(result === 700)
})
it('accepts timestamp', function() {
var result = getYear(new Date(50000, 3 /* Apr */, 2).getTime())
expect(result).to.be.equal(50000)
var result = getYear(new Date(20000, 3 /* Apr */, 2).getTime())
assert(result === 20000)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isAfter = require('../is_after')
describe('isAfter', function() {
it('returns true if first date is after second one ', function() {
it('returns true if first date is after second one', function() {
var result = isAfter(

@@ -9,6 +10,6 @@ new Date(1989, 6 /* Jul */, 10),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if first date is before second one ', function() {
it('returns false if first date is before second one', function() {
var result = isAfter(

@@ -18,6 +19,6 @@ new Date(1987, 1 /* Feb */, 11),

)
expect(result).to.be.false
assert(result === false)
})
it('returns false if first date is equal to second one ', function() {
it('returns false if first date is equal to second one', function() {
var result = isAfter(

@@ -27,6 +28,6 @@ new Date(1989, 6 /* Jul */, 10),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isAfter(

@@ -36,6 +37,6 @@ new Date(1989, 6 /* Jul */, 10).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isAfter(

@@ -45,5 +46,5 @@ new Date(1989, 6 /* Jul */, 10).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isBefore = require('../is_before')
describe('isBefore', function() {
it('returns true if first date is before second one ', function() {
it('returns true if first date is before second one', function() {
var result = isBefore(

@@ -9,6 +10,6 @@ new Date(1987, 1 /* Feb */, 11),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if first date is after second one ', function() {
it('returns false if first date is after second one', function() {
var result = isBefore(

@@ -18,6 +19,6 @@ new Date(1989, 6 /* Jul */, 10),

)
expect(result).to.be.false
assert(result === false)
})
it('returns false if first date is equal to second one ', function() {
it('returns false if first date is equal to second one', function() {
var result = isBefore(

@@ -27,6 +28,6 @@ new Date(1989, 6 /* Jul */, 10),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isBefore(

@@ -36,6 +37,6 @@ new Date(1987, 1 /* Feb */, 11).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isBefore(

@@ -45,5 +46,5 @@ new Date(1987, 1 /* Feb */, 11).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isEqual = require('../is_equal')
describe('isEqual', function() {
it('returns true if passed dates are equal', function() {
it('returns true if given dates are equal', function() {
var result = isEqual(

@@ -9,6 +10,6 @@ new Date(1987, 1 /* Feb */, 11),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed dates are not equal', function() {
it('returns false if given dates are not equal', function() {
var result = isEqual(

@@ -18,6 +19,6 @@ new Date(1989, 6 /* Jul */, 10),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isEqual(

@@ -27,6 +28,6 @@ new Date(1987, 1 /* Feb */, 11).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isEqual(

@@ -36,5 +37,5 @@ new Date(1987, 1 /* Feb */, 11).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,26 +1,27 @@

var assert = require('power-assert')
var isFirstDayOfMonth = require('../is_first_day_of_month')
describe('isFirstDayOfMonth', function() {
it('returns true if passed is last day of month', function() {
it('returns true if given date is in last day of month', function() {
var result = isFirstDayOfMonth(new Date(2014, 9 /* Oct */, 1))
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed is not last day of month', function() {
it('returns false if given date is not in last day of month', function() {
var result = isFirstDayOfMonth(new Date(2014, 9 /* Oct */, 2))
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var date = new Date(2014, 9 /* Oct */, 1).toISOString()
var result = isFirstDayOfMonth(date)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var date = new Date(2014, 9 /* Oct */, 1).getTime()
var result = isFirstDayOfMonth(date)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var isFuture = require('../is_future')

@@ -14,27 +15,27 @@

it('returns true if passed date is future', function() {
it('returns true if given date is in future', function() {
var result = isFuture(new Date(2014, 9 /* Oct */, 31))
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed date is past', function() {
it('returns false if given date is in past', function() {
var result = isFuture(new Date(2014, 8 /* Sep */, 1))
expect(result).to.be.false
assert(result === false)
})
it('returns false if passed date is current date', function() {
it('returns false if given date is now', function() {
var result = isFuture(new Date(2014, 8 /* Sep */, 25))
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isFuture(new Date(2014, 9 /* Oct */, 31).toISOString())
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isFuture(new Date(2014, 9 /* Oct */, 31).getTime())
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,26 +1,27 @@

var assert = require('power-assert')
var isLastDayOfMonth = require('../is_last_day_of_month')
describe('isLastDayOfMonth', function() {
it('returns true if passed is last day of month', function() {
it('returns true if given date is in last day of month', function() {
var result = isLastDayOfMonth(new Date(2014, 9 /* Oct */, 31))
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed is not last day of month', function() {
it('returns false if given date is not in last day of month', function() {
var result = isLastDayOfMonth(new Date(2014, 9 /* Oct */, 30))
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var date = new Date(2014, 9 /* Oct */, 31).toISOString()
var result = isLastDayOfMonth(date)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var date = new Date(2014, 9 /* Oct */, 31).getTime()
var result = isLastDayOfMonth(date)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,12 +1,13 @@

var assert = require('power-assert')
var isLeapYear = require('../is_leap_year')
describe('isLeapYear', function() {
it('returns true if passed date is in the leap year', function() {
it('returns true if given date is in the leap year', function() {
var result = isLeapYear(new Date(2012, 6 /* Jul */, 2))
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed date is not in the leap year', function() {
it('returns false if given date is not in the leap year', function() {
var result = isLeapYear(new Date(2014, 6 /* Jul */, 2))
expect(result).to.be.false
assert(result === false)
})

@@ -16,3 +17,3 @@

var result = isLeapYear(new Date(2100, 6 /* Jul */, 2))
expect(result).to.be.false
assert(result === false)
})

@@ -22,17 +23,17 @@

var result = isLeapYear(new Date(2000, 6 /* Jul */, 2))
expect(result).to.be.true
assert(result === true)
})
it('allows to pass string', function() {
it('accepts string', function() {
var date = new Date(2012, 6 /* Jul */, 2).toISOString()
var result = isLeapYear(date)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var date = new Date(2012, 6 /* Jul */, 2).getTime()
var result = isLeapYear(date)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var isPast = require('../is_past')

@@ -14,27 +15,27 @@

it('returns true if passed date is past', function() {
it('returns true if given date is in past', function() {
var result = isPast(new Date(2014, 6 /* Jul */, 2))
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed date is future', function() {
it('returns false if given date is in future', function() {
var result = isPast(new Date(2014, 11 /* Dec */, 31))
expect(result).to.be.false
assert(result === false)
})
it('returns false if passed date is current date', function() {
it('returns false if given date is current date', function() {
var result = isPast(new Date(2014, 8 /* Sep */, 25))
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isPast(new Date(2014, 6 /* Jul */, 2).toISOString())
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isPast(new Date(2014, 6 /* Jul */, 2).getTime())
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isSameDay = require('../is_same_day')
describe('isSameDay', function() {
it('returns true if passed dates has same day', function() {
it('returns true if given dates have same day', function() {
var result = isSameDay(

@@ -9,6 +10,6 @@ new Date(2014, 8 /* Sep */, 4, 6, 0),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed dates has different days', function() {
it('returns false if given dates have different days', function() {
var result = isSameDay(

@@ -18,6 +19,6 @@ new Date(2014, 8 /* Sep */, 4, 23, 59),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isSameDay(

@@ -27,6 +28,6 @@ new Date(2014, 8 /* Sep */, 4, 6, 0).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isSameDay(

@@ -36,5 +37,5 @@ new Date(2014, 8 /* Sep */, 4, 6, 0).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isSameHour = require('../is_same_hour')
describe('isSameHour', function() {
it('returns true if passed dates has same hour', function() {
it('returns true if given dates have same hour', function() {
var result = isSameHour(

@@ -9,6 +10,6 @@ new Date(2014, 8 /* Sep */, 4, 6, 0),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed dates has different hours', function() {
it('returns false if given dates have different hours', function() {
var result = isSameHour(

@@ -18,6 +19,6 @@ new Date(2014, 8 /* Sep */, 4, 6, 0),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isSameHour(

@@ -27,6 +28,6 @@ new Date(2014, 8 /* Sep */, 4, 18, 0).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isSameHour(

@@ -36,5 +37,5 @@ new Date(2014, 8 /* Sep */, 4, 18, 0).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isSameMinute = require('../is_same_minute')
describe('isSameMinute', function() {
it('returns true if passed dates has same minute', function() {
it('returns true if given dates have same minute', function() {
var result = isSameMinute(

@@ -9,6 +10,6 @@ new Date(2014, 8 /* Sep */, 4, 6, 30),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed dates has different minutes', function() {
it('returns false if given dates have different minutes', function() {
var result = isSameMinute(

@@ -18,6 +19,6 @@ new Date(2014, 8 /* Sep */, 4, 6, 30, 59),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isSameMinute(

@@ -27,6 +28,6 @@ new Date(2014, 8 /* Sep */, 4, 18, 45).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isSameMinute(

@@ -36,5 +37,5 @@ new Date(2014, 8 /* Sep */, 4, 18, 45).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isSameMonth = require('../is_same_month')
describe('isSameMonth', function() {
it('returns true if passed dates has same month (and year)', function() {
it('returns true if given dates have same month (and year)', function() {
var result = isSameMonth(

@@ -9,6 +10,6 @@ new Date(2014, 8 /* Sep */, 2),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed dates has different months', function() {
it('returns false if given dates have different months', function() {
var result = isSameMonth(

@@ -18,6 +19,6 @@ new Date(2014, 8 /* Sep */, 2),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isSameMonth(

@@ -27,6 +28,6 @@ new Date(2014, 8 /* Sep */, 2).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isSameMonth(

@@ -36,5 +37,5 @@ new Date(2014, 8 /* Sep */, 2).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isSameQuarter = require('../is_same_quarter')
describe('isSameQuarter', function() {
it('returns true if passed dates has same quarter (and year)', function() {
it('returns true if given dates have same quarter (and year)', function() {
var result = isSameQuarter(

@@ -9,6 +10,6 @@ new Date(2014, 0 /* Jan */, 1),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed dates has different quarters', function() {
it('returns false if given dates have different quarters', function() {
var result = isSameQuarter(

@@ -18,6 +19,6 @@ new Date(2014, 0 /* Jan */, 1),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isSameQuarter(

@@ -27,6 +28,6 @@ new Date(2014, 6 /* Jul */, 2).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isSameQuarter(

@@ -36,5 +37,5 @@ new Date(2014, 6 /* Jul */, 2).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isSameSecond = require('../is_same_second')
describe('isSameSecond', function() {
it('returns true if passed dates has same second', function() {
it('returns true if given dates have same second', function() {
var result = isSameSecond(

@@ -9,6 +10,6 @@ new Date(2014, 8 /* Sep */, 4, 6, 30, 15),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed dates has different seconds', function() {
it('returns false if given dates have different seconds', function() {
var result = isSameSecond(

@@ -18,6 +19,6 @@ new Date(2014, 8 /* Sep */, 4, 6, 30, 58, 999),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isSameSecond(

@@ -27,6 +28,6 @@ new Date(2014, 8 /* Sep */, 4, 18, 45, 30).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isSameSecond(

@@ -36,5 +37,5 @@ new Date(2014, 8 /* Sep */, 4, 18, 45, 30).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isSameWeek = require('../is_same_week')
describe('isSameWeek', function() {
it('returns true if passed dates belongs to the same week', function() {
it('returns true if given dates have same week', function() {
var result = isSameWeek(

@@ -9,6 +10,6 @@ new Date(2014, 7 /* Aug */, 31),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed dates do not belongs to the same week', function() {
it('returns false if given dates have different weeks', function() {
var result = isSameWeek(

@@ -18,6 +19,6 @@ new Date(2014, 7 /* Aug */, 30),

)
expect(result).to.be.false
assert(result === false)
})
it('allow to specify when week starts', function() {
it('allows to specify when week starts', function() {
var result = isSameWeek(

@@ -28,6 +29,6 @@ new Date(2014, 7 /* Aug */, 31),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isSameWeek(

@@ -37,6 +38,6 @@ new Date(2014, 7 /* Aug */, 31).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isSameWeek(

@@ -46,5 +47,5 @@ new Date(2014, 7 /* Aug */, 31).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isSameYear = require('../is_same_year')
describe('isSameYear', function() {
it('returns true if passed dates has same year', function() {
it('returns true if given dates have same year', function() {
var result = isSameYear(

@@ -9,6 +10,6 @@ new Date(2014, 8 /* Sep */, 2),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed dates has different years', function() {
it('returns false if given dates have different years', function() {
var result = isSameYear(

@@ -18,6 +19,6 @@ new Date(2014, 8 /* Sep */, 2),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isSameYear(

@@ -27,6 +28,6 @@ new Date(2014, 8 /* Sep */, 2).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isSameYear(

@@ -36,5 +37,5 @@ new Date(2014, 8 /* Sep */, 2).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var isToday = require('../is_today')

@@ -6,3 +7,3 @@

this.clock = sinon.useFakeTimers(
new Date(2014, 8 /* starts from 0 */, 25).getTime()
new Date(2014, 8 /* Sep */, 25).getTime()
)

@@ -15,22 +16,22 @@ })

it('returns true if passed is weekend', function() {
var result = isToday(new Date(2014, 8 /* starts from 0 */, 25))
expect(result).to.be.true
it('returns true if given date is today', function() {
var result = isToday(new Date(2014, 8 /* Sep */, 25))
assert(result === true)
})
it('returns false if passed date is not today', function() {
var result = isToday(new Date(2014, 8 /* starts from 0 */, 26))
expect(result).to.be.false
it('returns false if given date is not today', function() {
var result = isToday(new Date(2014, 8 /* Sep */, 26))
assert(result === false)
})
it('allows to pass string', function() {
var result = isToday(new Date(2014, 8 /* starts from 0 */, 25).toString())
expect(result).to.be.true
it('accepts string', function() {
var result = isToday(new Date(2014, 8 /* Sep */, 25).toString())
assert(result === true)
})
it('allows to pass timestamp', function() {
var result = isToday(new Date(2014, 8 /* starts from 0 */, 25).getTime())
expect(result).to.be.true
it('accepts timestamp', function() {
var result = isToday(new Date(2014, 8 /* Sep */, 25).getTime())
assert(result === true)
})
})

@@ -0,24 +1,25 @@

var assert = require('power-assert')
var isWeekend = require('../is_weekend')
describe('isWeekend', function() {
it('returns true if passed is weekend', function() {
var result = isWeekend(new Date(2014, 9 /* starts from 0 */, 5))
expect(result).to.be.true
it('returns true if given date is in weekend', function() {
var result = isWeekend(new Date(2014, 9 /* Oct */, 5))
assert(result === true)
})
it('returns false if passed date is not weekend', function() {
var result = isWeekend(new Date(2014, 9 /* starts from 0 */, 6))
expect(result).to.be.false
it('returns false if given date is not weekend', function() {
var result = isWeekend(new Date(2014, 9 /* Oct */, 6))
assert(result === false)
})
it('allows to pass string', function() {
var result = isWeekend(new Date(2014, 9 /* starts from 0 */, 5).toString())
expect(result).to.be.true
it('accepts string', function() {
var result = isWeekend(new Date(2014, 9 /* Oct */, 5).toString())
assert(result === true)
})
it('allows to pass timestamp', function() {
var result = isWeekend(new Date(2014, 9 /* starts from 0 */, 5).getTime())
expect(result).to.be.true
it('accepts timestamp', function() {
var result = isWeekend(new Date(2014, 9 /* Oct */, 5).getTime())
assert(result === true)
})
})

@@ -0,5 +1,6 @@

var assert = require('power-assert')
var isWithinRange = require('../is_within_range')
describe('isWithinRange', function() {
it('returns true if passed date within the range', function() {
it('returns true if given date in within given range', function() {
var result = isWithinRange(

@@ -10,6 +11,6 @@ new Date(2014, 9 /* Oct */, 31),

)
expect(result).to.be.true
assert(result === true)
})
it('returns true if passed date has the same time as left boundary', function() {
it('returns true if given date has same time as left boundary', function() {
var result = isWithinRange(

@@ -20,6 +21,6 @@ new Date(2014, 8 /* Sep */, 1),

)
expect(result).to.be.true
assert(result === true)
})
it('returns true if passed date has the same time as right boundary', function() {
it('returns true if given date has same time as right boundary', function() {
var result = isWithinRange(

@@ -30,6 +31,6 @@ new Date(2014, 11 /* Dec */, 31),

)
expect(result).to.be.true
assert(result === true)
})
it('returns false if passed date outside of the range', function() {
it('returns false if given date in outside of range', function() {
var result = isWithinRange(

@@ -40,6 +41,6 @@ new Date(2014, 1 /* Feb */, 11),

)
expect(result).to.be.false
assert(result === false)
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = isWithinRange(

@@ -50,6 +51,6 @@ new Date(2014, 9 /* Oct */, 31).toISOString(),

)
expect(result).to.be.true
assert(result === true)
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = isWithinRange(

@@ -60,5 +61,15 @@ new Date(2014, 9 /* Oct */, 31).getTime(),

)
expect(result).to.be.true
assert(result === true)
})
it('throws exception if start date is after end date', function() {
var block = isWithinRange.bind(
null,
new Date(2014, 9 /* Oct */, 31),
new Date(2014, 11 /* Dec */, 31),
new Date(2014, 8 /* Sep */, 1)
)
assert.throws(block)
})
})

@@ -0,8 +1,9 @@

var assert = require('power-assert')
var lastDayOfMonth = require('../last_day_of_month')
describe('lastDayOfMonth', function() {
it('returns date with time setted to 00:00:00.000 and date setted to last day of month', function() {
it('returns date with time setted to 00:00:00 and date setted to last day of month', function() {
var date = new Date(2014, 8 /* Sep */, 2, 11, 55, 0)
var result = lastDayOfMonth(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 30)

@@ -15,3 +16,3 @@ )

var result = lastDayOfMonth(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 11 /* Dec */, 31)

@@ -24,3 +25,3 @@ )

var result = lastDayOfMonth(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 7 /* Aug */, 31)

@@ -33,3 +34,3 @@ )

lastDayOfMonth(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})

@@ -41,3 +42,3 @@

var result = lastDayOfMonth(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2012, 1 /* Feb */, 29)

@@ -50,3 +51,3 @@ )

var result = lastDayOfMonth(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 1 /* Feb */, 28)

@@ -53,0 +54,0 @@ )

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var lastDayOfQuarter = require('../last_day_of_quarter')

@@ -7,3 +8,3 @@

var result = lastDayOfQuarter(date)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 30))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 30))
})

@@ -14,3 +15,3 @@

var result = lastDayOfQuarter(date)
expect(result).to.be.eql(new Date(2014, 2 /* Mar */, 31))
assert.deepEqual(result, new Date(2014, 2 /* Mar */, 31))
})

@@ -21,3 +22,3 @@

var result = lastDayOfQuarter(date)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 30))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 30))
})

@@ -28,5 +29,5 @@

lastDayOfQuarter(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var lastDayOfWeek = require('../last_day_of_week')

@@ -7,3 +8,3 @@

var result = lastDayOfWeek(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 6)

@@ -16,3 +17,3 @@ )

var result = lastDayOfWeek(date, 1)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 7)

@@ -25,3 +26,3 @@ )

var result = lastDayOfWeek(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 6)

@@ -34,3 +35,3 @@ )

var result = lastDayOfWeek(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 6)

@@ -43,3 +44,3 @@ )

lastDayOfWeek(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})

@@ -52,3 +53,3 @@

var result = lastDayOfWeek(date, 3)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 7))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 7))
})

@@ -61,3 +62,3 @@ })

var result = lastDayOfWeek(date, 3)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 14))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 14))
})

@@ -70,3 +71,3 @@ })

var result = lastDayOfWeek(date, 3)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 14))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 14))
})

@@ -78,3 +79,3 @@ })

var result = lastDayOfWeek(date, 5)
expect(result).to.be.eql(new Date(2015, 0 /* Jan */, 1))
assert.deepEqual(result, new Date(2015, 0 /* Jan */, 1))
})

@@ -81,0 +82,0 @@ })

@@ -0,8 +1,9 @@

var assert = require('power-assert')
var lastDayOfYear = require('../last_day_of_year')
describe('lastDayOfYear', function() {
it('returns date with time setted to 00:00:00.000 and date setted to last day of year', function() {
it('returns date with time setted to 00:00:00 and date setted to last day of year', function() {
var date = new Date(2014, 8 /* Sep */, 2, 11, 55, 0)
var result = lastDayOfYear(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 11 /* Dec */, 31)

@@ -15,3 +16,3 @@ )

var result = lastDayOfYear(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 11 /* Dec */, 31)

@@ -24,3 +25,3 @@ )

var result = lastDayOfYear(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 11 /* Dec */, 31)

@@ -33,5 +34,5 @@ )

lastDayOfYear(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var max = require('../max')

@@ -9,3 +10,3 @@

)
expect(result).to.be.eql(new Date(1989, 6 /* Jul */, 10))
assert.deepEqual(result, new Date(1989, 6 /* Jul */, 10))
})

@@ -20,6 +21,6 @@

)
expect(result).to.be.eql(new Date(1995, 6 /* Jul */, 2))
assert.deepEqual(result, new Date(1995, 6 /* Jul */, 2))
})
it('allows to pass strings', function() {
it('accepts strings', function() {
var result = max(

@@ -29,6 +30,6 @@ new Date(1987, 1 /* Feb */, 11).toISOString(),

)
expect(result).to.be.eql(new Date(1989, 6 /* Jul */, 10))
assert.deepEqual(result, new Date(1989, 6 /* Jul */, 10))
})
it('allows to pass timestamps', function() {
it('accepts timestamps', function() {
var result = max(

@@ -38,5 +39,5 @@ new Date(1989, 6 /* Jul */, 10).getTime(),

)
expect(result).to.be.eql(new Date(1989, 6 /* Jul */, 10))
assert.deepEqual(result, new Date(1989, 6 /* Jul */, 10))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var min = require('../min')

@@ -9,3 +10,3 @@

)
expect(result).to.be.eql(new Date(1987, 1 /* Feb */, 11))
assert.deepEqual(result, new Date(1987, 1 /* Feb */, 11))
})

@@ -20,6 +21,6 @@

)
expect(result).to.be.eql(new Date(1985, 6 /* Jul */, 2))
assert.deepEqual(result, new Date(1985, 6 /* Jul */, 2))
})
it('allows to pass strings', function() {
it('accepts strings', function() {
var result = min(

@@ -29,6 +30,6 @@ new Date(1987, 1 /* Feb */, 11).toISOString(),

)
expect(result).to.be.eql(new Date(1987, 1 /* Feb */, 11))
assert.deepEqual(result, new Date(1987, 1 /* Feb */, 11))
})
it('allows to pass timestamps', function() {
it('accepts timestamps', function() {
var result = min(

@@ -38,5 +39,5 @@ new Date(1989, 6 /* Jul */, 10).getTime(),

)
expect(result).to.be.eql(new Date(1987, 1 /* Feb */, 11))
assert.deepEqual(result, new Date(1987, 1 /* Feb */, 11))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var parse = require('../parse')

@@ -7,3 +8,3 @@

var result = parse('2014')
expect(result).to.be.eql(new Date(2014, 0, 1))
assert.deepEqual(result, new Date(2014, 0, 1))
})

@@ -15,3 +16,3 @@ })

var result = parse('2014-02')
expect(result).to.be.eql(new Date(2014, 1, 1))
assert.deepEqual(result, new Date(2014, 1, 1))
})

@@ -23,3 +24,3 @@ })

var result = parse('2014-W02')
expect(result).to.be.eql(new Date(2014, 0, 6))
assert.deepEqual(result, new Date(2014, 0, 6))
})

@@ -29,3 +30,3 @@

var result = parse('2014W02')
expect(result).to.be.eql(new Date(2014, 0, 6))
assert.deepEqual(result, new Date(2014, 0, 6))
})

@@ -37,3 +38,3 @@ })

var result = parse('2014-02-11')
expect(result).to.be.eql(new Date(2014, 1, 11))
assert.deepEqual(result, new Date(2014, 1, 11))
})

@@ -43,3 +44,3 @@

var result = parse('20140211')
expect(result).to.be.eql(new Date(2014, 1, 11))
assert.deepEqual(result, new Date(2014, 1, 11))
})

@@ -51,3 +52,3 @@ })

var result = parse('2014-W02-7')
expect(result).to.be.eql(new Date(2014, 0, 12))
assert.deepEqual(result, new Date(2014, 0, 12))
})

@@ -57,3 +58,3 @@

var result = parse('2014W027')
expect(result).to.be.eql(new Date(2014, 0, 12))
assert.deepEqual(result, new Date(2014, 0, 12))
})

@@ -65,3 +66,3 @@ })

var result = parse('2014-026')
expect(result).to.be.eql(new Date(2014, 0, 26))
assert.deepEqual(result, new Date(2014, 0, 26))
})

@@ -71,3 +72,3 @@

var result = parse('2014026')
expect(result).to.be.eql(new Date(2014, 0, 26))
assert.deepEqual(result, new Date(2014, 0, 26))
})

@@ -79,3 +80,3 @@ })

var result = parse('2014-02-11T11:30')
expect(result).to.be.eql(new Date(2014, 1, 11, 11, 30))
assert.deepEqual(result, new Date(2014, 1, 11, 11, 30))
})

@@ -85,3 +86,3 @@

var result = parse('2014-02-11T1130')
expect(result).to.be.eql(new Date(2014, 1, 11, 11, 30))
assert.deepEqual(result, new Date(2014, 1, 11, 11, 30))
})

@@ -91,3 +92,3 @@

var result = parse('2014-02-11T2400')
expect(result).to.be.eql(new Date(2014, 1, 11, 0, 0))
assert.deepEqual(result, new Date(2014, 1, 11, 0, 0))
})

@@ -99,3 +100,3 @@ })

var result = parse('2014-02-11T11.5')
expect(result).to.be.eql(new Date(2014, 1, 11, 11, 30))
assert.deepEqual(result, new Date(2014, 1, 11, 11, 30))
})

@@ -105,3 +106,3 @@

var result = parse('2014-02-11T11:30.5')
expect(result).to.be.eql(new Date(2014, 1, 11, 11, 30, 30))
assert.deepEqual(result, new Date(2014, 1, 11, 11, 30, 30))
})

@@ -111,3 +112,3 @@

var result = parse('2014-02-11T11:30:30.768')
expect(result).to.be.eql(new Date(2014, 1, 11, 11, 30, 30, 768))
assert.deepEqual(result, new Date(2014, 1, 11, 11, 30, 30, 768))
})

@@ -117,3 +118,3 @@

var result = parse('2014-02-11T11,5')
expect(result).to.be.eql(new Date(2014, 1, 11, 11, 30))
assert.deepEqual(result, new Date(2014, 1, 11, 11, 30))
})

@@ -126,3 +127,3 @@ })

var result = parse('2014-10-25T06:46:20Z')
expect(result).to.be.eql(new Date('2014-10-25T13:46:20+07:00'))
assert.deepEqual(result, new Date('2014-10-25T13:46:20+07:00'))
})

@@ -132,3 +133,3 @@

var result = parse('2014-10-25T13:46:20+07:00')
expect(result).to.be.eql(new Date('2014-10-25T13:46:20+07:00'))
assert.deepEqual(result, new Date('2014-10-25T13:46:20+07:00'))
})

@@ -138,3 +139,3 @@

var result = parse('2014-10-25T03:46:20-0300')
expect(result).to.be.eql(new Date('2014-10-25T13:46:20+07:00'))
assert.deepEqual(result, new Date('2014-10-25T13:46:20+07:00'))
})

@@ -144,3 +145,3 @@

var result = parse('2014-10-25T13:46:20+07')
expect(result).to.be.eql(new Date('2014-10-25T13:46:20+07:00'))
assert.deepEqual(result, new Date('2014-10-25T13:46:20+07:00'))
})

@@ -153,3 +154,3 @@ })

var result = parse(new Date(2014, 8 /* Sep */, 1, 11).toString())
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 11))
})

@@ -156,0 +157,0 @@ })

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var setDate = require('../set_date')

@@ -6,3 +7,3 @@

var result = setDate(new Date(2014, 8 /* Sep */, 1), 30)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 30))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 30))
})

@@ -12,3 +13,3 @@

var result = setDate(new Date(2014, 8 /* Sep */, 1).toISOString(), 18)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 18))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 18))
})

@@ -18,3 +19,3 @@

var result = setDate(new Date(2014, 8 /* Sep */, 1).getTime(), 25)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 25))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 25))
})

@@ -25,5 +26,5 @@

setDate(date, 20)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var setDayOfYear = require('../set_day_of_year')

@@ -6,3 +7,3 @@

var result = setDayOfYear(new Date(2014, 6 /* Jul */, 2), 2)
expect(result).to.be.eql(new Date(2014, 0 /* Jan */, 2))
assert.deepEqual(result, new Date(2014, 0 /* Jan */, 2))
})

@@ -12,3 +13,3 @@

var result = setDayOfYear(new Date(2014, 6 /* Jul */, 2).toISOString(), 60)
expect(result).to.be.eql(new Date(2014, 2 /* Mar */, 1))
assert.deepEqual(result, new Date(2014, 2 /* Mar */, 1))
})

@@ -18,3 +19,3 @@

var result = setDayOfYear(new Date(2014, 6 /* Jul */, 2).getTime(), 60)
expect(result).to.be.eql(new Date(2014, 2 /* Mar */, 1))
assert.deepEqual(result, new Date(2014, 2 /* Mar */, 1))
})

@@ -25,5 +26,5 @@

setDayOfYear(date, 365)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 2))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 2))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var setDay = require('../set_day')

@@ -6,3 +7,3 @@

var result = setDay(new Date(2014, 8 /* Sep */, 1), 0)
expect(result).to.be.eql(new Date(2014, 7 /* Aug */, 31))
assert.deepEqual(result, new Date(2014, 7 /* Aug */, 31))
})

@@ -12,3 +13,3 @@

var result = setDay(new Date(2014, 8 /* Sep */, 1), 0, 1)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 7))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 7))
})

@@ -18,3 +19,3 @@

var result = setDay(new Date(2014, 8 /* Sep */, 1), 8)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 8))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 8))
})

@@ -24,3 +25,3 @@

var result = setDay(new Date(2014, 8 /* Sep */, 1).toISOString(), 5)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 5))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 5))
})

@@ -30,3 +31,3 @@

var result = setDay(new Date(2014, 8 /* Sep */, 1).getTime(), 3)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 3))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 3))
})

@@ -37,5 +38,5 @@

setDay(date, 3)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var setHours = require('../set_hours')

@@ -6,3 +7,3 @@

var result = setHours(new Date(2014, 8 /* Sep */, 1, 11, 30), 4)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 4, 30))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 4, 30))
})

@@ -12,3 +13,3 @@

var result = setHours(new Date(2014, 8 /* Sep */, 1, 11).toISOString(), 18)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 18))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 18))
})

@@ -18,3 +19,3 @@

var result = setHours(new Date(2014, 8 /* Sep */, 1, 11).getTime(), 5)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 5))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 5))
})

@@ -25,5 +26,5 @@

setHours(date, 12)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1, 11))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var setISOWeek = require('../set_iso_week')

@@ -6,13 +7,13 @@

var result = setISOWeek(new Date(2004, 7 /* Aug */, 7), 53)
expect(result).to.be.eql(new Date(2005, 0 /* Jan */, 1))
assert.deepEqual(result, new Date(2005, 0 /* Jan */, 1))
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = setISOWeek(new Date(2009, 11 /* Dec */, 2).toISOString(), 1)
expect(result).to.be.eql(new Date(2008, 11 /* Dec */, 31))
assert.deepEqual(result, new Date(2008, 11 /* Dec */, 31))
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = setISOWeek(new Date(2009, 11 /* Dec */, 2).getTime(), 1)
expect(result).to.be.eql(new Date(2008, 11 /* Dec */, 31))
assert.deepEqual(result, new Date(2008, 11 /* Dec */, 31))
})

@@ -23,5 +24,5 @@

setISOWeek(date, 52)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 2))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 2))
})
})

@@ -0,17 +1,18 @@

var assert = require('power-assert')
var setISOYear = require('../set_iso_year')
describe('setISOYear', function() {
it('sets year of given date, saving ISO week and day of week', function() {
it('sets ISO year of given date, saving ISO week and day of week', function() {
var result = setISOYear(new Date(2008, 11 /* Dec */, 29), 2007)
expect(result).to.be.eql(new Date(2007, 0 /* Jan */, 1))
assert.deepEqual(result, new Date(2007, 0 /* Jan */, 1))
})
it('allows to pass string', function() {
it('accepts string', function() {
var result = setISOYear(new Date(2010, 0 /* Jan */, 2).toISOString(), 2004)
expect(result).to.be.eql(new Date(2005, 0 /* Jan */, 1))
assert.deepEqual(result, new Date(2005, 0 /* Jan */, 1))
})
it('allows to pass timestamp', function() {
it('accepts timestamp', function() {
var result = setISOYear(new Date(2010, 0 /* Jan */, 2).getTime(), 2004)
expect(result).to.be.eql(new Date(2005, 0 /* Jan */, 1))
assert.deepEqual(result, new Date(2005, 0 /* Jan */, 1))
})

@@ -22,5 +23,5 @@

setISOYear(date, 2000)
expect(date).to.be.eql(new Date(2008, 11 /* Dec */, 29))
assert.deepEqual(date, new Date(2008, 11 /* Dec */, 29))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var setMilliseconds = require('../set_milliseconds')
describe('setMilliseconds', function() {
it('sets amount of milliseconds', function() {
it('sets milliseconds', function() {
var result = setMilliseconds(new Date(2014, 8 /* Sep */, 1, 11, 30, 40, 500), 300)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 30, 40, 300))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 11, 30, 40, 300))
})

@@ -11,3 +12,3 @@

var result = setMilliseconds(new Date(2014, 8 /* Sep */, 1, 11).toISOString(), 123)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 0, 0, 123))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 11, 0, 0, 123))
})

@@ -17,3 +18,3 @@

var result = setMilliseconds(new Date(2014, 8 /* Sep */, 1, 11, 30, 15, 750).getTime(), 755)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 30, 15, 755))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 11, 30, 15, 755))
})

@@ -24,5 +25,5 @@

setMilliseconds(date, 137)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 30, 40, 500))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1, 11, 30, 40, 500))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var setMinutes = require('../set_minutes')
describe('setMinutes', function() {
it('sets amount of minutes', function() {
it('sets minutes', function() {
var result = setMinutes(new Date(2014, 8 /* Sep */, 1, 11, 30, 40), 45)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 45, 40))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 11, 45, 40))
})

@@ -11,3 +12,3 @@

var result = setMinutes(new Date(2014, 8 /* Sep */, 1, 11).toISOString(), 18)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 18))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 11, 18))
})

@@ -17,3 +18,3 @@

var result = setMinutes(new Date(2014, 8 /* Sep */, 1, 11, 30).getTime(), 5)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 5))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 11, 5))
})

@@ -24,5 +25,5 @@

setMinutes(date, 15)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 30))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1, 11, 30))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var setMonth = require('../set_month')
describe('setMonth', function() {
it('set index of month', function() {
it('set month', function() {
var result = setMonth(new Date(2014, 8 /* Sep */, 1), 1)
expect(result).to.be.eql(new Date(2014, 1 /* Feb */, 1))
assert.deepEqual(result, new Date(2014, 1 /* Feb */, 1))
})

@@ -11,3 +12,3 @@

var result = setMonth(new Date(2014, 11 /* Dec */, 31), 1)
expect(result).to.be.eql(new Date(2014, 1 /* Feb */, 28))
assert.deepEqual(result, new Date(2014, 1 /* Feb */, 28))
})

@@ -17,3 +18,3 @@

var result = setMonth(new Date(2014, 8 /* Sep */, 1).toISOString(), 11)
expect(result).to.be.eql(new Date(2014, 11 /* Dec */, 1))
assert.deepEqual(result, new Date(2014, 11 /* Dec */, 1))
})

@@ -23,3 +24,3 @@

var result = setMonth(new Date(2014, 8 /* Sep */, 1).getTime(), 11)
expect(result).to.be.eql(new Date(2014, 11 /* Dec */, 1))
assert.deepEqual(result, new Date(2014, 11 /* Dec */, 1))
})

@@ -30,5 +31,5 @@

setMonth(date, 5)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var setQuarter = require('../set_quarter')

@@ -6,3 +7,3 @@

var result = setQuarter(new Date(2014, 6 /* Jul */, 2), 1)
expect(result).to.be.eql(new Date(2014, 0 /* Jan */, 2))
assert.deepEqual(result, new Date(2014, 0 /* Jan */, 2))
})

@@ -12,3 +13,3 @@

var result = setQuarter(new Date(2014, 10 /* Nov */, 30), 1)
expect(result).to.be.eql(new Date(2014, 1 /* Feb */, 28))
assert.deepEqual(result, new Date(2014, 1 /* Feb */, 28))
})

@@ -18,3 +19,3 @@

var result = setQuarter(new Date(2014, 6 /* Jul */, 1).toISOString(), 4)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 1))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 1))
})

@@ -24,3 +25,3 @@

var result = setQuarter(new Date(2014, 6 /* Jul */, 1).getTime(), 4)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 1))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 1))
})

@@ -31,5 +32,5 @@

setQuarter(date, 2)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 1))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 1))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var setSeconds = require('../set_seconds')
describe('setSeconds', function() {
it('sets amount of seconds', function() {
it('sets seconds', function() {
var result = setSeconds(new Date(2014, 8 /* Sep */, 1, 11, 30, 40, 500), 45)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 30, 45, 500))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 11, 30, 45, 500))
})

@@ -11,3 +12,3 @@

var result = setSeconds(new Date(2014, 8 /* Sep */, 1, 11).toISOString(), 18)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 0, 18))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 11, 0, 18))
})

@@ -17,3 +18,3 @@

var result = setSeconds(new Date(2014, 8 /* Sep */, 1, 11, 30, 15).getTime(), 45)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 30, 45))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1, 11, 30, 45))
})

@@ -24,5 +25,5 @@

setSeconds(date, 15)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1, 11, 30, 40))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1, 11, 30, 40))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var setYear = require('../set_year')
describe('setYear', function() {
it('set full year', function() {
it('set year', function() {
var result = setYear(new Date(2014, 8 /* Sep */, 1), 2013)
expect(result).to.be.eql(new Date(2013, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2013, 8 /* Sep */, 1))
})

@@ -11,3 +12,3 @@

var result = setYear(new Date(2014, 8 /* Sep */, 1).toISOString(), 2016)
expect(result).to.be.eql(new Date(2016, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2016, 8 /* Sep */, 1))
})

@@ -17,3 +18,3 @@

var result = setYear(new Date(2014, 8 /* Sep */, 1).getTime(), 2016)
expect(result).to.be.eql(new Date(2016, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2016, 8 /* Sep */, 1))
})

@@ -24,5 +25,5 @@

setYear(date, 2011)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var startOfDay = require('../start_of_day')

@@ -7,3 +8,3 @@

var result = startOfDay(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 2, 0, 0, 0, 0)

@@ -16,3 +17,3 @@ )

var result = startOfDay(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 2, 0, 0, 0, 0)

@@ -25,3 +26,3 @@ )

var result = startOfDay(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 8 /* Sep */, 2, 0, 0, 0, 0)

@@ -34,5 +35,5 @@ )

startOfDay(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})
})

@@ -0,8 +1,9 @@

var assert = require('power-assert')
var startOfHour = require('../start_of_hour')
describe('startOfHour', function() {
it('returns date with minutes setted to 00:00:00', function() {
it('returns date with first minute of hour', function() {
var date = new Date(2014, 8 /* Sep */, 2, 11, 55)
var result = startOfHour(date)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 2, 11))
})

@@ -13,3 +14,3 @@

startOfHour(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55))
})

@@ -20,3 +21,3 @@

var result = startOfHour(date)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 2, 11))
})

@@ -27,5 +28,5 @@

var result = startOfHour(date)
expect(result).to.be.eql(new Date(2014, 11, 1, 12, 0))
assert.deepEqual(result, new Date(2014, 11, 1, 12, 0))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var startOfISOYear = require('../start_of_iso_year')

@@ -6,3 +7,3 @@

var result = startOfISOYear(new Date(2009, 0 /* Jan */, 1, 16, 0))
expect(result).to.be.eql(new Date(2008, 11 /* Dec */, 29, 0, 0, 0, 0))
assert.deepEqual(result, new Date(2008, 11 /* Dec */, 29, 0, 0, 0, 0))
})

@@ -12,3 +13,3 @@

var result = startOfISOYear(new Date(2005, 0 /* Jan */, 1, 6, 0).toISOString())
expect(result).to.be.eql(new Date(2003, 11 /* Dec */, 29, 0, 0, 0, 0))
assert.deepEqual(result, new Date(2003, 11 /* Dec */, 29, 0, 0, 0, 0))
})

@@ -18,3 +19,3 @@

var result = startOfISOYear(new Date(2005, 0 /* Jan */, 1, 6, 0).getTime())
expect(result).to.be.eql(new Date(2003, 11 /* Dec */, 29, 0, 0, 0, 0))
assert.deepEqual(result, new Date(2003, 11 /* Dec */, 29, 0, 0, 0, 0))
})

@@ -25,5 +26,5 @@

startOfISOYear(date)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 2))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 2))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var startOfMinute = require('../start_of_minute')

@@ -7,13 +8,13 @@

var result = startOfMinute(date)
expect(result).to.be.eql(new Date(2014, 11, 1, 22, 15))
assert.deepEqual(result, new Date(2014, 11, 1, 22, 15))
})
it('supports string as a date', function() {
it('accepts string', function() {
var result = startOfMinute('2014-12-01T13:20:30.456Z')
expect(result).to.be.eql(new Date(Date.UTC(2014, 11, 1, 13, 20)))
assert.deepEqual(result, new Date(Date.UTC(2014, 11, 1, 13, 20)))
})
it('supports timestamp as a date', function() {
it('accepts timestamp', function() {
var result = startOfMinute(new Date(2014, 11, 1, 22, 15, 45, 400).getTime())
expect(result).to.be.eql(new Date(2014, 11, 1, 22, 15))
assert.deepEqual(result, new Date(2014, 11, 1, 22, 15))
})

@@ -24,5 +25,5 @@

startOfMinute(date)
expect(date).to.be.eql(new Date(2014, 11, 1, 22, 15, 45, 400))
assert.deepEqual(date, new Date(2014, 11, 1, 22, 15, 45, 400))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var startOfMonth = require('../start_of_month')

@@ -7,3 +8,3 @@

var result = startOfMonth(date)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1))
})

@@ -14,3 +15,3 @@

var result = startOfMonth(date)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1))
})

@@ -21,3 +22,3 @@

var result = startOfMonth(date)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1))
})

@@ -28,5 +29,5 @@

startOfMonth(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var startOfQuarter = require('../start_of_quarter')

@@ -7,3 +8,3 @@

var result = startOfQuarter(date)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 1))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 1))
})

@@ -14,3 +15,3 @@

var result = startOfQuarter(date)
expect(result).to.be.eql(new Date(2014, 0 /* Jan */, 1))
assert.deepEqual(result, new Date(2014, 0 /* Jan */, 1))
})

@@ -21,3 +22,3 @@

var result = startOfQuarter(date)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 1))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 1))
})

@@ -28,5 +29,5 @@

startOfQuarter(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})
})

@@ -0,1 +1,2 @@

var assert = require('power-assert')
var startOfSecond = require('../start_of_second')

@@ -7,13 +8,13 @@

var result = startOfSecond(date)
expect(result).to.be.eql(new Date(2014, 11, 1, 22, 15, 45))
assert.deepEqual(result, new Date(2014, 11, 1, 22, 15, 45))
})
it('supports string as a date', function() {
it('accepts string', function() {
var result = startOfSecond('2014-12-01T13:20:30.456Z')
expect(result).to.be.eql(new Date(Date.UTC(2014, 11, 1, 13, 20, 30)))
assert.deepEqual(result, new Date(Date.UTC(2014, 11, 1, 13, 20, 30)))
})
it('supports timestamp as a date', function() {
it('accepts timestamp', function() {
var result = startOfSecond(new Date(2014, 11, 1, 22, 15, 45, 400).getTime())
expect(result).to.be.eql(new Date(2014, 11, 1, 22, 15, 45))
assert.deepEqual(result, new Date(2014, 11, 1, 22, 15, 45))
})

@@ -24,5 +25,5 @@

startOfSecond(date)
expect(date).to.be.eql(new Date(2014, 11, 1, 22, 15, 45, 400))
assert.deepEqual(date, new Date(2014, 11, 1, 22, 15, 45, 400))
})
})

@@ -0,8 +1,9 @@

var assert = require('power-assert')
var startOfWeek = require('../start_of_week')
describe('startOfWeek', function() {
it('returns date with time setted to 00:00:00 and date setted to first day in month', function() {
it('returns date with time setted to 00:00:00 and date setted to first day of week', function() {
var date = new Date(2014, 8 /* Sep */, 2, 11, 55, 0)
var result = startOfWeek(date)
expect(result).to.be.eql(new Date(2014, 7 /* Aug */, 31))
assert.deepEqual(result, new Date(2014, 7 /* Aug */, 31))
})

@@ -13,3 +14,3 @@

var result = startOfWeek(date, 1)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1))
})

@@ -20,3 +21,3 @@

var result = startOfWeek(date)
expect(result).to.be.eql(new Date(2014, 7 /* Aug */, 31))
assert.deepEqual(result, new Date(2014, 7 /* Aug */, 31))
})

@@ -27,3 +28,3 @@

var result = startOfWeek(date)
expect(result).to.be.eql(new Date(2014, 7 /* Aug */, 31))
assert.deepEqual(result, new Date(2014, 7 /* Aug */, 31))
})

@@ -34,3 +35,3 @@

startOfWeek(date)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
})

@@ -43,3 +44,3 @@

var result = startOfWeek(date, 3)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 1))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 1))
})

@@ -52,3 +53,3 @@ })

var result = startOfWeek(date, 3)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 8))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 8))
})

@@ -61,3 +62,3 @@ })

var result = startOfWeek(date, 3)
expect(result).to.be.eql(new Date(2014, 9 /* Oct */, 8))
assert.deepEqual(result, new Date(2014, 9 /* Oct */, 8))
})

@@ -69,3 +70,3 @@ })

var result = startOfWeek(date)
expect(result).to.be.eql(new Date(2013, 11 /* Dec */, 29))
assert.deepEqual(result, new Date(2013, 11 /* Dec */, 29))
})

@@ -72,0 +73,0 @@ })

@@ -0,8 +1,9 @@

var assert = require('power-assert')
var startOfYear = require('../start_of_year')
describe('startOfYear', function() {
it('returns date with time setted to 00:00:00', function() {
it('returns date with time setted to 00:00:00 and date setted to first day of year', function() {
var date = new Date(2014, 8, 2, 11, 55, 00)
var result = startOfYear(date)
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 0, 1, 0, 0, 0, 0)

@@ -15,3 +16,3 @@ )

var result = startOfYear(date.toISOString())
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 0, 1, 0, 0, 0, 0)

@@ -24,3 +25,3 @@ )

var result = startOfYear(date.getTime())
expect(result).to.be.eql(
assert.deepEqual(result,
new Date(2014, 0, 1, 0, 0, 0, 0)

@@ -33,5 +34,5 @@ )

startOfYear(date)
expect(date).to.be.eql(new Date('2014-09-02T11:55:00'))
assert.deepEqual(date, new Date('2014-09-02T11:55:00'))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var subDays = require('../sub_days')
describe('subDays', function() {
it('subs number of passed days', function() {
it('subtracts given number of days', function() {
var result = subDays(new Date(2014, 8 /* Sep */, 1), 10)
expect(result).to.be.eql(new Date(2014, 7 /* Aug */, 22))
assert.deepEqual(result, new Date(2014, 7 /* Aug */, 22))
})

@@ -11,3 +12,3 @@

var result = subDays(new Date(2014, 8 /* Sep */, 1).toISOString(), 10)
expect(result).to.be.eql(new Date(2014, 7 /* Aug */, 22))
assert.deepEqual(result, new Date(2014, 7 /* Aug */, 22))
})

@@ -17,3 +18,3 @@

var result = subDays(new Date(2014, 8 /* Sep */, 1).getTime(), 10)
expect(result).to.be.eql(new Date(2014, 7 /* Aug */, 22))
assert.deepEqual(result, new Date(2014, 7 /* Aug */, 22))
})

@@ -24,5 +25,5 @@

subDays(date, 11)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var subHours = require('../sub_hours')
describe('subHours', function() {
it('subtracts numbers of passed hours', function() {
it('subtracts given numbers of hours', function() {
var result = subHours(new Date(2014, 6 /* Jul */, 11, 1, 0), 2)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 23, 0))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 23, 0))
})

@@ -13,3 +14,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 23, 0))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 23, 0))
})

@@ -21,3 +22,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 23, 0))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 23, 0))
})

@@ -28,5 +29,5 @@

subHours(date, 10)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 10, 23, 0))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 10, 23, 0))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var subMilliseconds = require('../sub_milliseconds')
describe('subMilliseconds', function() {
it('subtracts number of passed milliseconds', function() {
it('subtracts given number of milliseconds', function() {
var result = subMilliseconds(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0), 750)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 29, 250))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 45, 29, 250))
})

@@ -13,3 +14,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 29, 500))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 45, 29, 500))
})

@@ -21,3 +22,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 29, 500))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 45, 29, 500))
})

@@ -28,5 +29,5 @@

subMilliseconds(date, 250)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 10, 12, 45, 30, 0))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var subMinutes = require('../sub_minutes')
describe('subMinutes', function() {
it('subtracts number of passed minutes', function() {
it('subtracts given number of minutes', function() {
var result = subMinutes(new Date(2014, 6 /* Jul */, 10, 12, 0), 30)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 11, 30))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 11, 30))
})

@@ -13,3 +14,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 11, 40))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 11, 40))
})

@@ -21,3 +22,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 11, 40))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 11, 40))
})

@@ -28,5 +29,5 @@

subMinutes(date, 25)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 0))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 10, 12, 0))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var subMonths = require('../sub_months')
describe('subMonths', function() {
it('subtracts number of passed months', function() {
it('subtracts given number of months', function() {
var result = subMonths(new Date(2015, 1 /* Feb */, 1), 5)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1))
})

@@ -11,3 +12,3 @@

var result = subMonths(new Date(2015, 8 /* Sep */, 1).toISOString(), 12)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1))
})

@@ -17,3 +18,3 @@

var result = subMonths(new Date(2015, 8 /* Sep */, 1).getTime(), 12)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 1))
})

@@ -24,5 +25,5 @@

subMonths(date, 12)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var subQuarters = require('../sub_quarters')
describe('subQuarters', function() {
it('subtracts number of passed quarters', function() {
it('subtracts given number of quarters', function() {
var result = subQuarters(new Date(2014, 8 /* Sep */, 1), 3)
expect(result).to.be.eql(new Date(2013, 11 /* Dec */, 1))
assert.deepEqual(result, new Date(2013, 11 /* Dec */, 1))
})

@@ -11,3 +12,3 @@

var result = subQuarters(new Date(2014, 8 /* Sep */, 1).toISOString(), 4)
expect(result).to.be.eql(new Date(2013, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2013, 8 /* Sep */, 1))
})

@@ -17,3 +18,3 @@

var result = subQuarters(new Date(2014, 8 /* Sep */, 1).getTime(), 4)
expect(result).to.be.eql(new Date(2013, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2013, 8 /* Sep */, 1))
})

@@ -24,11 +25,11 @@

subQuarters(date, 3)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
it('works well when desired month have less days and provided date is on the last day of month', function() {
it('works well if desired month have less days and provided date is on the last day of month', function() {
var date = new Date(2014, 11 /* Dec */, 31)
var result = subQuarters(date, 1)
expect(result).to.be.eql(new Date(2014, 8 /* Sep */, 30))
assert.deepEqual(result, new Date(2014, 8 /* Sep */, 30))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var subSeconds = require('../sub_seconds')
describe('subSeconds', function() {
it('subtracts number of passed seconds', function() {
it('subtracts given number of seconds', function() {
var result = subSeconds(new Date(2014, 6 /* Jul */, 10, 12, 45, 0), 30)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 44, 30))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 44, 30))
})

@@ -13,3 +14,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 44, 40))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 44, 40))
})

@@ -21,3 +22,3 @@

)
expect(result).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 44, 40))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 44, 40))
})

@@ -28,5 +29,5 @@

subSeconds(date, 15)
expect(date).to.be.eql(new Date(2014, 6 /* Jul */, 10, 12, 45, 0))
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 10, 12, 45, 0))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var subWeeks = require('../sub_weeks')
describe('subWeeks', function() {
it('subtracts number of passed days', function() {
it('subtracts given number of weeks', function() {
var result = subWeeks(new Date(2014, 8 /* Sep */, 1), 4)
expect(result).to.be.eql(new Date(2014, 7 /* Aug */, 4))
assert.deepEqual(result, new Date(2014, 7 /* Aug */, 4))
})

@@ -11,3 +12,3 @@

var result = subWeeks(new Date(2014, 8 /* Sep */, 1).toISOString(), 2)
expect(result).to.be.eql(new Date(2014, 7 /* Aug */, 18))
assert.deepEqual(result, new Date(2014, 7 /* Aug */, 18))
})

@@ -17,3 +18,3 @@

var result = subWeeks(new Date(2014, 8 /* Sep */, 1).getTime(), 1)
expect(result).to.be.eql(new Date(2014, 7 /* Aug */, 25))
assert.deepEqual(result, new Date(2014, 7 /* Aug */, 25))
})

@@ -24,5 +25,5 @@

subWeeks(date, 2)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})

@@ -0,7 +1,8 @@

var assert = require('power-assert')
var subYears = require('../sub_years')
describe('subYears', function() {
it('subtracts number of passed years', function() {
it('subtracts given number of years', function() {
var result = subYears(new Date(2014, 8 /* Sep */, 1), 5)
expect(result).to.be.eql(new Date(2009, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2009, 8 /* Sep */, 1))
})

@@ -11,3 +12,3 @@

var result = subYears(new Date(2014, 8 /* Sep */, 1).toISOString(), 12)
expect(result).to.be.eql(new Date(2002, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2002, 8 /* Sep */, 1))
})

@@ -17,3 +18,3 @@

var result = subYears(new Date(2014, 8 /* Sep */, 1).getTime(), 12)
expect(result).to.be.eql(new Date(2002, 8 /* Sep */, 1))
assert.deepEqual(result, new Date(2002, 8 /* Sep */, 1))
})

@@ -24,5 +25,5 @@

subYears(date, 12)
expect(date).to.be.eql(new Date(2014, 8 /* Sep */, 1))
assert.deepEqual(date, new Date(2014, 8 /* Sep */, 1))
})
})
var parse = require('./parse')
var getTimeSinceMidnight = require('./get_time_since_midnight')
/**
* Adds specified number of days to passed date.
* @param {data|string} dirtyDate
* @param {number} amount
* @returns {date} new date
* @category Day Helpers
* @summary Get the day of the month.
*
* @description
* Add the specified number of days to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of days to be added
* @returns {Date} new date with the days added
*/
var addDays = function(dirtyDate, amount) {
var date = parse(dirtyDate)
var time = getTimeSinceMidnight(date)
date.setDate(date.getDate() + amount)
date.setHours(0, 0, 0, time)
return date

@@ -16,0 +18,0 @@ }

var parse = require('./parse')
/**
* Adds specified number of hours to passed date.
* @param {data|string} dirtyDate
* @param {number} amount of hours
* @returns {date} new date
* @category Hour Helpers
* @summary Add hours to the given date.
*
* @description
* Add the specified number of hours to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of hours to be added
* @returns {Date} new date with the hours added
*/

@@ -9,0 +14,0 @@ var addHours = function(dirtyDate, amount) {

var parse = require('./parse')
/**
* Adds specified number of milliseconds to passed date.
* @param {data|string} dirtyDate
* @param {number} amount of milliseconds
* @returns {date} new date
* @category Millisecond Helpers
* @summary Add the milliseconds to the given date.
*
* @description
* Add the specified number of milliseconds to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of milliseconds to be added
* @returns {Date} new date with the milliseconds added
*/

@@ -9,0 +14,0 @@ var addMilliseconds = function(dirtyDate, amount) {

var parse = require('./parse')
/**
* Adds specified number of minutes to passed date.
* @param {data|string} dirtyDate
* @param {number} amount of minutes
* @returns {date} new date
* @category Minute Helpers
* @summary Add the minutes to the given date.
*
* @description
* Add the specified number of minutes to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of minutes to be added
* @returns {Date} new date with the minutes added
*/

@@ -9,0 +14,0 @@ var addMinutes = function(dirtyDate, amount) {

var parse = require('./parse')
var getTimeSinceMidnight = require('./get_time_since_midnight')
var getDaysInMonth = require('./get_days_in_month')
/**
* Adds specified number of months to passed date.
* @param {data|string} dirtyDate
* @param {number} amount
* @returns {date} new date
* @category Month Helpers
* @summary Add the specified number of months to the given date.
*
* @description
* Add the specified number of months to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of months to be added
* @returns {Date} new date with the months added
*/
var addMonths = function(dirtyDate, amount) {
var date = parse(dirtyDate)
var time = getTimeSinceMidnight(date)
var desiredMonth = date.getMonth() + amount
var daysInMonth = getDaysInMonth(new Date(date.getFullYear(), desiredMonth, 1))
// Set the last day of the new month
// if the original date was the last day of the longer month
date.setMonth(desiredMonth, Math.min(daysInMonth, date.getDate()))
date.setHours(0, 0, 0, time)
return date

@@ -20,0 +23,0 @@ }

var addMonths = require('./add_months')
/**
* Adds specified number of quarters to passed date.
* @param {data|string} dirtyDate
* @param {number} amount
* @returns {date} new date
* @category Quarter Helpers
* @summary Add the specified number of year quarters to the given date.
*
* @description
* Add the specified number of quarters to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of quarters to be added
* @returns {Date} new date with the quarters added
*/

@@ -9,0 +14,0 @@ var addQuarters = function(dirtyDate, amount) {

var parse = require('./parse')
/**
* Adds specified number of seconds to passed date.
* @param {data|string} dirtyDate
* @param {number} amount of seconds
* @returns {date} new date
* @category Second Helpers
* @summary Add the seconds to the given date.
*
* @description
* Add the specified number of seconds to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of seconds to be added
* @returns {Date} new date with the seconds added
*/

@@ -9,0 +14,0 @@ var addSeconds = function(dirtyDate, amount) {

var addDays = require('./add_days')
/**
* Adds specified number of week to passed date.
* @param {data|string} dirtyDate
* @param {number} amount
* @returns {date} new date
* @category Week Helpers
* @summary Add specified number of weeks to the given date.
*
* @description
* Add the specified number of week to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of weeks to be added
* @returns {Date} new date with the weeks added
*/

@@ -9,0 +14,0 @@ var addWeeks = function(dirtyDate, amount) {

var parse = require('./parse')
var getTimeSinceMidnight = require('./get_time_since_midnight')
/**
* Adds specified number of years to passed date.
* @param {data|string} dirtyDate
* @param {number} amount
* @returns {date} new date
* @category Year Helpers
* @summary Add the specified number of years to the given date.
*
* @description
* Add the specified number of years to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of years to be added
* @returns {Date} new date with the years added
*/
var addYears = function(dirtyDate, amount) {
var date = parse(dirtyDate)
var time = getTimeSinceMidnight(date)
date.setFullYear(date.getFullYear() + amount)
date.setHours(0, 0, 0, time)
return date

@@ -16,0 +18,0 @@ }

var parse = require('./parse')
/**
* Compares the two dates and returns -1, 0 or 1.
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @returns {number}
* @category Common Helpers
* @summary Compare the two dates and return -1, 0 or 1.
*
* @description
* Compare the two dates and return -1, 0 or 1.
*
* @param {Date|String|Number} dateLeft - the first date to compare
* @param {Date|String|Number} dateRight - the second date to compare
* @returns {Number} result of the comparison
*/

@@ -9,0 +14,0 @@ var compareAsc = function(dirtyDateLeft, dirtyDateRight) {

var parse = require('./parse')
/**
* Compares the two dates reverse chronologicaly and returns -1, 0 or 1.
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @returns {number}
* @category Common Helpers
* @summary Compare the two dates reverse chronologically and return -1, 0 or 1.
*
* @description
* Compare the two dates reverse chronologically and return -1, 0 or 1.
*
* @param {Date|String|Number} dateLeft - the first date to compare
* @param {Date|String|Number} dateRight - the second date to compare
* @returns {Number} result of the comparison
*/

@@ -9,0 +14,0 @@ var compareDesc = function(dirtyDateLeft, dirtyDateRight) {

@@ -7,6 +7,11 @@ var startOfDay = require('./start_of_day')

/**
* Returns number of days between dates.
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @returns {number}
* @category Day Helpers
* @summary Get the number of full days between the given dates.
*
* @description
* Return the number of full days between the given dates.
*
* @param {Date|String|Number} dateLeft - the earlier date
* @param {Date|String|Number} dateRight - the later date
* @returns {Number} number of days
*/

@@ -22,2 +27,5 @@ var differenceInDays = function(dirtyDateLeft, dirtyDateRight) {

// Round the number of days to the nearest integer
// because the number of milliseconds in a day is not constant
// (e.g. it's different in the day of the daylight saving time clock shift)
return Math.round((timestampLeft - timestampRight) / MILLISECONDS_IN_DAY)

@@ -24,0 +32,0 @@ }

var parse = require('./parse')
/**
* Returns array of dates withtin specified range.
* @param {date|string} dirtyStart
* @param {date|string} dirtyEnd
* @returns {date[]}
* @category Day Helpers
* @summary Return the array of dates within the specified range.
*
* @description
* Return the array of dates within the specified range.
*
* @param {Date|String|Number} startDate - the start of range
* @param {Date|String|Number} endDate - the end of range
* @returns {Date[]} array of dates for every day of the range
* @throws End of range must have time value greater than time value of start of range
*/
var eachDay = function(dirtyStart, dirtyEnd) {
var endTime = parse(dirtyEnd).getTime()
var dates = []
var tmpDate
var eachDay = function(dirtyStartDate, dirtyEndDate) {
var startDate = parse(dirtyStartDate)
var endDate = parse(dirtyEndDate)
var curDate = parse(dirtyStart)
curDate.setHours(0, 0, 0, 0)
var endTime = endDate.getTime()
while (curDate.getTime() <= endTime) {
dates.push(new Date(curDate))
if (startDate.getTime() > endTime) {
throw new Error('End of range must have time value greater than time value of start of range')
}
curDate.setDate(curDate.getDate() + 1)
var dates = []
/**
* add additional 5 hours to get next day,
* because of possible troubles with daylight savings dates
*/
tmpDate = new Date(curDate.setTime(curDate.getTime() + 5 * 60 * 60 * 1000))
tmpDate = new Date(tmpDate.setHours(0, 0, 0, 0))
curDate = tmpDate
var currentDate = startDate
currentDate.setHours(0, 0, 0, 0)
while (currentDate.getTime() <= endTime) {
dates.push(new Date(currentDate))
currentDate.setDate(currentDate.getDate() + 1)
}

@@ -30,0 +34,0 @@

var parse = require('./parse')
/**
* Returns end of a day for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Day Helpers
* @summary Return the end of a day for the given date.
*
* @description
* Return the end of a day for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} end of a day
*/

@@ -8,0 +14,0 @@ var endOfDay = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns end of an hour for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Hour Helpers
* @summary Return the end of an hour for the given date.
*
* @description
* Return the end of an hour for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} end of an hour
*/

@@ -8,0 +14,0 @@ var endOfHour = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns end of a minute for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Minute Helpers
* @summary Return the end of a minute for the given date.
*
* @description
* Return the end of a minute for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} end of a minute
*/

@@ -8,0 +14,0 @@ var endOfMinute = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns end of a month for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Month Helpers
* @summary Return the end of a month for the given date.
*
* @description
* Return the end of a month for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} end of a month
*/

@@ -11,4 +17,4 @@ var endOfMonth = function(dirtyDate) {

var month = date.getMonth()
date.setFullYear(date.getFullYear(), month + 1, 0)
date.setHours(23, 59, 59, 999)
date.setFullYear(date.getFullYear(), month + 1, 0)
return date

@@ -15,0 +21,0 @@ }

var parse = require('./parse')
/**
* Returns end of a quarter for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Quarter Helpers
* @summary Return the end of a year quarter for the given date.
*
* @description
* Return the end of a quarter for the given date
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} end of a quarter
*/

@@ -12,4 +18,4 @@ var endOfQuarter = function(dirtyDate) {

var month = currentMonth - currentMonth % 3 + 3
date.setMonth(month, 0)
date.setHours(23, 59, 59, 999)
date.setMonth(month, 0)
return date

@@ -16,0 +22,0 @@ }

var parse = require('./parse')
/**
* Returns end of a second for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Second Helpers
* @summary Return the end of a second for the given date.
*
* @description
* Return the end of a second for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} end of a second
*/

@@ -8,0 +14,0 @@ var endOfSecond = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns end of a week for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @param {number} [weekStartsAt=0] first day of week (0 - sunday)
* @returns {date}
* @category Week Helpers
* @summary Return the end of a week for the given date.
*
* @description
* Return the end of a week for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @param {Number} [weekStartsAt=0] the index of the first day of a week (0 - sunday)
* @returns {Date} end of a week
*/

@@ -16,4 +22,4 @@ var endOfWeek = function(dirtyDate, weekStartsAt) {

date.setDate(date.getDate() + diff)
date.setHours(23, 59, 59, 999)
date.setDate(date.getDate() + diff)
return date

@@ -20,0 +26,0 @@ }

var parse = require('./parse')
/**
* Returns end of a year for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Year Helpers
* @summary Return the end of a year for the given date.
*
* @description
* Return the end of a year for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} end of a year
*/

@@ -11,4 +17,4 @@ var endOfYear = function(dirtyDate) {

var year = date.getFullYear()
date.setFullYear(year + 1, 0, 0)
date.setHours(23, 59, 59, 999)
date.setFullYear(year + 1, 0, 0)
return date

@@ -15,0 +21,0 @@ }

var getDayOfYear = require('./get_day_of_year')
var getISOWeek = require('./get_iso_week')
var getISOYear = require('./get_iso_year')
var parse = require('./parse')
var NUMBER_OF_MS_IN_DAY = 864e5
/**
* Returns formatted date string in a given format
* @param {date|string} date
* @param {string} format
* @returns {string}
* @category Common Helpers
* @summary Format the date.
*
* @description
* Return the formatted date string in the given format.
*
* Accepted tokens:
* | Unit | Token | Result examples |
* |-------------------------|-------|----------------------------------|
* | Month | M | 1, 2, ..., 12 |
* | | Mo | 1st, 2nd, ..., 12th |
* | | MM | 01, 02, ..., 12 |
* | | MMM | Jan, Feb, ..., Dec |
* | | MMMM | January, February, ..., December |
* | Quarter | Q | 1, 2, 3, 4 |
* | | Qo | 1st, 2nd, 3rd, 4th |
* | Day of month | D | 1, 2, ..., 31 |
* | | Do | 1st, 2nd, ..., 31st |
* | | DD | 01, 02, ..., 31 |
* | Day of year | DDD | 1, 2, ..., 366 |
* | | DDDo | 1st, 2nd, ..., 366th |
* | | DDDD | 001, 002, ..., 366 |
* | Day of week | d | 0, 1, ..., 6 |
* | | do | 0th, 1st, ..., 6th |
* | | dd | Su, Mo, ..., Sa |
* | | ddd | Sun, Mon, ..., Sat |
* | | dddd | Sunday, Monday, ..., Saturday |
* | Day of ISO week | E | 1, 2, ..., 7 |
* | ISO week | W | 1, 2, ..., 53 |
* | | Wo | 1st, 2nd, ..., 53rd |
* | | WW | 01, 02, ..., 53 |
* | Year | YY | 00, 01, ..., 99 |
* | | YYYY | 1900, 1901, ..., 2099 |
* | ISO week-numbering year | GG | 00, 01, ..., 99 |
* | | GGGG | 1900, 1901, ..., 2099 |
* | AM/PM | A | AM, PM |
* | | a | am, pm |
* | | aa | a.m., p.m. |
* | Hour | H | 0, 1, ... 23 |
* | | HH | 00, 01, ... 23 |
* | | h | 1, 2, ..., 12 |
* | | hh | 01, 02, ..., 12 |
* | Minute | m | 0, 1, ..., 59 |
* | | mm | 00, 01, ..., 59 |
* | Second | s | 0, 1, ..., 59 |
* | | ss | 00, 01, ..., 59 |
* | 1/10 of second | S | 0, 1, ..., 9 |
* | 1/100 of second | SS | 00, 01, ..., 99 |
* | Millisecond | SSS | 000, 001, ..., 999 |
* | Timezone | Z | -01:00, +00:00, ... +12:00 |
* | | ZZ | -0100, +0000, ..., +1200 |
* | Seconds timestamp | X | 512969520 |
* | Milliseconds timestamp | x | 512969520900 |
*
* @param {Date|String|Number} date - the original date
* @param {String} format - the string of tokens
* @returns {String} formatted date string
*/

@@ -24,65 +77,128 @@ var format = function(dirtyDate, format) {

var formats = {
// Month: 1, 2, ..., 12
'M': function() {
return this.getMonth() + 1
},
// Month: 01, 02, ..., 12
'MM': function() {
return leftZeroFill(this.getMonth() + 1, 2)
return addLeadingZeros(this.getMonth() + 1, 2)
},
// Month: Jan, Feb, ..., Dec
'MMM': function() {
return locale.monthsShort[this.getMonth()]
},
// Month: January, February, ..., December
'MMMM': function() {
return locale.months[this.getMonth()]
},
// Quarter: 1, 2, 3, 4
'Q': function() {
return Math.ceil((this.getMonth() + 1) / 3)
},
// Day of month: 1, 2, ..., 31
'D': function() {
return this.getDate()
},
// Day of month: 01, 02, ..., 31
'DD': function() {
return leftZeroFill(this.getDate(), 2)
return addLeadingZeros(this.getDate(), 2)
},
// Day of year: 1, 2, ..., 366
'DDD': function() {
return getDayOfYear(this)
},
// Day of year: 001, 002, ..., 366
'DDDD': function() {
return leftZeroFill(formats['DDD'].apply(this), 3)
return addLeadingZeros(getDayOfYear(this), 3)
},
// Day of week: 0, 1, ..., 6
'd': function() {
return this.getDay()
},
// Day of week: Su, Mo, ..., Sa
'dd': function() {
return locale.dayNamesMin[this.getDay()]
},
// Day of week: Sun, Mon, ..., Sat
'ddd': function() {
return locale.dayNamesShort[this.getDay()]
},
// Day of week: Sunday, Monday, ..., Saturday
'dddd': function() {
return locale.dayNames[this.getDay()]
},
// Day of ISO week: 1, 2, ..., 7
'E': function() {
return this.getDay() + 1
return this.getDay() || 7
},
// ISO week: 1, 2, ..., 53
'W': function() {
return getISOWeek(this)
},
// ISO week: 01, 02, ..., 53
'WW': function() {
return addLeadingZeros(getISOWeek(this), 2)
},
// Year: 00, 01, ..., 99
'YY': function() {
return String(this.getFullYear()).substr(2)
},
// Year: 1900, 1901, ..., 2099
'YYYY': function() {
return this.getFullYear()
},
// ISO week-numbering year: 00, 01, ..., 99
'GG': function() {
return String(getISOYear(this)).substr(2)
},
// ISO week-numbering year: 1900, 1901, ..., 2099
'GGGG': function() {
return getISOYear(this)
},
// AM, PM
'A': function() {
return (this.getHours() / 12) >= 1 ? 'PM' : 'AM'
},
// am, pm
'a': function() {
return (this.getHours() / 12) >= 1 ? 'pm' : 'am'
},
// a.m., p.m.
'aa': function() {
return (this.getHours() / 12) >= 1 ? 'p.m.' : 'a.m.'
},
// Hour: 0, 1, ... 23
'H': function() {
return this.getHours()
},
// Hour: 00, 01, ..., 23
'HH': function() {
return leftZeroFill(this.getHours(), 2)
return addLeadingZeros(this.getHours(), 2)
},
// Hour: 1, 2, ..., 12
'h': function() {

@@ -98,29 +214,65 @@ var hours = this.getHours()

},
// Hour: 01, 02, ..., 12
'hh': function() {
return leftZeroFill(formats['h'].apply(this), 2)
return addLeadingZeros(formats['h'].apply(this), 2)
},
// Minute: 0, 1, ..., 59
'm': function() {
return this.getMinutes()
},
// Minute: 00, 01, ..., 59
'mm': function() {
return leftZeroFill(this.getMinutes(), 2)
return addLeadingZeros(this.getMinutes(), 2)
},
// Second: 0, 1, ..., 59
's': function() {
return this.getSeconds()
},
// Second: 00, 01, ..., 59
'ss': function() {
return leftZeroFill(this.getSeconds(), 2)
return addLeadingZeros(this.getSeconds(), 2)
},
// 1/10 of second: 0, 1, ..., 9
'S': function() {
return this.getMilliseconds()
return Math.floor(this.getMilliseconds() / 100)
},
// 1/100 of second: 00, 01, ..., 99
'SS': function() {
return leftZeroFill(this.getMilliseconds(), 2)
return Math.floor(this.getMilliseconds() / 10)
},
// Millisecond: 000, 001, ..., 999
'SSS': function() {
return leftZeroFill(this.getMilliseconds(), 3)
return this.getMilliseconds()
},
// Timezone: -01:00, +00:00, ... +12:00
'Z': function() {
return formatTimezone(this.getTimezoneOffset(), ':')
},
// Timezone: -0100, +0000, ... +1200
'ZZ': function() {
return formatTimezone(this.getTimezoneOffset())
},
// Seconds timestamp: 512969520
'X': function() {
return Math.floor(this.getTime() / 1000)
},
// Milliseconds timestamp: 512969520900
'x': function() {
return this.getTime()
}
}
var ordinalFunctions = ['M', 'D', 'DDD', 'd']
var ordinalFunctions = ['M', 'D', 'DDD', 'd', 'Q', 'W']
ordinalFunctions.forEach(function(functionName) {

@@ -168,3 +320,3 @@ formats[functionName + 'o'] = function() {

var leftZeroFill = function(number, targetLength) {
var addLeadingZeros = function(number, targetLength) {
var output = String(Math.abs(number))

@@ -178,2 +330,11 @@

var formatTimezone = function(offset, delimeter) {
delimeter = delimeter || ''
var sign = offset > 0 ? '-' : '+'
var absOffset = Math.abs(offset)
var hours = Math.floor(absOffset / 60)
var minutes = absOffset % 60
return sign + addLeadingZeros(hours, 2) + delimeter + addLeadingZeros(minutes, 2)
}
var locale = {

@@ -180,0 +341,0 @@ ordinal: function(number) {

var parse = require('./parse')
/**
* Returns day of month of passed date.
* @param {date|string} dirtyDate
* @returns {number} (day of month)
* @category Day Helpers
* @summary Get the day of the month.
*
* @description
* Get the day of the month of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} day of month
*/

@@ -8,0 +13,0 @@ var getDate = function(dirtyDate) {

@@ -6,5 +6,10 @@ var parse = require('./parse')

/**
* Returns day of year of passed date.
* @param {date|string} dirtyDate
* @returns {number} (day of year)
* @category Day Helpers
* @summary Get the day of the year.
*
* @description
* Get the day of the year of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} day of year
*/

@@ -11,0 +16,0 @@ var getDayOfYear = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns day of week of passed date.
* @param {date|string} dirtyDate
* @returns {number} (day)
* @category Weekday Helpers
* @summary Get the day of the week.
*
* @description
* Get the day of the week of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} day of week
*/

@@ -8,0 +13,0 @@ var getDay = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns number of days of month of passed date.
* @param {date|string} dirtyDate
* @returns {number} (days)
* @category Month Helpers
* @summary Get the number of days in a month of the given date.
*
* @description
* Get the number of days in a month of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} number of days in a month
*/

@@ -8,0 +13,0 @@ var getDaysInMonth = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns amount of hours of passed date.
* @param {date|string} dirtyDate
* @returns {number} (hours)
* @category Hour Helpers
* @summary Get the hours.
*
* @description
* Get the hours of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} hours
*/

@@ -8,0 +13,0 @@ var getHours = function(dirtyDate) {

@@ -8,8 +8,12 @@ var parse = require('./parse')

/**
* Returns ISO week of given date.
* @category ISO Week Helpers
* @summary Get the ISO week.
*
* @description
* Get the ISO week of the given date.
*
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
*
* @param {date|string} dirtyDate
* @returns {number} (ISO week)
* @param {Date|String|Number} date - the given date
* @returns {Number} ISO week
*

@@ -16,0 +20,0 @@ * @example which week of ISO-week numbering year is 2 January 2005

@@ -7,5 +7,12 @@ var startOfISOYear = require('./start_of_iso_year')

/**
* Returns number of ISO weeks of ISO week-numbering year of passed date.
* @param {date|string} dirtyDate
* @returns {number} (days)
* @category ISO Week-Numbering Year Helpers
* @summary Get the number of weeks in the ISO week-numbering year.
*
* @description
* Get the number of ISO weeks in an ISO week-numbering year of the given date.
*
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
*
* @param {Date|String|Number} date - the given date
* @returns {Number} number of ISO weeks in a year
*/

@@ -16,2 +23,5 @@ var getISOWeeksInYear = function(dirtyDate) {

var diff = nextYear.valueOf() - thisYear.valueOf()
// Round the number of weeks to the nearest integer
// because the number of milliseconds in a week is not constant
// (e.g. it's different in the week of the daylight saving time clock shift)
return Math.round(diff / MILLISECONDS_IN_WEEK)

@@ -18,0 +28,0 @@ }

var parse = require('./parse')
var startOfWeek = require('./start_of_week')
var startOfISOWeek = require('./start_of_iso_week')
/**
* Returns ISO week-numbering year of given date,
* which always starts 3 days before year's first Thursday.
* @category ISO Week-Numbering Year Helpers
* @summary Get the ISO week-numbering year.
*
* @description
* Get the ISO week-numbering year of the given date,
* which always starts 3 days before the year's first Thursday.
*
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
*
* @param {date|string} dirtyDate
* @returns {number} (ISO year)
* @param {Date|String|Number} date - the given date
* @returns {Number} ISO year
*

@@ -20,4 +24,4 @@ * @example which ISO-week numbering year is 2 January 2005

var year = date.getFullYear()
var startOfNextYear = startOfWeek(new Date(year + 1, 0, 4), 1)
var startOfThisYear = startOfWeek(new Date(year, 0, 4), 1)
var startOfNextYear = startOfISOWeek(new Date(year + 1, 0, 4))
var startOfThisYear = startOfISOWeek(new Date(year, 0, 4))

@@ -24,0 +28,0 @@ if (date.getTime() >= startOfNextYear.getTime()) {

var parse = require('./parse')
/**
* Returns amount of milliseconds of passed date.
* @param {date|string} dirtyDate
* @returns {number} (milliseconds)
* @category Millisecond Helpers
* @summary Get the milliseconds.
*
* @description
* Get the milliseconds of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} milliseconds
*/

@@ -8,0 +13,0 @@ var getMilliseconds = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns amount of minutes of passed date.
* @param {date|string} dirtyDate
* @returns {number} (minutes)
* @category Minute Helpers
* @summary Get the minutes.
*
* @description
* Get the minutes of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} minutes
*/

@@ -8,0 +13,0 @@ var getMinutes = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns month of passed date.
* @param {date|string} dirtyDate
* @returns {number} (month)
* @category Month Helpers
* @summary Get the month.
*
* @description
* Get the month of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} month
*/

@@ -8,0 +13,0 @@ var getMonth = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns quarter of year of passed date.
* @param {date|string} dirtyDate
* @returns {number} (quarter)
* @category Quarter Helpers
* @summary Get the year quarter.
*
* @description
* Get the year quarter of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} quarter
*
* @example which quarter is 2 July 2014

@@ -9,0 +14,0 @@ * var result = getQuarter(new Date(2014, 6, 2))

var parse = require('./parse')
/**
* Returns amount of seconds of passed date.
* @param {date|string} dirtyDate
* @returns {number} (seconds)
* @category Second Helpers
* @summary Get the seconds.
*
* @description
* Get the seconds of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} seconds
*/

@@ -8,0 +13,0 @@ var getSeconds = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns year of passed date.
* @param {date|string} dirtyDate
* @returns {number} (year)
* @category Year Helpers
* @summary Get the year.
*
* @description
* Get the year of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} year
*/

@@ -8,0 +13,0 @@ var getYear = function(dirtyDate) {

var parse = require('./parse')
/**
* Is first date after second one?
* @param {date|string} dirtyDateToCompare
* @param {date|string} dirtyDate
* @returns {boolean}
* @category Common Helpers
* @summary Is the first date after the second one?
*
* @description
* Is the first date after the second one?
*
* @param {Date|String|Number} dateToCompare - the date to compare with
* @param {Date|String|Number} date that should be after the first one to return true
* @returns {Boolean} the first date is after the second date
*
* @example is 10 July 1989 after 11 February 1987

@@ -10,0 +15,0 @@ * var result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))

var parse = require('./parse')
/**
* Is first date is before second one?
* @param {date|string} dirtyDateToCompare
* @param {date|string} dirtyDate
* @returns {boolean}
* @category Common Helpers
* @summary Is the first date before the second one?
*
* @description
* Is the first date before the second one?
*
* @param {Date|String|Number} dateToCompare - the date to compare with
* @param {Date|String|Number} date that should be before the first one to return true
* @returns {Boolean} the first date is before the second date
*
* @example is 10 July 1989 before 11 February 1987

@@ -10,0 +15,0 @@ * var result = isBefore(new Date(1989, 6, 10), new Date(1987, 1, 11))

var parse = require('./parse')
/**
* Are passed dates equal?
* @param {date|string} dirtyLeftDate
* @param {date|string} dirtyRightDate
* @returns {boolean}
* @category Common Helpers
* @summary Are the given dates equal?
*
* @description
* Are the given dates equal?
*
* @param {Date|String|Number} dateLeft - the first date to compare
* @param {Date|String|Number} dateRight - the second date to compare
* @returns {Boolean} the dates are equal
*/

@@ -9,0 +14,0 @@ var isEqual = function(dirtyLeftDate, dirtyRightDate) {

var parse = require('./parse')
var startOfDay = require('./start_of_day')
var startOfMonth = require('./end_of_month')
/**
* Is passed date first day of month?
* @param {date|string} dirtyDate
* @returns {boolean}
* @category Month Helpers
* @summary Is the given date the first day of a month?
*
* @description
* Is the given date the first day of a month?
*
* @param {Date|String|Number} date to check
* @returns {Boolean} the date is the first day of a month
*/

@@ -10,0 +13,0 @@ var isFirstDayOfMonth = function(dirtyDate) {

var parse = require('./parse')
/**
* Is passed date future?
* @param {date|string} dirtyDate
* @returns {boolean}
* @category Common Helpers
* @summary Is the given date in the future?
*
* @description
* Is the given date in the future?
*
* @param {Date|String|Number} date to check
* @returns {Boolean} the date is in the future
*/

@@ -8,0 +13,0 @@ var isFuture = function(dirtyDate) {

@@ -6,5 +6,10 @@ var parse = require('./parse')

/**
* Is passed date last day of month?
* @param {date|string} dirtyDate
* @returns {boolean}
* @category Month Helpers
* @summary Is the given date the last day of a month?
*
* @description
* Is the given date the last day of a month?
*
* @param {Date|String|Number} date to check
* @returns {Boolean} the date is the last day of a month
*/

@@ -11,0 +16,0 @@ var isLastDayOfMonth = function(dirtyDate) {

var parse = require('./parse')
/**
* Is date in the leap year?
* @param {date|string} dirtyDate
* @returns {boolean}
* @category Year Helpers
* @summary Is the given date in the leap year?
*
* @description
* Is the given date in the leap year?
*
* @param {Date|String|Number} date to check
* @returns {Boolean} the date is in the leap year
*/

@@ -11,3 +16,3 @@ var isLeapYear = function(dirtyDate) {

var year = date.getFullYear()
return new Date(year, 1, 29).getMonth() == 1
return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0
}

@@ -14,0 +19,0 @@

var parse = require('./parse')
/**
* Is passed date past?
* @param {date|string} dirtyDate
* @returns {boolean}
* @category Common Helpers
* @summary Is the given date in the past?
*
* @description
* Is the given date in the past?
*
* @param {Date|String|Number} date to check
* @returns {Boolean} the date is in the past
*/

@@ -8,0 +13,0 @@ var isPast = function(dirtyDate) {

var startOfDay = require('./start_of_day')
/**
* Are passed dates has the same day?
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @returns {boolean}
* @category Day Helpers
* @summary Are the given dates in the same day?
*
* @description
* Are the given dates in the same day?
*
* @param {Date|String|Number} dateLeft - the first date to check
* @param {Date|String|Number} dateRight - the second date to check
* @returns {Boolean} the dates are in the same day
*/

@@ -9,0 +14,0 @@ var isSameDay = function(dirtyDateLeft, dirtyDateRight) {

var startOfHour = require('./start_of_hour')
/**
* Are passed dates belongs to the same hour?
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @returns {boolean}
* @category Hour Helpers
* @summary Are the given dates in the same hour?
*
* @description
* Are the given dates in the same hour?
*
* @param {Date|String|Number} dateLeft - the first date to check
* @param {Date|String|Number} dateRight - the second date to check
* @returns {Boolean} the dates are in the same hour
*/

@@ -9,0 +14,0 @@ var isSameHour = function(dirtyDateLeft, dirtyDateRight) {

var startOfMinute = require('./start_of_minute')
/**
* Are passed dates belongs to the same minute?
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @returns {boolean}
* @category Minute Helpers
* @summary Are the given dates in the same minute?
*
* @description
* Are the given dates in the same minute?
*
* @param {Date|String|Number} dateLeft - the first date to check
* @param {Date|String|Number} dateRight - the second date to check
* @returns {Boolean} the dates are in the same minute
*/

@@ -9,0 +14,0 @@ var isSameMinute = function(dirtyDateLeft, dirtyDateRight) {

var parse = require('./parse')
/**
* Are passed dates has the same month (and year)?
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @returns {boolean}
* @category Month Helpers
* @summary Are the given dates in the same month?
*
* @description
* Are the given dates in the same month?
*
* @param {Date|String|Number} dateLeft - the first date to check
* @param {Date|String|Number} dateRight - the second date to check
* @returns {Boolean} the dates are in the same month
*/

@@ -9,0 +14,0 @@ var isSameMonth = function(dirtyDateLeft, dirtyDateRight) {

var startOfQuarter = require('./start_of_quarter')
/**
* Are passed dates belongs to the same quarter?
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @returns {boolean}
* @category Quarter Helpers
* @summary Are the given dates in the same year quarter?
*
* @description
* Are the given dates in the same year quarter?
*
* @param {Date|String|Number} dateLeft - the first date to check
* @param {Date|String|Number} dateRight - the second date to check
* @returns {Boolean} the dates are in the same quarter
*/

@@ -9,0 +14,0 @@ var isSameQuarter = function(dirtyDateLeft, dirtyDateRight) {

var startOfSecond = require('./start_of_second')
/**
* Are passed dates belongs to the same second?
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @returns {boolean}
* @category Second Helpers
* @summary Are the given dates in the same second?
*
* @description
* Are the given dates in the same second?
*
* @param {Date|String|Number} dateLeft - the first date to check
* @param {Date|String|Number} dateRight - the second date to check
* @returns {Boolean} the dates are in the same second
*/

@@ -9,0 +14,0 @@ var isSameSecond = function(dirtyDateLeft, dirtyDateRight) {

var startOfWeek = require('./start_of_week')
/**
* Are passed dates belongs to the same week?
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @param {number} [weekStartsAt=0] first day of week (0 - sunday)
* @returns {boolean}
* @category Week Helpers
* @summary Are the given dates in the same week?
*
* @description
* Are the given dates in the same week?
*
* @param {Date|String|Number} dateLeft - the first date to check
* @param {Date|String|Number} dateRight - the second date to check
* @param {Number} [weekStartsAt=0] first day of week (0 - sunday)
* @returns {Boolean} the dates are in the same week
*/

@@ -10,0 +15,0 @@ var isSameWeek = function(dirtyDateLeft, dirtyDateRight, weekStartsAt) {

var parse = require('./parse')
/**
* Are passed dates has the same year?
* @param {date|string} dirtyDateLeft
* @param {date|string} dirtyDateRight
* @returns {boolean}
* @category Year Helpers
* @summary Are the given dates in the same year?
*
* @description
* Are the given dates in the same year?
*
* @param {Date|String|Number} dateLeft - the first date to check
* @param {Date|String|Number} dateRight - the second date to check
* @returns {Boolean} the dates are in the same year
*/

@@ -9,0 +14,0 @@ var isSameYear = function(dirtyDateLeft, dirtyDateRight) {

var startOfDay = require('./start_of_day')
/**
* Is passed date today?
* @param {date|string} dirtyDate
* @returns {boolean}
* @category Day Helpers
* @summary Is the given date today?
*
* @description
* Is the given date today?
*
* @param {Date|String|Number} date to check
* @returns {Boolean} the date is today
*/

@@ -8,0 +13,0 @@ var isToday = function(dirtyDate) {

var parse = require('./parse')
/**
* Is passed date weekend?
* @param {date|string} dirtyDate
* @returns {boolean}
* @category Weekday Helpers
* @summary Is the given date in a weekend?
*
* @description
* Is the given date in a weekend?
*
* @param {Date|String|Number} date to check
* @returns {Boolean} the date is in the weekend
*/

@@ -8,0 +13,0 @@ var isWeekend = function(dirtyDate) {

var parse = require('./parse')
/**
* Is passed date within given range?
* @param {date|string} dirtyDate
* @param {date|string} dirtyStartDate
* @param {date|string} dirtyEndDate
* @returns {boolean}
* @category Range Helpers
* @summary Is the given date within the range?
*
* @description
* Is the given date within the range?
*
* @param {Date|String|Number} date to check
* @param {Date|String|Number} startDate - the start of range
* @param {Date|String|Number} endDate - the end of range
* @returns {Boolean} the date is within the range
* @throws End of range must have time value greater than time value of start of range
*
* @example for date within the range

@@ -23,8 +29,11 @@ * isWithinRange(

var isWithinRange = function(dirtyDate, dirtyStartDate, dirtyEndDate) {
var date = parse(dirtyDate)
var time = date.getTime()
return(
time >= parse(dirtyStartDate).getTime()
&& time <= parse(dirtyEndDate).getTime()
)
var time = parse(dirtyDate).getTime()
var startTime = parse(dirtyStartDate).getTime()
var endTime = parse(dirtyEndDate).getTime()
if (startTime > endTime) {
throw new Error('End of range must have time value greater than time value of start of range')
}
return time >= startTime && time <= endTime
}

@@ -31,0 +40,0 @@

var parse = require('./parse')
/**
* Returns last day of a month for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Month Helpers
* @summary Return the last day of a month for the given date.
*
* @description
* Return the last day of a month for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} last day of a month
*/

@@ -11,4 +17,4 @@ var lastDayOfMonth = function(dirtyDate) {

var month = date.getMonth()
date.setFullYear(date.getFullYear(), month + 1, 0)
date.setHours(0, 0, 0, 0)
date.setFullYear(date.getFullYear(), month + 1, 0)
return date

@@ -15,0 +21,0 @@ }

var parse = require('./parse')
/**
* Returns last day of a quarter for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Quarter Helpers
* @summary Return the last day of a year quarter for the given date.
*
* @description
* Return the last day of a quarter for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} last day of a quarter
*/

@@ -12,4 +18,4 @@ var lastDayOfQuarter = function(dirtyDate) {

var month = currentMonth - currentMonth % 3 + 3
date.setMonth(month, 0)
date.setHours(0, 0, 0, 0)
date.setMonth(month, 0)
return date

@@ -16,0 +22,0 @@ }

var parse = require('./parse')
/**
* Returns last day of a week for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @param {number} [weekStartsAt=0] first day of week (0 - sunday)
* @returns {date}
* @category Week Helpers
* @summary Return the last day of a week for the given date.
*
* @description
* Return the last day of a week for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @param {Number} [weekStartsAt=0] the index of the first day of a week (0 - sunday)
* @returns {Date} last day of a week
*/

@@ -9,0 +15,0 @@ var lastDayOfWeek = function(dirtyDate, weekStartsAt) {

var parse = require('./parse')
/**
* Returns last day of a year for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Year Helpers
* @summary Return the last day of a year for the given date.
*
* @description
* Return the last day of a year for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} last day of a year
*/

@@ -11,4 +17,4 @@ var lastDayOfYear = function(dirtyDate) {

var year = date.getFullYear()
date.setFullYear(year + 1, 0, 0)
date.setHours(0, 0, 0, 0)
date.setFullYear(year + 1, 0, 0)
return date

@@ -15,0 +21,0 @@ }

var parse = require('./parse')
/**
* Returns latest of the dates.
* @param {...date|string} dates
* @returns {date}
* @category Common Helpers
* @summary Return the latest of the given dates.
*
* @description
* Return the latest of the given dates.
*
* @param {...Date|String|Number} list of dates
* @returns {Date} latest of the dates
*/

@@ -8,0 +13,0 @@ var max = function() {

var parse = require('./parse')
/**
* Returns earliest of the dates.
* @param {...date|string} dates
* @returns {date}
* @category Common Helpers
* @summary Return the earliest of the given dates.
*
* @description
* Return the earliest of the given dates.
*
* @param {...Date|String|Number} list of dates
* @returns {Date} earliest of the dates
*/

@@ -8,0 +13,0 @@ var min = function() {

@@ -27,17 +27,21 @@ var MILLISECONDS_IN_HOUR = 3600000

/**
* Parses date string representation. It accepts ISO 8601 format as well as
* partial implementation.
* @category Common Helpers
* @summary Parse the ISO-8601-formatted date.
*
* @description
* Parse the date string representation.
* It accepts the ISO 8601 format as well as a partial implementation.
*
* ISO 8601: http://en.wikipedia.org/wiki/ISO_8601
*
* @param {string} dateStr
* @return {date} parsed date in local time zone.
* @param {String} dateStr - the ISO 8601 formatted string to parse
* @returns {Date} parsed date in the local time zone.
*/
var parse = function(dateStr) {
if (dateStr instanceof Date) {
// Prevent dates to lose milliseconds when passed to new Date() in IE10
// Prevent the date to lose the milliseconds when passed to new Date() in IE10
return new Date(dateStr.getTime())
} else if (typeof dateStr !== 'string') {
return new Date(dateStr)
}
}

@@ -44,0 +48,0 @@ var dateStrings = splitDateString(dateStr)

var parse = require('./parse')
var getTimeSinceMidnight = require('./get_time_since_midnight')
/**
* Sets day of month to passed date.
* @param {date|string} dirtyDate
* @param {number} dayOfMonth
* @returns {date} (new date)
* @category Day Helpers
* @summary Set the day of the month.
*
* @description
* Set the day of the month to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} dayOfMonth of the new date
* @returns {Date} new date with the day of the month setted
*/
var setDate = function(dirtyDate, dayOfMonth) {
var date = parse(dirtyDate)
var time = getTimeSinceMidnight(date)
date.setDate(dayOfMonth)
date.setHours(0, 0, 0, time)
return date

@@ -16,0 +18,0 @@ }

var parse = require('./parse')
var getTimeSinceMidnight = require('./get_time_since_midnight')
/**
* Sets day of year to passed date.
* @param {date|string} dirtyDate
* @param {number} dayOfYear
* @returns {date} (new date)
* @category Day Helpers
* @summary Set the day of the year.
*
* @description
* Set the day of the year to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} dayOfYear of the new date
* @returns {Date} new date with the day of the year setted
*/
var setDayOfYear = function(dirtyDate, dayOfYear) {
var date = parse(dirtyDate)
var time = getTimeSinceMidnight(date)
date.setMonth(0)
date.setDate(dayOfYear)
date.setHours(0, 0, 0, time)
return date

@@ -17,0 +19,0 @@ }

@@ -5,9 +5,15 @@ var parse = require('./parse')

/**
* Sets day of week to passed date.
* @param {date|string} dirtyDate
* @param {number} day
* @param {number} weekStartsAt
* @returns {date} (new date)
* @category Weekday Helpers
* @summary Set the day of the week.
*
* @description
* Set the day of the week to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} day of the new date
* @param {Number} [weekStartsAt=0] the index of the first day of a week (0 - sunday)
* @returns {Date} new date with the day of the week setted
*/
var setDay = function(dirtyDate, day, weekStartsAt) {
weekStartsAt = weekStartsAt || 0
var date = parse(dirtyDate)

@@ -14,0 +20,0 @@ var currentDay = date.getDay()

var parse = require('./parse')
/**
* Sets amount of hours to passed date.
* @param {date|string} dirtyDate
* @param {number} hours
* @returns {date} (new date)
* @category Hour Helpers
* @summary Set the hours.
*
* @description
* Set the hours to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} hours of the new date
* @returns {Date} new date with the hours setted
*/

@@ -9,0 +14,0 @@ var setHours = function(dirtyDate, hours) {

var parse = require('./parse')
var getISOWeek = require('./get_iso_week')
var getTimeSinceMidnight = require('./get_time_since_midnight')
/**
* Sets ISO week to given date, saving weekday number.
* @category ISO Week Helpers
* @summary Set the ISO week.
*
* @description
* Set the ISO week to the given date, saving the weekday number.
*
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
*
* @param {date|string} dirtyDate
* @param {number} isoWeek
* @returns {date} (new date)
* @param {Date|String|Number} date to be changed
* @param {Number} isoWeek of the new date
* @returns {Date} new date with the ISO week setted
*/
var setISOWeek = function(dirtyDate, isoWeek) {
var date = parse(dirtyDate)
var time = getTimeSinceMidnight(date)
var diff = getISOWeek(date) - isoWeek
date.setDate(date.getDate() - diff * 7)
date.setHours(0, 0, 0, time)
return date

@@ -21,0 +22,0 @@ }

var parse = require('./parse')
var getTimeSinceMidnight = require('./get_time_since_midnight')
var startOfISOYear = require('./start_of_iso_year')
var differenceInDays = require('./difference_in_days')
var MILLISECONDS_IN_DAY = 86400000
/**
* Sets ISO week-numbering year to given date,
* saving week number and weekday number.
* @category ISO Week-Numbering Year Helpers
* @summary Set the ISO week-numbering year.
*
* @description
* Set the ISO week-numbering year to the given date,
* saving the week number and the weekday number.
*
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
*
* @param {date|string} dirtyDate
* @param {number} isoYear
* @returns {date} (new date)
* @param {Date|String|Number} date to be changed
* @param {Number} isoYear of the new date
* @returns {Date} new date with the ISO year setted
*/
var setISOYear = function(dirtyDate, isoYear) {
var date = parse(dirtyDate)
var time = getTimeSinceMidnight(date)
var diff = differenceInDays(date, startOfISOYear(date))
date = startOfISOYear(new Date(isoYear, 0, 4))
date.setDate(date.getDate() + diff)
date.setHours(0, 0, 0, time)
return date

@@ -28,0 +25,0 @@ }

var parse = require('./parse')
/**
* Sets amount of milliseconds to passed date.
* @param {date|string} dirtyDate
* @param {number} milliseconds
* @returns {date} (new date)
* @category Millisecond Helpers
* @summary Set the milliseconds.
*
* @description
* Set the milliseconds to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} milliseconds of the new date
* @returns {Date} new date with the milliseconds setted
*/

@@ -9,0 +14,0 @@ var setMilliseconds = function(dirtyDate, milliseconds) {

var parse = require('./parse')
/**
* Sets amount of minutes to passed date.
* @param {date|string} dirtyDate
* @param {number} minutes
* @returns {date} (new date)
* @category Minute Helpers
* @summary Set the minutes.
*
* @description
* Set the minutes to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} minutes of the new date
* @returns {Date} new date with the minutes setted
*/

@@ -9,0 +14,0 @@ var setMinutes = function(dirtyDate, minutes) {

var parse = require('./parse')
var getTimeSinceMidnight = require('./get_time_since_midnight')
var getDaysInMonth = require('./get_days_in_month')
/**
* Sets month index to passed date.
* @param {date|string} dirtyDate
* @param {number} monthIndex
* @returns {date} (new date)
* @category Month Helpers
* @summary Set the month.
*
* @description
* Set the month to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} month of the new date
* @returns {Date} new date with the month setted
*/
var setMonth = function(dirtyDate, monthIndex) {
var setMonth = function(dirtyDate, month) {
var date = parse(dirtyDate)
var time = getTimeSinceMidnight(date)
var year = date.getFullYear()
var day = date.getDate()
var daysInMonth = getDaysInMonth(new Date(year, monthIndex))
date.setMonth(monthIndex, Math.min(day, daysInMonth))
date.setHours(0, 0, 0, time)
var daysInMonth = getDaysInMonth(new Date(year, month))
// Set the last day of the new month
// if the original date was the last day of the longer month
date.setMonth(month, Math.min(day, daysInMonth))
return date

@@ -20,0 +24,0 @@ }

@@ -5,7 +5,12 @@ var parse = require('./parse')

/**
* Sets quarter of year to passed date.
* @param {date|string} dirtyDate
* @param {number} quarter
* @returns {date} (new date)
* @category Quarter Helpers
* @summary Set the year quarter.
*
* @description
* Set the year quarter to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} quarter of the new date
* @returns {Date} new date with the quarter setted
*
* @example set second quarter to date 2 July 2014

@@ -12,0 +17,0 @@ * var result = setQuarter(new Date(2014, 6, 2), 2)

var parse = require('./parse')
/**
* Sets amount of seconds to passed date.
* @param {date|string} dirtyDate
* @param {number} seconds
* @returns {date} (new date)
* @category Second Helpers
* @summary Set the seconds.
*
* @description
* Set the seconds to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} seconds of the new date
* @returns {Date} new date with the seconds setted
*/

@@ -9,0 +14,0 @@ var setSeconds = function(dirtyDate, seconds) {

var parse = require('./parse')
var getTimeSinceMidnight = require('./get_time_since_midnight')
/**
* Sets year to passed date.
* @param {date|string} dirtyDate
* @param {number} fullYear
* @returns {date} (new date)
* @category Year Helpers
* @summary Set the year.
*
* @description
* Set the year to the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} year of the new date
* @returns {Date} new date with the year setted
*/
var setYear = function(dirtyDate, fullYear) {
var setYear = function(dirtyDate, year) {
var date = parse(dirtyDate)
var time = getTimeSinceMidnight(date)
date.setFullYear(fullYear)
date.setHours(0, 0, 0, time)
date.setFullYear(year)
return date

@@ -16,0 +18,0 @@ }

var parse = require('./parse')
/**
* Returns start of a day for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Day Helpers
* @summary Return the start of a day for the given date.
*
* @description
* Return the start of a day for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} start of a day
*/

@@ -8,0 +14,0 @@ var startOfDay = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns start of an hour for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Hour Helpers
* @summary Return the start of an hour for the given date.
*
* @description
* Return the start of an hour for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} start of an hour
*/

@@ -8,0 +14,0 @@ var startOfHour = function(dirtyDate) {

@@ -1,13 +0,17 @@

var parse = require('./parse')
var startOfWeek = require('./start_of_week')
var getISOYear = require('./get_iso_year')
var startOfISOWeek = require('./start_of_iso_week')
/**
* Returns start of ISO week-numbering year,
* which always starts 3 days before year's first Thursday.
* @category ISO Week-Numbering Year Helpers
* @summary Return the start of an ISO week-numbering year for the given date.
*
* @description
* Return the start of an ISO week-numbering year,
* which always starts 3 days before the year's first Thursday.
* The result will be in the local timezone.
*
* ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
*
* Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date} (new date)
* @param {Date|String|Number} date - the original date
* @returns {Date} start of an ISO year
*

@@ -19,13 +23,5 @@ * @example when ISO week-numbering 2005 year starts

var startOfISOYear = function(dirtyDate) {
var date = parse(dirtyDate)
var startOfNextYear = startOfWeek(new Date(date.getFullYear() + 1, 0, 4), 1)
var startOfThisYear = startOfWeek(new Date(date.getFullYear(), 0, 4), 1)
if (date.getTime() >= startOfNextYear.getTime()) {
return startOfNextYear
} else if (date.getTime() >= startOfThisYear.getTime()) {
return startOfThisYear
} else {
return startOfWeek(new Date(date.getFullYear() - 1, 0, 4), 1)
}
var year = getISOYear(dirtyDate)
var date = startOfISOWeek(new Date(year, 0, 4))
return date
}

@@ -32,0 +28,0 @@

var parse = require('./parse')
/**
* Returns start of a minute for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Minute Helpers
* @summary Return the start of a minute for the given date.
*
* @description
* Return the start of a minute for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} start of a minute
*/

@@ -8,0 +14,0 @@ var startOfMinute = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns start of a month for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Month Helpers
* @summary Return the start of a month for the given date.
*
* @description
* Return the start of a month for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} start of a month
*/
var startOfMonth = function(dirtyDate) {
var date = parse(dirtyDate)
date.setDate(1)
date.setHours(0, 0, 0, 0)
date.setDate(1)
return date

@@ -13,0 +19,0 @@ }

var parse = require('./parse')
/**
* Returns start of a quarter for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Quarter Helpers
* @summary Return the start of a year quarter for the given date.
*
* @description
* Return the start of a year quarter for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} start of a quarter
*/

@@ -12,4 +18,4 @@ var startOfQuarter = function(dirtyDate) {

var month = currentMonth - currentMonth % 3
date.setMonth(month, 1)
date.setHours(0, 0, 0, 0)
date.setMonth(month, 1)
return date

@@ -16,0 +22,0 @@ }

var parse = require('./parse')
/**
* Returns start of a second for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Second Helpers
* @summary Return the start of a second for the given date.
*
* @description
* Return the start of a second for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} start of a second
*/

@@ -8,0 +14,0 @@ var startOfSecond = function(dirtyDate) {

var parse = require('./parse')
/**
* Returns start of a week for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @param {number} [weekStartsAt=0] first day of week (0 - sunday)
* @returns {date}
* @category Week Helpers
* @summary Return the start of a week for the given date.
*
* @description
* Return the start of a week for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @param {Number} [weekStartsAt=0] the index of the first day of a week (0 - sunday)
* @returns {Date} start of a week
*/

@@ -16,4 +22,4 @@ var startOfWeek = function(dirtyDate, weekStartsAt) {

date.setDate(date.getDate() - diff)
date.setHours(0, 0, 0, 0)
date.setDate(date.getDate() - diff)
return date

@@ -20,0 +26,0 @@ }

var parse = require('./parse')
/**
* Returns start of a year for given date. Date will be in local timezone.
* @param {date|string} dirtyDate
* @returns {date}
* @category Year Helpers
* @summary Return the start of a year for the given date.
*
* @description
* Return the start of a year for the given date.
* The result will be in the local timezone.
*
* @param {Date|String|Number} date - the original date
* @returns {Date} start of a year
*/

@@ -8,0 +14,0 @@ var startOfYear = function(dirtyDate) {

var addDays = require('./add_days')
/**
* Subtracts specified number of days from passed date.
* @param {data|string} dirtyDate
* @param {number} amount
* @returns {date} new date
* @category Day Helpers
* @summary Subtract the specified number of days from the given date.
*
* @description
* Subtract the specified number of days from the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of days to be subtracted
* @returns {Date} new date with the days subtracted
*/

@@ -9,0 +14,0 @@ var subDays = function(dirtyDate, amount) {

var addHours = require('./add_hours')
/**
* Subtracts specified number of hours from passed date.
* @param {data|string} dirtyDate
* @param {number} amount of hours
* @returns {date} new date
* @category Hour Helpers
* @summary Subtract hours from the given date.
*
* @description
* Subtract the specified number of hours from the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of hours to be subtracted
* @returns {Date} new date with the hours subtracted
*/

@@ -9,0 +14,0 @@ var subHours = function(dirtyDate, amount) {

var addMilliseconds = require('./add_milliseconds')
/**
* Subtracts specified number of milliseconds from passed date.
* @param {data|string} dirtyDate
* @param {number} amount of milliseconds
* @returns {date} new date
* @category Millisecond Helpers
* @summary Subtract the milliseconds from the given date.
*
* @description
* Subtract the specified number of milliseconds from the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of milliseconds to be subtracted
* @returns {Date} new date with the milliseconds subtracted
*/

@@ -9,0 +14,0 @@ var subMilliseconds = function(dirtyDate, amount) {

var addMinutes = require('./add_minutes')
/**
* Subtracts specified number of minutes from passed date.
* @param {data|string} dirtyDate
* @param {number} amount of minutes
* @returns {date} new date
* @category Minute Helpers
* @summary Subtract the minutes from the given date.
*
* @description
* Subtract the specified number of minutes from the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of minutes to be subtracted
* @returns {Date} new date with the mintues subtracted
*/

@@ -9,0 +14,0 @@ var subMinutes = function(dirtyDate, amount) {

var addMonths = require('./add_months')
/**
* Subtracts specified number of month from passed date.
* @param {data|string} dirtyDate
* @param {number} amount
* @returns {date} new date
* @category Month Helpers
* @summary Subtract the specified number of months from the given date.
*
* @description
* Subtract the specified number of month from the gien date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of months to be subtracted
* @returns {Date} new date with the months subtracted
*/

@@ -9,0 +14,0 @@ var subMonths = function(dirtyDate, amount) {

var addQuarters = require('./add_quarters')
/**
* Subtracts specified number of quarters from passed date.
* @param {data|string} dirtyDate
* @param {number} amount
* @returns {date} new date
* @category Quarter Helpers
* @summary Subtract the specified number of year quarters from the given date.
*
* @description
* Subtract the specified number of quarters from the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of quarters to be subtracted
* @returns {Date} new date with the quarters subtracted
*/

@@ -9,0 +14,0 @@ var subQuarters = function(dirtyDate, amount) {

var addSeconds = require('./add_seconds')
/**
* Subtracts specified number of seconds from passed date.
* @param {data|string} dirtyDate
* @param {number} amount of seconds
* @returns {date} new date
* @category Second Helpers
* @summary Subtract the seconds from the given date.
*
* @description
* Subtract the specified number of seconds from the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of seconds to be subtracted
* @returns {Date} new date with the seconds subtracted
*/

@@ -9,0 +14,0 @@ var subSeconds = function(dirtyDate, amount) {

var addWeeks = require('./add_weeks')
/**
* Subtracts specified number of weeks from passed date.
* @param {data|string} dirtyDate
* @param {number} amount
* @returns {date} new date
* @category Week Helpers
* @summary Subtract specified number of weeks from the given date.
*
* @description
* Subtract the specified number of weeks from the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of weeks to be subtracted
* @returns {Date} new date with the weeks subtracted
*/

@@ -9,0 +14,0 @@ var subWeeks = function(dirtyDate, amount) {

var addYears = require('./add_years')
/**
* Subtracts specified number of years from passed date.
* @param {data|string} dirtyDate
* @param {number} amount
* @returns {date} new date
* @category Year Helpers
* @summary Subtract the specified number of years from the given date.
*
* @description
* Subtract the specified number of years from the given date.
*
* @param {Date|String|Number} date to be changed
* @param {Number} amount of years to be subtracted
* @returns {Date} new date with the years subtracted
*/

@@ -9,0 +14,0 @@ var subYears = function(dirtyDate, amount) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc