index.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. export default (function (o, c, dayjs) {
  2. // locale needed later
  3. var proto = c.prototype;
  4. var getLocalePart = function getLocalePart(part) {
  5. return part && (part.indexOf ? part : part.s);
  6. };
  7. var getShort = function getShort(ins, target, full, num) {
  8. var locale = ins.name ? ins : ins.$locale();
  9. var targetLocale = getLocalePart(locale[target]);
  10. var fullLocale = getLocalePart(locale[full]);
  11. return targetLocale || fullLocale.map(function (f) {
  12. return f.substr(0, num);
  13. });
  14. };
  15. var getDayjsLocaleObject = function getDayjsLocaleObject() {
  16. return dayjs.Ls[dayjs.locale()];
  17. };
  18. var localeData = function localeData() {
  19. var _this = this;
  20. return {
  21. months: function months(instance) {
  22. return instance ? instance.format('MMMM') : getShort(_this, 'months');
  23. },
  24. monthsShort: function monthsShort(instance) {
  25. return instance ? instance.format('MMM') : getShort(_this, 'monthsShort', 'months', 3);
  26. },
  27. firstDayOfWeek: function firstDayOfWeek() {
  28. return _this.$locale().weekStart || 0;
  29. },
  30. weekdaysMin: function weekdaysMin(instance) {
  31. return instance ? instance.format('dd') : getShort(_this, 'weekdaysMin', 'weekdays', 2);
  32. },
  33. weekdaysShort: function weekdaysShort(instance) {
  34. return instance ? instance.format('ddd') : getShort(_this, 'weekdaysShort', 'weekdays', 3);
  35. },
  36. longDateFormat: function longDateFormat(format) {
  37. return _this.$locale().formats[format];
  38. }
  39. };
  40. };
  41. proto.localeData = function () {
  42. return localeData.bind(this)();
  43. };
  44. dayjs.localeData = function () {
  45. var localeObject = getDayjsLocaleObject();
  46. return {
  47. firstDayOfWeek: function firstDayOfWeek() {
  48. return localeObject.weekStart || 0;
  49. },
  50. weekdays: function weekdays() {
  51. return dayjs.weekdays();
  52. },
  53. weekdaysShort: function weekdaysShort() {
  54. return dayjs.weekdaysShort();
  55. },
  56. weekdaysMin: function weekdaysMin() {
  57. return dayjs.weekdaysMin();
  58. },
  59. months: function months() {
  60. return dayjs.months();
  61. },
  62. monthsShort: function monthsShort() {
  63. return dayjs.monthsShort();
  64. }
  65. };
  66. };
  67. dayjs.months = function () {
  68. return getShort(getDayjsLocaleObject(), 'months');
  69. };
  70. dayjs.monthsShort = function () {
  71. return getShort(getDayjsLocaleObject(), 'monthsShort', 'months', 3);
  72. };
  73. dayjs.weekdays = function () {
  74. return getDayjsLocaleObject().weekdays;
  75. };
  76. dayjs.weekdaysShort = function () {
  77. return getShort(getDayjsLocaleObject(), 'weekdaysShort', 'weekdays', 3);
  78. };
  79. dayjs.weekdaysMin = function () {
  80. return getShort(getDayjsLocaleObject(), 'weekdaysMin', 'weekdays', 2);
  81. };
  82. });