hugoWebsite/node_modules/date-fns/startOfDecade/index.js

41 lines
1.1 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = startOfDecade;
var _index = _interopRequireDefault(require("../toDate/index.js"));
var _index2 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @name startOfDecade
* @category Decade Helpers
* @summary Return the start of a decade for the given date.
*
* @description
* Return the start of a decade for the given date.
*
* @param {Date|Number} date - the original date
* @returns {Date} the start of a decade
* @throws {TypeError} 1 argument required
*
* @example
* // The start of a decade for 21 October 2015 00:00:00:
* const result = startOfDecade(new Date(2015, 9, 21, 00, 00, 00))
* //=> Jan 01 2010 00:00:00
*/
function startOfDecade(dirtyDate) {
(0, _index2.default)(1, arguments);
var date = (0, _index.default)(dirtyDate);
var year = date.getFullYear();
var decade = Math.floor(year / 10) * 10;
date.setFullYear(decade, 0, 1);
date.setHours(0, 0, 0, 0);
return date;
}
module.exports = exports.default;