day-of-month.js (959B)
1import { makeGetSet } from '../moment/get-set'; 2import { addFormatToken } from '../format/format'; 3import { 4 addRegexToken, 5 match1to2, 6 match2, 7 match1to2NoLeadingZero, 8} from '../parse/regex'; 9import { addParseToken } from '../parse/token'; 10import { DATE } from './constants'; 11import toInt from '../utils/to-int'; 12 13// FORMATTING 14 15addFormatToken('D', ['DD', 2], 'Do', 'date'); 16 17// PARSING 18 19addRegexToken('D', match1to2, match1to2NoLeadingZero); 20addRegexToken('DD', match1to2, match2); 21addRegexToken('Do', function (isStrict, locale) { 22 // TODO: Remove "ordinalParse" fallback in next major release. 23 return isStrict 24 ? locale._dayOfMonthOrdinalParse || locale._ordinalParse 25 : locale._dayOfMonthOrdinalParseLenient; 26}); 27 28addParseToken(['D', 'DD'], DATE); 29addParseToken('Do', function (input, array) { 30 array[DATE] = toInt(input.match(match1to2)[0]); 31}); 32 33// MOMENTS 34 35export var getSetDayOfMonth = makeGetSet('Date', true);