Repository: iamkun/dayjs

Problem statement:
Format need to check date is invalid & Don't format dayjs(null)
```js
const dayjs = require('dayjs');
const moment = require('moment');

console.log('\n=== dayjs ===');
console.log(dayjs('wtf').format());
console.log(dayjs(null).format());

console.log('\n=== moment ===');
console.log(moment('wtf').format());
console.log(moment(null).format());
```

That code will print: 
```
=== dayjs ===
NaN-NaN-NaNTNaN:NaN:NaN++N:00
2018-04-27T10:38:31+08:00

=== moment ===
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major
 release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: wtf, _f: undefined, _strict: undefined, _locale: [object Object]
Error
    at Function.createFromInputFallback (/Users/ahonn/Desktop/test/node_modules/moment/moment.js:320:98)
    at configFromString (/Users/ahonn/Desktop/test/node_modules/moment/moment.js:2368:15)
    at configFromInput (/Users/ahonn/Desktop/test/node_modules/moment/moment.js:2594:13)
    at prepareConfig (/Users/ahonn/Desktop/test/node_modules/moment/moment.js:2577:13)
    at createFromConfig (/Users/ahonn/Desktop/test/node_modules/moment/moment.js:2544:44)
    at createLocalOrUTC (/Users/ahonn/Desktop/test/node_modules/moment/moment.js:2631:16)
    at createLocal (/Users/ahonn/Desktop/test/node_modules/moment/moment.js:2635:16)
    at hooks (/Users/ahonn/Desktop/test/node_modules/moment/moment.js:12:29)
    at Object.<anonymous> (/Users/ahonn/Desktop/test/index.js:16:13)
    at Module._compile (module.js:652:30)
Invalid date
Invalid date
```

You need to check date is invalid, `dayjs('wtf')` preferably returns `Invalid date`.
And `dayjs(null)` should not return current date, `null` is not equal to `undefined`.



Hints:
After checking ECMAScript docs, I found a interesting thing.
```
new Date(null) // Valid
new Date(0) // Valid
// but:
new Date(undefined) // Invalid
new Date('wtf') // Invalid
```
That is to say, null is considered as a valid date in JS.

Still, I think `null` is different to `0`, and `null` should be an __invalid__ date.

Please share your thoughts.

Patch:
diff --git a/src/index.js b/src/index.js
--- a/src/index.js
+++ b/src/index.js
@@ -3,6 +3,7 @@ import * as Utils from './utils'
 
 const parseConfig = (config) => {
   let reg
+  if (config === null) return new Date(NaN) // Treat null as an invalid date
   if (!config) return new Date()
   if (config instanceof Date) return config
   // eslint-disable-next-line no-cond-assign


Test patch:
diff --git a/test/parse.test.js b/test/parse.test.js
--- a/test/parse.test.js
+++ b/test/parse.test.js
@@ -27,11 +27,12 @@ describe('Parse', () => {
     expect(dayjs(time).valueOf()).toBe(moment(time).valueOf())
   })
 
-  it('String Other and isValid', () => {
+  it('String Other, Null and isValid', () => {
     global.console.warn = jest.genMockFunction()// moment.js otherString will throw warn
     expect(dayjs('otherString').toString().toLowerCase()).toBe(moment('otherString').toString().toLowerCase())
     expect(dayjs().isValid()).toBe(true)
     expect(dayjs('otherString').isValid()).toBe(false)
+    expect(dayjs(null).toString().toLowerCase()).toBe(moment(null).toString().toLowerCase())
   })
 })