budibase/packages/common/node_modules/date-fns/get_quarter/index.js

25 lines
556 B
JavaScript
Raw Normal View History

2020-04-07 16:12:08 +02:00
var parse = require('../parse/index.js')
/**
* @category Quarter Helpers
* @summary Get the year quarter of the given date.
*
* @description
* Get the year quarter of the given date.
*
* @param {Date|String|Number} date - the given date
* @returns {Number} the quarter
*
* @example
* // Which quarter is 2 July 2014?
* var result = getQuarter(new Date(2014, 6, 2))
* //=> 3
*/
function getQuarter (dirtyDate) {
var date = parse(dirtyDate)
var quarter = Math.floor(date.getMonth() / 3) + 1
return quarter
}
module.exports = getQuarter