cscg24-guacamole

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

week.js (1518B)


      1import { addFormatToken } from '../format/format';
      2import {
      3    addRegexToken,
      4    match1to2,
      5    match2,
      6    match1to2NoLeadingZero,
      7} from '../parse/regex';
      8import { addWeekParseToken } from '../parse/token';
      9import toInt from '../utils/to-int';
     10import { weekOfYear } from './week-calendar-utils';
     11
     12// FORMATTING
     13
     14addFormatToken('w', ['ww', 2], 'wo', 'week');
     15addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
     16
     17// PARSING
     18
     19addRegexToken('w', match1to2, match1to2NoLeadingZero);
     20addRegexToken('ww', match1to2, match2);
     21addRegexToken('W', match1to2, match1to2NoLeadingZero);
     22addRegexToken('WW', match1to2, match2);
     23
     24addWeekParseToken(
     25    ['w', 'ww', 'W', 'WW'],
     26    function (input, week, config, token) {
     27        week[token.substr(0, 1)] = toInt(input);
     28    }
     29);
     30
     31// HELPERS
     32
     33// LOCALES
     34
     35export function localeWeek(mom) {
     36    return weekOfYear(mom, this._week.dow, this._week.doy).week;
     37}
     38
     39export var defaultLocaleWeek = {
     40    dow: 0, // Sunday is the first day of the week.
     41    doy: 6, // The week that contains Jan 6th is the first week of the year.
     42};
     43
     44export function localeFirstDayOfWeek() {
     45    return this._week.dow;
     46}
     47
     48export function localeFirstDayOfYear() {
     49    return this._week.doy;
     50}
     51
     52// MOMENTS
     53
     54export function getSetWeek(input) {
     55    var week = this.localeData().week(this);
     56    return input == null ? week : this.add((input - week) * 7, 'd');
     57}
     58
     59export function getSetISOWeek(input) {
     60    var week = weekOfYear(this, 1, 4).week;
     61    return input == null ? week : this.add((input - week) * 7, 'd');
     62}