quarter.js 780 B

12345678910111213141516171819202122232425262728293031323334
  1. import { addFormatToken } from '../format/format';
  2. import { addUnitAlias } from './aliases';
  3. import { addUnitPriority } from './priorities';
  4. import { addRegexToken, match1 } from '../parse/regex';
  5. import { addParseToken } from '../parse/token';
  6. import { MONTH } from './constants';
  7. import toInt from '../utils/to-int';
  8. // FORMATTING
  9. addFormatToken('Q', 0, 'Qo', 'quarter');
  10. // ALIASES
  11. addUnitAlias('quarter', 'Q');
  12. // PRIORITY
  13. addUnitPriority('quarter', 7);
  14. // PARSING
  15. addRegexToken('Q', match1);
  16. addParseToken('Q', function (input, array) {
  17. array[MONTH] = (toInt(input) - 1) * 3;
  18. });
  19. // MOMENTS
  20. export function getSetQuarter(input) {
  21. return input == null
  22. ? Math.ceil((this.month() + 1) / 3)
  23. : this.month((input - 1) * 3 + (this.month() % 3));
  24. }