index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* eslint-disable no-console */
  2. export default (function (o, c, d) {
  3. /* istanbul ignore next line */
  4. if (!process || process.env.NODE_ENV !== 'production') {
  5. var proto = c.prototype;
  6. var oldParse = proto.parse;
  7. proto.parse = function (cfg) {
  8. var date = cfg.date;
  9. if (typeof date === 'string' && date.length === 13) {
  10. 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");
  11. }
  12. if (typeof date === 'number' && String(date).length === 4) {
  13. console.warn("Guessing you may want to parse the Year " + date + ", you should pass it as a String " + date + ", not a Number. Otherwise, " + date + " will be treated as a Unix timestamp");
  14. }
  15. if (cfg.args.length >= 2 && !d.p.customParseFormat) {
  16. 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");
  17. }
  18. return oldParse.bind(this)(cfg);
  19. };
  20. var oldLocale = d.locale;
  21. d.locale = function (preset, object, isLocal) {
  22. if (typeof object === 'undefined' && typeof preset === 'string') {
  23. if (!d.Ls[preset]) {
  24. console.warn("Guessing you may want to use locale " + preset + ", you have to load it before using it. https://day.js.org/docs/en/i18n/loading-into-nodejs");
  25. }
  26. }
  27. return oldLocale(preset, object, isLocal);
  28. };
  29. var oldDiff = proto.diff;
  30. proto.diff = function (date, unit, _float) {
  31. var isInvalidDate = !date || !d(date).isValid();
  32. if (isInvalidDate) {
  33. console.warn('Invalid usage: diff() requires a valid comparison date as the first argument. https://day.js.org/docs/en/display/difference');
  34. }
  35. return oldDiff.call(this, date, unit, _float);
  36. };
  37. }
  38. });