2026-07-05 06:41:32 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = addDays ;
2026-07-07 07:11:50 +00:00
2026-07-05 06:41:32 +00:00
var _index = _interopRequireDefault ( require ( "../_lib/toInteger/index.js" ) ) ;
2026-07-07 07:11:50 +00:00
2026-07-05 06:41:32 +00:00
var _index2 = _interopRequireDefault ( require ( "../toDate/index.js" ) ) ;
2026-07-07 07:11:50 +00:00
2026-07-05 06:41:32 +00:00
var _index3 = _interopRequireDefault ( require ( "../_lib/requiredArgs/index.js" ) ) ;
2026-07-07 07:11:50 +00:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
2026-07-05 06:41:32 +00:00
/**
* @name addDays
* @category Day Helpers
* @summary Add the specified number of days to the given date.
*
* @description
* Add the specified number of days to the given date.
*
2026-07-07 07:11:50 +00:00
* ### v2.0.0 breaking changes:
*
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
*
2026-07-05 06:41:32 +00:00
* @param {Date|Number} date - the date to be changed
* @param {Number} amount - the amount of days to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
* @returns {Date} - the new date with the days added
* @throws {TypeError} - 2 arguments required
*
* @example
* // Add 10 days to 1 September 2014:
* const result = addDays(new Date(2014, 8, 1), 10)
* //=> Thu Sep 11 2014 00:00:00
*/
function addDays ( dirtyDate , dirtyAmount ) {
( 0 , _index3 . default ) ( 2 , arguments ) ;
var date = ( 0 , _index2 . default ) ( dirtyDate ) ;
var amount = ( 0 , _index . default ) ( dirtyAmount ) ;
2026-07-07 07:11:50 +00:00
2026-07-05 06:41:32 +00:00
if ( isNaN ( amount ) ) {
return new Date ( NaN ) ;
}
2026-07-07 07:11:50 +00:00
2026-07-05 06:41:32 +00:00
if ( ! amount ) {
// If 0 days, no-op to avoid changing times in the hour before end of DST
return date ;
}
2026-07-07 07:11:50 +00:00
2026-07-05 06:41:32 +00:00
date . setDate ( date . getDate ( ) + amount ) ;
return date ;
}
2026-07-07 07:11:50 +00:00
2026-07-05 06:41:32 +00:00
module . exports = exports . default ;