UNPKG

jobiqo-cl

Version:

[![CircleCI](https://circleci.com/gh/jobiqo/jobiqo-cl.svg?style=svg&circle-token=5a24efa5b8bbc4879276123e77d0d3f35ca7144c)](https://circleci.com/gh/jobiqo/jobiqo-cl)

45 lines (38 loc) 1.37 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var index = require('../toDate/index.js'); var index$1$1 = require('../_lib/toInteger/index.js'); var index$1 = require('../setMonth/index.js'); /** * @name setQuarter * @category Quarter Helpers * @summary Set the year quarter to the given date. * * @description * Set the year quarter to 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 date to be changed * @param {Number} quarter - the quarter of the new date * @returns {Date} the new date with the quarter set * @throws {TypeError} 2 arguments required * * @example * // Set the 2nd quarter to 2 July 2014: * var result = setQuarter(new Date(2014, 6, 2), 2) * //=> Wed Apr 02 2014 00:00:00 */ function setQuarter(dirtyDate, dirtyQuarter) { if (arguments.length < 2) { throw new TypeError('2 arguments required, but only ' + arguments.length + ' present'); } var date = index.default(dirtyDate); var quarter = index$1$1.default(dirtyQuarter); var oldQuarter = Math.floor(date.getMonth() / 3) + 1; var diff = quarter - oldQuarter; return index$1.default(date, date.getMonth() + diff * 3); } exports.default = setQuarter;