Tumortisch-Dist/resources/app/node_modules/date-fns/esm/lastDayOfDecade/index.js
2021-06-15 16:00:08 +02:00

35 lines
1.1 KiB
JavaScript

import toDate from '../toDate/index.js';
/**
* @name lastDayOfDecade
* @category Decade Helpers
* @summary Return the last day of a decade for the given date.
*
* @description
* Return the last day of a decade for the given date.
*
* ### 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).
*
* @param {Date|Number} date - the original date
* @returns {Date} the last day of a decade
* @throws {TypeError} 1 argument required
*
* @example
* // The last day of a decade for 21 December 2012 21:12:00:
* var result = lastDayOfDecade(new Date(2012, 11, 21, 21, 12, 00))
* //=> Wed Dec 31 2019 00:00:00
*/
export default function lastDayOfDecade(dirtyDate) {
if (arguments.length < 1) {
throw new TypeError('1 argument required, but only ' + arguments.length + ' present');
}
var date = toDate(dirtyDate);
var year = date.getFullYear();
var decade = 9 + Math.floor(year / 10) * 10;
date.setFullYear(decade + 1, 0, 0);
date.setHours(0, 0, 0, 0);
return date;
}