index.js 781 B

123456789101112131415161718192021222324252627282930313233343536
  1. export default (function (_, c, dayjs) {
  2. var proto = c.prototype;
  3. var parseDate = function parseDate(cfg) {
  4. var date = cfg.date,
  5. utc = cfg.utc;
  6. if (typeof date === 'string' && date.charAt(0) === '-') {
  7. var normalData = date.slice(1);
  8. var newDate = dayjs(normalData);
  9. if (utc) {
  10. newDate = dayjs.utc(normalData);
  11. } else {
  12. newDate = dayjs(normalData);
  13. }
  14. var fullYear = newDate.year();
  15. if (date.indexOf("-" + fullYear) !== -1) {
  16. return dayjs(newDate).subtract(fullYear * 2, 'year').toDate();
  17. }
  18. return date;
  19. }
  20. return date;
  21. };
  22. var oldParse = proto.parse;
  23. proto.parse = function (cfg) {
  24. cfg.date = parseDate.bind(this)(cfg);
  25. oldParse.bind(this)(cfg);
  26. };
  27. });