Няма описание

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*!
  2. FullCalendar Moment Plugin v4.3.0
  3. Docs & License: https://fullcalendar.io/
  4. (c) 2019 Adam Shaw
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('moment'), require('@fullcalendar/core')) :
  8. typeof define === 'function' && define.amd ? define(['exports', 'moment', '@fullcalendar/core'], factory) :
  9. (global = global || self, factory(global.FullCalendarMoment = {}, global.moment, global.FullCalendar));
  10. }(this, function (exports, momentNs, core) { 'use strict';
  11. var moment = momentNs; // the directly callable function
  12. function toMoment(date, calendar) {
  13. if (!(calendar instanceof core.Calendar)) {
  14. throw new Error('must supply a Calendar instance');
  15. }
  16. return convertToMoment(date, calendar.dateEnv.timeZone, null, calendar.dateEnv.locale.codes[0]);
  17. }
  18. function toDuration(fcDuration) {
  19. return moment.duration(fcDuration); // moment accepts all the props that fc.Duration already has!
  20. }
  21. function formatWithCmdStr(cmdStr, arg) {
  22. var cmd = parseCmdStr(cmdStr);
  23. if (arg.end) {
  24. var startMom = convertToMoment(arg.start.array, arg.timeZone, arg.start.timeZoneOffset, arg.localeCodes[0]);
  25. var endMom = convertToMoment(arg.end.array, arg.timeZone, arg.end.timeZoneOffset, arg.localeCodes[0]);
  26. return formatRange(cmd, createMomentFormatFunc(startMom), createMomentFormatFunc(endMom), arg.separator);
  27. }
  28. return convertToMoment(arg.date.array, arg.timeZone, arg.date.timeZoneOffset, arg.localeCodes[0]).format(cmd.whole); // TODO: test for this
  29. }
  30. var main = core.createPlugin({
  31. cmdFormatter: formatWithCmdStr
  32. });
  33. function createMomentFormatFunc(mom) {
  34. return function (cmdStr) {
  35. return cmdStr ? mom.format(cmdStr) : ''; // because calling with blank string results in ISO8601 :(
  36. };
  37. }
  38. function convertToMoment(input, timeZone, timeZoneOffset, locale) {
  39. var mom;
  40. if (timeZone === 'local') {
  41. mom = moment(input);
  42. }
  43. else if (timeZone === 'UTC') {
  44. mom = moment.utc(input);
  45. }
  46. else if (moment.tz) {
  47. mom = moment.tz(input, timeZone);
  48. }
  49. else {
  50. mom = moment.utc(input);
  51. if (timeZoneOffset != null) {
  52. mom.utcOffset(timeZoneOffset);
  53. }
  54. }
  55. mom.locale(locale);
  56. return mom;
  57. }
  58. function parseCmdStr(cmdStr) {
  59. var parts = cmdStr.match(/^(.*?)\{(.*)\}(.*)$/); // TODO: lookbehinds for escape characters
  60. if (parts) {
  61. var middle = parseCmdStr(parts[2]);
  62. return {
  63. head: parts[1],
  64. middle: middle,
  65. tail: parts[3],
  66. whole: parts[1] + middle.whole + parts[3]
  67. };
  68. }
  69. else {
  70. return {
  71. head: null,
  72. middle: null,
  73. tail: null,
  74. whole: cmdStr
  75. };
  76. }
  77. }
  78. function formatRange(cmd, formatStart, formatEnd, separator) {
  79. if (cmd.middle) {
  80. var startHead = formatStart(cmd.head);
  81. var startMiddle = formatRange(cmd.middle, formatStart, formatEnd, separator);
  82. var startTail = formatStart(cmd.tail);
  83. var endHead = formatEnd(cmd.head);
  84. var endMiddle = formatRange(cmd.middle, formatStart, formatEnd, separator);
  85. var endTail = formatEnd(cmd.tail);
  86. if (startHead === endHead && startTail === endTail) {
  87. return startHead +
  88. (startMiddle === endMiddle ? startMiddle : startMiddle + separator + endMiddle) +
  89. startTail;
  90. }
  91. }
  92. var startWhole = formatStart(cmd.whole);
  93. var endWhole = formatEnd(cmd.whole);
  94. if (startWhole === endWhole) {
  95. return startWhole;
  96. }
  97. else {
  98. return startWhole + separator + endWhole;
  99. }
  100. }
  101. exports.default = main;
  102. exports.toDuration = toDuration;
  103. exports.toMoment = toMoment;
  104. Object.defineProperty(exports, '__esModule', { value: true });
  105. }));