cscg24-guacamole

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

day-of-year.js (737B)


      1import { addFormatToken } from '../format/format';
      2import { addRegexToken, match3, match1to3 } from '../parse/regex';
      3import { addParseToken } from '../parse/token';
      4import toInt from '../utils/to-int';
      5
      6// FORMATTING
      7
      8addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
      9
     10// PARSING
     11
     12addRegexToken('DDD', match1to3);
     13addRegexToken('DDDD', match3);
     14addParseToken(['DDD', 'DDDD'], function (input, array, config) {
     15    config._dayOfYear = toInt(input);
     16});
     17
     18// HELPERS
     19
     20// MOMENTS
     21
     22export function getSetDayOfYear(input) {
     23    var dayOfYear =
     24        Math.round(
     25            (this.clone().startOf('day') - this.clone().startOf('year')) / 864e5
     26        ) + 1;
     27    return input == null ? dayOfYear : this.add(input - dayOfYear, 'd');
     28}