cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

quarter.js (602B)


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