Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed May 31, 2018
2 parents 7a592cb + 6ef7d98 commit ad46ef9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/en/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Returns a `Dayjs` with the applied changes.
```js
dayjs('2000-10-25')
.set('month', 3)
.set('year', 2020).toString(); // Sat, 25 Apr 2020 00:00:00 GMT
.set('year', 2020).toString(); // Sat, 25 Mar 2020 00:00:00 GMT
```

## Manipulating
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@
"typescript": "^2.8.3"
},
"dependencies": {}
}
}
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ const parseDate = (date) => {
if (Utils.isUndefined(date)) return new Date()
if (date instanceof Date) return date
// eslint-disable-next-line no-cond-assign
if ((typeof date === 'string') && (reg = date.match(C.REGEX_PARSE))) {
if ((typeof date === 'string')
&& (/.*[^Z]$/i.test(date)) // looking for a better way
&& (reg = date.match(C.REGEX_PARSE))) {
// 2018-08-08 or 20180808
return new Date(
reg[1], reg[2] - 1, reg[3] || 1,
Expand Down
2 changes: 2 additions & 0 deletions test/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ describe('Parse', () => {
expect(dayjs(d).valueOf()).toBe(moment(d).valueOf()) // not recommend
d = '2018'
expect(dayjs(d).format()).toBe(moment(d).format()) // not recommend
d = '2018-05-02T11:12:13Z' // should go direct to new Date() rather our regex
expect(dayjs(d).format()).toBe(moment(d).format()) // not recommend
})

it('String ISO 8601 date, time and zone', () => {
Expand Down

0 comments on commit ad46ef9

Please sign in to comment.