You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

122 line
3.8 KiB

  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
  4. exports.__esModule = true;
  5. exports.default = _default;
  6. exports.formats = void 0;
  7. var dates = _interopRequireWildcard(require("../utils/dates"));
  8. var _oldGlobalize = _interopRequireDefault(require("./oldGlobalize"));
  9. var _localizer = require("../localizer");
  10. var _warning = _interopRequireDefault(require("warning"));
  11. var dateRangeFormat = function dateRangeFormat(_ref, culture, local) {
  12. var start = _ref.start,
  13. end = _ref.end;
  14. return local.format(start, {
  15. date: 'short'
  16. }, culture) + ' – ' + local.format(end, {
  17. date: 'short'
  18. }, culture);
  19. };
  20. var timeRangeFormat = function timeRangeFormat(_ref2, culture, local) {
  21. var start = _ref2.start,
  22. end = _ref2.end;
  23. return local.format(start, {
  24. time: 'short'
  25. }, culture) + ' – ' + local.format(end, {
  26. time: 'short'
  27. }, culture);
  28. };
  29. var timeRangeStartFormat = function timeRangeStartFormat(_ref3, culture, local) {
  30. var start = _ref3.start;
  31. return local.format(start, {
  32. time: 'short'
  33. }, culture) + ' – ';
  34. };
  35. var timeRangeEndFormat = function timeRangeEndFormat(_ref4, culture, local) {
  36. var end = _ref4.end;
  37. return ' – ' + local.format(end, {
  38. time: 'short'
  39. }, culture);
  40. };
  41. var weekRangeFormat = function weekRangeFormat(_ref5, culture, local) {
  42. var start = _ref5.start,
  43. end = _ref5.end;
  44. return local.format(start, 'MMM dd', culture) + ' – ' + local.format(end, dates.eq(start, end, 'month') ? 'dd' : 'MMM dd', culture);
  45. };
  46. var formats = {
  47. dateFormat: 'dd',
  48. dayFormat: 'eee dd/MM',
  49. weekdayFormat: 'eee',
  50. selectRangeFormat: timeRangeFormat,
  51. eventTimeRangeFormat: timeRangeFormat,
  52. eventTimeRangeStartFormat: timeRangeStartFormat,
  53. eventTimeRangeEndFormat: timeRangeEndFormat,
  54. timeGutterFormat: {
  55. time: 'short'
  56. },
  57. monthHeaderFormat: 'MMMM yyyy',
  58. dayHeaderFormat: 'eeee MMM dd',
  59. dayRangeHeaderFormat: weekRangeFormat,
  60. agendaHeaderFormat: dateRangeFormat,
  61. agendaDateFormat: 'eee MMM dd',
  62. agendaTimeFormat: {
  63. time: 'short'
  64. },
  65. agendaTimeRangeFormat: timeRangeFormat
  66. };
  67. exports.formats = formats;
  68. function _default(globalize) {
  69. var locale = function locale(culture) {
  70. return culture ? globalize(culture) : globalize;
  71. }; // return the first day of the week from the locale data. Defaults to 'world'
  72. // territory if no territory is derivable from CLDR.
  73. // Failing to use CLDR supplemental (not loaded?), revert to the original
  74. // method of getting first day of week.
  75. function firstOfWeek(culture) {
  76. try {
  77. var days = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
  78. var cldr = locale(culture).cldr;
  79. var territory = cldr.attributes.territory;
  80. var weekData = cldr.get('supplemental').weekData;
  81. var firstDay = weekData.firstDay[territory || '001'];
  82. return days.indexOf(firstDay);
  83. } catch (e) {
  84. process.env.NODE_ENV !== "production" ? (0, _warning.default)(true, "Failed to accurately determine first day of the week.\n Is supplemental data loaded into CLDR?") : void 0; // maybe cldr supplemental is not loaded? revert to original method
  85. var date = new Date(); //cldr-data doesn't seem to be zero based
  86. var localeDay = Math.max(parseInt(locale(culture).formatDate(date, {
  87. raw: 'e'
  88. }), 10) - 1, 0);
  89. return Math.abs(date.getDay() - localeDay);
  90. }
  91. }
  92. if (!globalize.load) return (0, _oldGlobalize.default)(globalize);
  93. return new _localizer.DateLocalizer({
  94. firstOfWeek: firstOfWeek,
  95. formats: formats,
  96. format: function format(value, _format, culture) {
  97. _format = typeof _format === 'string' ? {
  98. raw: _format
  99. } : _format;
  100. return locale(culture).formatDate(value, _format);
  101. }
  102. });
  103. }