Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/parseformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,24 @@ function parseFormat (dateString, options) {
format = format.replace(regexMonth, options.preferLongFormat ? 'MM' : 'M')
}

// If still remaining more numbers and year is not present then one number is the year
if (!format.match(formatIncludesYear) && format.match(formatHasTimeAfterRemainingDigits)) {
format = format.replace(regexYearShort, 'YY')
}

// Check for some odd cases, such as MMMM <some number that is a DAY> <more of the format>
if (format.match(formatHasDayWithLeadingZeroAfterMonthSegment) && !format.match(formatHasTimeAfterRemainingDigits)) {
if (format.match(formatHasDayWithLeadingZeroAfterMonthSegment)) {
format = format.replace(regexDayLeadingZero, 'DD')
}
if (format.match(formatHasDayAfterMonthSegment) && !format.match(formatHasTimeAfterRemainingDigits)) {
if (format.match(formatHasDayAfterMonthSegment)) {
format = format.replace(regexDay, options.preferLongFormat ? 'DD' : 'D')
}

// now, the next number, if existing, must be a day IF it is the last set of numbers in the format
if (!format.match(formatIncludesNumericDay) && format.match(formatHasMultipleRemainingSegments) && !format.match(formatHasTimeAfterRemainingDigits)) {
if (!format.match(formatIncludesNumericDay) && format.match(formatHasMultipleRemainingSegments) ) {
format = format.replace(regexDayLeadingZero, 'DD')
}
if (!format.match(formatIncludesNumericDay) && format.match(formatHasMultipleRemainingSegments) && !format.match(formatHasTimeAfterRemainingDigits)) {
if (!format.match(formatIncludesNumericDay) && format.match(formatHasMultipleRemainingSegments) ) {
format = format.replace(regexDay, options.preferLongFormat ? 'DD' : 'D')
}

Expand Down
2 changes: 1 addition & 1 deletion test/moment-parseformat-test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.