diff --git a/src/index.js b/src/index.js index 29adf1d4..799bb3a3 100644 --- a/src/index.js +++ b/src/index.js @@ -401,5 +401,5 @@ dayjs.unix = timestamp => ( dayjs.en = Ls[L] dayjs.Ls = Ls - +dayjs.p = {} export default dayjs diff --git a/src/plugin/customParseFormat/index.js b/src/plugin/customParseFormat/index.js index c1c7b85b..d96df6fe 100644 --- a/src/plugin/customParseFormat/index.js +++ b/src/plugin/customParseFormat/index.js @@ -182,6 +182,7 @@ const parseFormattedInput = (input, format, utc) => { export default (o, C, d) => { + d.p.customParseFormat = true const proto = C.prototype const oldParse = proto.parse proto.parse = function (cfg) { diff --git a/src/plugin/devHelper/index.js b/src/plugin/devHelper/index.js new file mode 100644 index 00000000..40e1f38a --- /dev/null +++ b/src/plugin/devHelper/index.js @@ -0,0 +1,18 @@ +/* eslint-disable no-console */ +export default (o, c, d) => { + if (process.env.NODE_ENV !== 'production') { + const proto = c.prototype + const oldParse = proto.parse + proto.parse = function (cfg) { + const { date } = cfg + if (typeof date === 'string' && date.length === 13) { + console.warn(`To parse a Unix timestamp like ${date}, you should pass it as a Number. https://day.js.org/docs/en/parse/unix-timestamp-milliseconds`) + } + if (cfg.args.length >= 2 && !d.p.customParseFormat) { + console.warn(`To parse a date-time string like ${date} using the given format, you should enable customParseFormat plugin first. https://day.js.org/docs/en/parse/string-format`) + } + return oldParse.bind(this)(cfg) + } + } +} + diff --git a/types/plugin/devHelper.d.ts b/types/plugin/devHelper.d.ts new file mode 100644 index 00000000..30ec75e5 --- /dev/null +++ b/types/plugin/devHelper.d.ts @@ -0,0 +1,4 @@ +import { PluginFunc } from 'dayjs' + +declare const plugin: PluginFunc +export = plugin