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
12 changes: 6 additions & 6 deletions src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ const expressions = {
MMM: [matchWord, function (input) {
const months = getLocalePart('months')
const monthsShort = getLocalePart('monthsShort')
const matchIndex = (monthsShort || months.map(_ => _.slice(0, 3))).indexOf(input) + 1
if (matchIndex < 1) {
const matchIndex = (monthsShort || months.map(_ => _.slice(0, 3))).indexOf(input)
if (matchIndex < 0) {
throw new Error()
}
this.month = (matchIndex % 12) || matchIndex
this.month = (matchIndex % 12) + 1
}],
MMMM: [matchWord, function (input) {
const months = getLocalePart('months')
const matchIndex = months.indexOf(input) + 1
if (matchIndex < 1) {
const matchIndex = months.indexOf(input)
if (matchIndex < 0) {
throw new Error()
}
this.month = (matchIndex % 12) || matchIndex
this.month = (matchIndex % 12) + 1
}],
Y: [matchSigned, addInput('year')],
YY: [match2, function (input) {
Expand Down
14 changes: 14 additions & 0 deletions test/plugin/customParseFormat.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import MockDate from 'mockdate'
import moment from 'moment'
import dayjs from '../../src'
import '../../src/locale/be'
import '../../src/locale/ru'
import uk from '../../src/locale/uk'
import '../../src/locale/zh-cn'
Expand Down Expand Up @@ -211,13 +212,26 @@ it('parse month from short string with locale in argument', () => {
expect(dayjs(input, format, 'uk').valueOf()).toBe(moment(input, format, 'uk').valueOf())
})

it('parse last month of year from short format string with locale', () => {
const input = '2018 снеж. 03'
const format = 'YYYY MMM DD'
expect(dayjs(input, format, 'be').valueOf()).toBe(moment(input, format, 'be').valueOf())
})

it('parse month from string with locale in argument', () => {
const input = '2018 лютий 03'
const format = 'YYYY MMMM DD'

expect(dayjs(input, format, 'uk').valueOf()).toBe(moment(input, format, 'uk').valueOf())
})

it('parse last month of year from format string with locale', () => {
const input = '2018 грудня 03'
const format = 'YYYY MMMM DD'

expect(dayjs(input, format, 'uk').valueOf()).toBe(moment(input, format, 'uk').valueOf())
})

it('return Invalid Date when parse corrupt string', () => {
const input = '2018 Turnip 03'
const format = 'YYYY MMMM DD'
Expand Down