ngx-bootstrap
Version:
Native Angular Bootstrap Components
63 lines • 5.85 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
import { addFormatToken } from '../format/format';
import { addRegexToken, match1 } from '../parse/regex';
import { addParseToken } from '../parse/token';
import { MONTH } from './constants';
import { toInt } from '../utils/type-checks';
import { getMonth } from '../utils/date-getters';
import { addUnitPriority } from './priorities';
import { addUnitAlias } from './aliases';
import { setMonth } from '../utils/date-setters';
/**
* @return {?}
*/
export function initQuarter() {
// FORMATTING
addFormatToken('Q', null, 'Qo', (/**
* @param {?} date
* @param {?} opts
* @return {?}
*/
function (date, opts) {
return getQuarter(date, opts.isUTC)
.toString(10);
}));
// ALIASES
addUnitAlias('quarter', 'Q');
// PRIORITY
addUnitPriority('quarter', 7);
// PARSING
addRegexToken('Q', match1);
addParseToken('Q', (/**
* @param {?} input
* @param {?} array
* @param {?} config
* @return {?}
*/
function (input, array, config) {
array[MONTH] = (toInt(input) - 1) * 3;
return config;
}));
}
// MOMENTS
/**
* @param {?} date
* @param {?=} isUTC
* @return {?}
*/
export function getQuarter(date, isUTC = false) {
return Math.ceil((getMonth(date, isUTC) + 1) / 3);
}
/**
* @param {?} date
* @param {?} quarter
* @param {?=} isUTC
* @return {?}
*/
export function setQuarter(date, quarter, isUTC) {
return setMonth(date, (quarter - 1) * 3 + getMonth(date, isUTC) % 3, isUTC);
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicXVhcnRlci5qcyIsInNvdXJjZVJvb3QiOiJuZzovL25neC1ib290c3RyYXAvY2hyb25vcy8iLCJzb3VyY2VzIjpbInVuaXRzL3F1YXJ0ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztBQUFBLE9BQU8sRUFBRSxjQUFjLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUNsRCxPQUFPLEVBQUUsY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