/* eslint-disable eslint-comments/no-unlimited-disable */ /* eslint-disable */ // @ts-nocheck import type { Match } from '../../../locale/types.ts'; import { setDay } from '../../../setDay/index.ts'; import { Parser } from '../Parser.ts'; import type { ParseFlags, ParseResult, ParserOptions } from '../types.ts'; import { mapValue, parseNDigits } from '../utils.ts'; // Stand-alone local day of week export class StandAloneLocalDayParser extends Parser { priority = 90; parse(dateString: string, token: string, match: Match, options: ParserOptions): ParseResult { const valueCallback = (value: number) => { // We want here floor instead of trunc, so we get -7 for value 0 instead of 0 const wholeWeekDays = Math.floor((value - 1) / 7) * 7; return ((value + options.weekStartsOn + 6) % 7) + wholeWeekDays; }; switch (token) { // 3 case 'c': case 'cc': // 03 return mapValue(parseNDigits(token.length, dateString), valueCallback); // 3rd case 'co': return mapValue( match.ordinalNumber(dateString, { unit: 'day', }), valueCallback, ); // Tue case 'ccc': return ( match.day(dateString, { width: 'abbreviated', context: 'standalone', }) || match.day(dateString, { width: 'short', context: 'standalone' }) || match.day(dateString, { width: 'narrow', context: 'standalone' }) ); // T case 'ccccc': return match.day(dateString, { width: 'narrow', context: 'standalone', }); // Tu case 'cccccc': return ( match.day(dateString, { width: 'short', context: 'standalone' }) || match.day(dateString, { width: 'narrow', context: 'standalone' }) ); // Tuesday case 'cccc': default: return ( match.day(dateString, { width: 'wide', context: 'standalone' }) || match.day(dateString, { width: 'abbreviated', context: 'standalone', }) || match.day(dateString, { width: 'short', context: 'standalone' }) || match.day(dateString, { width: 'narrow', context: 'standalone' }) ); } } validate(_date: DateType, value: number): boolean { return value >= 0 && value <= 6; } set(date: DateType, _flags: ParseFlags, value: number, options: ParserOptions): DateType { date = setDay(date, value, options); date.setHours(0, 0, 0, 0); return date; } incompatibleTokens: string[] = ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'E', 'i', 'e', 't', 'T']; } /* eslint-enable */