@react-fabric/date 1.0.0-beta.9 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +2 -9
  2. package/{src/components/Date.module.css → css/_date.css} +5 -5
  3. package/{src/superdate/SuperDate.module.css → css/styles.css} +2 -8
  4. package/dist/cjs/components/DateCell.js +5 -7
  5. package/dist/cjs/components/DateHeader.js +27 -20
  6. package/dist/cjs/components/DatePage.js +10 -12
  7. package/dist/cjs/components/DecadePage.js +3 -3
  8. package/dist/cjs/components/MonthPage.js +3 -3
  9. package/dist/cjs/components/TimeSliders.js +36 -35
  10. package/dist/cjs/components/YearPage.js +3 -3
  11. package/dist/cjs/display/DateDisplay.js +25 -8
  12. package/dist/cjs/display/DateDuration.js +155 -0
  13. package/dist/cjs/hijri/DateConverter.js +154 -0
  14. package/dist/cjs/hijri/FormatDate.js +116 -0
  15. package/dist/cjs/hijri/HijriDate.js +531 -0
  16. package/dist/cjs/hijri/StringDateParser.js +74 -0
  17. package/dist/cjs/hijri/index.js +15 -1025
  18. package/dist/cjs/hijri/initializer.js +113 -0
  19. package/dist/cjs/hijri/locales.js +19 -0
  20. package/dist/cjs/hijri/safe.js +17 -0
  21. package/dist/cjs/i18n/ar/date.json.js +213 -0
  22. package/dist/cjs/i18n/en/date.json.js +83 -0
  23. package/dist/cjs/i18n/index.js +4 -10
  24. package/dist/cjs/index.js +41 -2
  25. package/dist/cjs/panels/BasePanel.js +6 -5
  26. package/dist/cjs/panels/DatePanel.js +45 -21
  27. package/dist/cjs/{superdate → panels}/EventPanel.js +28 -12
  28. package/dist/cjs/panels/RangePanel.js +49 -19
  29. package/dist/cjs/utils/dateUtil.js +3 -5
  30. package/dist/esm/components/DateCell.js +6 -8
  31. package/dist/esm/components/DateHeader.js +28 -21
  32. package/dist/esm/components/DatePage.js +11 -13
  33. package/dist/esm/components/DecadePage.js +3 -3
  34. package/dist/esm/components/MonthPage.js +3 -3
  35. package/dist/esm/components/TimeSliders.js +38 -37
  36. package/dist/esm/components/YearPage.js +3 -3
  37. package/dist/esm/display/DateDisplay.js +26 -9
  38. package/dist/esm/display/DateDuration.js +155 -0
  39. package/dist/esm/hijri/DateConverter.js +152 -0
  40. package/dist/esm/hijri/FormatDate.js +113 -0
  41. package/dist/esm/hijri/HijriDate.js +528 -0
  42. package/dist/esm/hijri/StringDateParser.js +74 -0
  43. package/dist/esm/hijri/index.js +15 -1025
  44. package/dist/esm/hijri/initializer.js +113 -0
  45. package/dist/esm/hijri/locales.js +18 -0
  46. package/dist/esm/hijri/safe.js +14 -0
  47. package/dist/esm/i18n/ar/date.json.js +209 -0
  48. package/dist/esm/i18n/en/date.json.js +79 -0
  49. package/dist/esm/i18n/index.js +2 -8
  50. package/dist/esm/index.js +36 -1
  51. package/dist/esm/panels/BasePanel.js +6 -5
  52. package/dist/esm/panels/DatePanel.js +48 -24
  53. package/dist/esm/{superdate → panels}/EventPanel.js +29 -13
  54. package/dist/esm/panels/RangePanel.js +52 -22
  55. package/dist/esm/utils/dateUtil.js +4 -6
  56. package/dist/types/components/DateCell.d.ts +1 -1
  57. package/dist/types/components/DateHeader.d.ts +1 -1
  58. package/dist/types/components/DatePage.d.ts +1 -1
  59. package/dist/types/components/DecadePage.d.ts +1 -1
  60. package/dist/types/components/MonthPage.d.ts +1 -1
  61. package/dist/types/components/TimeSliders.d.ts +1 -1
  62. package/dist/types/components/YearPage.d.ts +1 -1
  63. package/dist/types/display/DateDisplay.d.ts +17 -4
  64. package/dist/types/display/DateDuration.d.ts +25 -0
  65. package/dist/types/hijri/DateConverter.d.ts +13 -0
  66. package/dist/types/hijri/FormatDate.d.ts +19 -0
  67. package/dist/types/hijri/HijriDate.d.ts +214 -0
  68. package/dist/types/hijri/StringDateParser.d.ts +11 -0
  69. package/dist/types/hijri/index.d.ts +2 -2
  70. package/dist/types/hijri/initializer.d.ts +129 -0
  71. package/dist/types/hijri/locales.d.ts +19 -0
  72. package/dist/types/hijri/safe.d.ts +3 -0
  73. package/dist/types/index.d.ts +32 -1
  74. package/dist/types/panels/BasePanel.d.ts +1 -1
  75. package/dist/types/panels/DatePanel.d.ts +22 -1
  76. package/dist/types/panels/EventPanel.d.ts +17 -0
  77. package/dist/types/panels/RangePanel.d.ts +19 -1
  78. package/dist/types/types/index.d.ts +8 -40
  79. package/package.json +14 -21
  80. package/src/components/DateCell.tsx +20 -75
  81. package/src/components/DateHeader.tsx +27 -78
  82. package/src/components/DatePage.tsx +11 -36
  83. package/src/components/DecadePage.tsx +2 -2
  84. package/src/components/MonthPage.tsx +2 -2
  85. package/src/components/TimeSliders.tsx +20 -60
  86. package/src/components/YearPage.tsx +2 -2
  87. package/src/display/DateDisplay.tsx +26 -38
  88. package/src/display/DateDuration.tsx +170 -0
  89. package/src/hijri/DateConverter.js +175 -0
  90. package/src/hijri/FormatDate.js +134 -0
  91. package/src/hijri/HijriDate.js +477 -0
  92. package/src/hijri/StringDateParser.js +68 -0
  93. package/src/hijri/index.js +16 -1535
  94. package/src/hijri/initializer.js +96 -0
  95. package/src/hijri/locales.js +109 -0
  96. package/src/hijri/safe.js +16 -0
  97. package/src/i18n/ar/date.json +203 -0
  98. package/src/i18n/en/date.json +73 -0
  99. package/src/i18n/index.ts +2 -5
  100. package/src/index.ts +29 -18
  101. package/src/panels/BasePanel.tsx +7 -10
  102. package/src/panels/DatePanel.tsx +41 -33
  103. package/src/{superdate → panels}/EventPanel.tsx +52 -53
  104. package/src/panels/RangePanel.tsx +54 -60
  105. package/src/types/index.ts +8 -43
  106. package/src/utils/dateUtil.ts +26 -82
  107. package/dist/cjs/components/Date.module.css +0 -1
  108. package/dist/cjs/i18n/ar.json.js +0 -25
  109. package/dist/cjs/i18n/en.json.js +0 -21
  110. package/dist/cjs/i18n/superdate/ar.json.js +0 -86
  111. package/dist/cjs/i18n/superdate/en.json.js +0 -93
  112. package/dist/cjs/superdate/QuickSelect.js +0 -134
  113. package/dist/cjs/superdate/RelativeInput.js +0 -79
  114. package/dist/cjs/superdate/RelativePanel.js +0 -91
  115. package/dist/cjs/superdate/SuperDate.module.css +0 -1
  116. package/dist/cjs/superdate/Superdate.js +0 -177
  117. package/dist/esm/components/Date.module.css +0 -1
  118. package/dist/esm/i18n/ar.json.js +0 -21
  119. package/dist/esm/i18n/en.json.js +0 -18
  120. package/dist/esm/i18n/superdate/ar.json.js +0 -79
  121. package/dist/esm/i18n/superdate/en.json.js +0 -85
  122. package/dist/esm/superdate/QuickSelect.js +0 -134
  123. package/dist/esm/superdate/RelativeInput.js +0 -79
  124. package/dist/esm/superdate/RelativePanel.js +0 -91
  125. package/dist/esm/superdate/SuperDate.module.css +0 -1
  126. package/dist/esm/superdate/Superdate.js +0 -176
  127. package/dist/types/superdate/EventPanel.d.ts +0 -4
  128. package/dist/types/superdate/QuickSelect.d.ts +0 -1
  129. package/dist/types/superdate/RelativeInput.d.ts +0 -1
  130. package/dist/types/superdate/RelativePanel.d.ts +0 -1
  131. package/dist/types/superdate/Superdate.d.ts +0 -17
  132. package/src/i18n/ar.json +0 -14
  133. package/src/i18n/en.json +0 -13
  134. package/src/i18n/superdate/ar.json +0 -70
  135. package/src/i18n/superdate/en.json +0 -75
  136. package/src/superdate/QuickSelect.tsx +0 -121
  137. package/src/superdate/RelativeInput.tsx +0 -64
  138. package/src/superdate/RelativePanel.tsx +0 -103
  139. package/src/superdate/Superdate.tsx +0 -198
@@ -0,0 +1,155 @@
1
+ 'use strict';
2
+
3
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
5
+ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
6
+ var core = require('@react-fabric/core');
7
+ var utilities = require('@react-fabric/utilities');
8
+ var dateFns = require('date-fns');
9
+ var react = require('react');
10
+ var reactI18next = require('react-i18next');
11
+ var dateUtil = require('../utils/dateUtil.js');
12
+ var jsxRuntime = require('react/jsx-runtime');
13
+
14
+ var _excluded = ["date", "children", "className", "format"];
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
+ /**
18
+ * DateDuration component to display the duration from a given date to now.
19
+ * It calculates the difference in years, months, weeks, days, hours, minutes, and seconds,
20
+ * and displays it in a human-readable format.
21
+ * It uses the current locale for translations.
22
+ *
23
+ * @example
24
+ * ```jsx
25
+ * <DateDuration date={new Date("2020-01-01")} />
26
+ * ```
27
+ */
28
+ function DateDuration(_ref) {
29
+ var date = _ref.date,
30
+ children = _ref.children,
31
+ className = _ref.className,
32
+ _ref$format = _ref.format,
33
+ format = _ref$format === void 0 ? "PPpp" : _ref$format,
34
+ props = _objectWithoutProperties(_ref, _excluded);
35
+ var _useTranslation = reactI18next.useTranslation("date"),
36
+ t = _useTranslation.t;
37
+ var _useState = react.useState(function () {
38
+ return {};
39
+ }),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ dateInterval = _useState2[0],
42
+ setDateInterval = _useState2[1];
43
+ react.useEffect(function () {
44
+ // eslint-disable-next-line @eslint-react/set-state-in-effect
45
+ setDateInterval(dateFns.intervalToDuration({
46
+ start: new Date(date),
47
+ end: new Date()
48
+ }));
49
+ // update interval every minute
50
+ var tmr = setInterval(function () {
51
+ setDateInterval(dateFns.intervalToDuration({
52
+ start: new Date(date),
53
+ end: new Date()
54
+ }));
55
+ }, 60 * 1000);
56
+ return function () {
57
+ return clearInterval(tmr);
58
+ };
59
+ }, [date]);
60
+ var label = react.useMemo(function () {
61
+ var before = dateFns.isBefore(dateUtil.DateUtil.parseDate(date), new Date());
62
+ var tkey = before ? "relative.before" : "relative.after";
63
+ var part = "now";
64
+ var count = 0;
65
+ if (dateInterval.years && dateInterval.years > 0) {
66
+ var _dateInterval$months;
67
+ part = "years";
68
+ count = dateInterval.years;
69
+ if (((_dateInterval$months = dateInterval.months) !== null && _dateInterval$months !== void 0 ? _dateInterval$months : 0) > 10) {
70
+ part = "yearsX";
71
+ count += 1;
72
+ }
73
+ } else if (dateInterval.months && dateInterval.months > 0) {
74
+ var _dateInterval$weeks;
75
+ part = "months";
76
+ count = dateInterval.months;
77
+ if (dateInterval.months > 10) {
78
+ part = "yearsX";
79
+ count = 1;
80
+ } else if (((_dateInterval$weeks = dateInterval.weeks) !== null && _dateInterval$weeks !== void 0 ? _dateInterval$weeks : 0) > 3) {
81
+ part = "monthsX";
82
+ count += 1;
83
+ }
84
+ } else if (dateInterval.weeks && dateInterval.weeks > 0) {
85
+ var _dateInterval$days;
86
+ part = "weeks";
87
+ count = dateInterval.weeks;
88
+ if (dateInterval.weeks > 3) {
89
+ part = "monthsX";
90
+ count = 1;
91
+ } else if (((_dateInterval$days = dateInterval.days) !== null && _dateInterval$days !== void 0 ? _dateInterval$days : 0) > 5) {
92
+ part = "weeksX";
93
+ count += 1;
94
+ }
95
+ } else if (dateInterval.days && dateInterval.days > 0) {
96
+ var _dateInterval$hours;
97
+ part = "days";
98
+ count = dateInterval.days;
99
+ if (dateInterval.days > 5) {
100
+ part = "weeksX";
101
+ count = 1;
102
+ } else if (((_dateInterval$hours = dateInterval.hours) !== null && _dateInterval$hours !== void 0 ? _dateInterval$hours : 0) > 20) {
103
+ part = "daysX";
104
+ count += 1;
105
+ }
106
+ } else if (dateInterval.hours && dateInterval.hours > 0) {
107
+ var _dateInterval$minutes;
108
+ part = "hours";
109
+ count = dateInterval.hours;
110
+ if (dateInterval.hours > 20) {
111
+ part = "daysX";
112
+ count = 1;
113
+ } else if (((_dateInterval$minutes = dateInterval.minutes) !== null && _dateInterval$minutes !== void 0 ? _dateInterval$minutes : 0) > 45) {
114
+ part = "hoursX";
115
+ count += 1;
116
+ }
117
+ } else if (dateInterval.minutes && dateInterval.minutes > 0) {
118
+ var _dateInterval$seconds;
119
+ part = "minutes";
120
+ count = dateInterval.minutes;
121
+ if (dateInterval.minutes > 45) {
122
+ part = "hoursX";
123
+ count = 1;
124
+ } else if (((_dateInterval$seconds = dateInterval.seconds) !== null && _dateInterval$seconds !== void 0 ? _dateInterval$seconds : 0) > 45) {
125
+ part = "minuteX";
126
+ count += 1;
127
+ }
128
+ } else if (dateInterval.seconds && dateInterval.seconds > 15) {
129
+ part = "seconds";
130
+ count = dateInterval.seconds;
131
+ if (dateInterval.seconds > 45) {
132
+ part = "minutesX";
133
+ count = 1;
134
+ }
135
+ }
136
+ return t("".concat(tkey, ".").concat(part), {
137
+ count: count
138
+ });
139
+ }, [date, dateInterval.days, dateInterval.hours, dateInterval.minutes, dateInterval.months, dateInterval.seconds, dateInterval.weeks, dateInterval.years, t]);
140
+ var dtLabel = /*#__PURE__*/jsxRuntime.jsx(core.Tooltip, {
141
+ content: utilities.Format.date(date, format),
142
+ children: /*#__PURE__*/jsxRuntime.jsx("span", _objectSpread(_objectSpread({
143
+ className: utilities.cn(className, !!children && "underline decoration-dotted cursor-pointer")
144
+ }, props), {}, {
145
+ children: label
146
+ }))
147
+ });
148
+ return children ? /*#__PURE__*/jsxRuntime.jsxs(core.Dropdown, {
149
+ showArrow: true,
150
+ closeOnClick: true,
151
+ children: [dtLabel, children]
152
+ }) : dtLabel;
153
+ }
154
+
155
+ exports.DateDuration = DateDuration;
@@ -0,0 +1,154 @@
1
+ 'use strict';
2
+
3
+ function intPart(floatNum) {
4
+ if (floatNum < -1e-7) {
5
+ return Math.ceil(floatNum - 0.0000001);
6
+ }
7
+ return Math.floor(floatNum + 0.0000001);
8
+ }
9
+ var delta = 1;
10
+ function GregToIsl(arg) {
11
+ var d = parseInt(arg.CDay.value);
12
+ var m = parseInt(arg.CMonth.value);
13
+ var y = parseInt(arg.CYear.value);
14
+ var jd,
15
+ l,
16
+ jd1,
17
+ n,
18
+ j,
19
+ delta = 1;
20
+ if (y > 1582 || y == 1582 && m > 10 || y == 1582 && m == 10 && d > 14) {
21
+ //added delta=1 on jd to comply isna rulling 2007
22
+ jd = intPart(1461 * (y + 4800 + intPart((m - 14) / 12)) / 4) + intPart(367 * (m - 2 - 12 * intPart((m - 14) / 12)) / 12) - intPart(3 * intPart((y + 4900 + intPart((m - 14) / 12)) / 100) / 4) + d - 32075 + delta;
23
+ } else {
24
+ //added +1 on jd to comply isna rulling
25
+ jd = 367 * y - intPart(7 * (y + 5001 + intPart((m - 9) / 7)) / 4) + intPart(275 * m / 9) + d + 1729777 + delta;
26
+ }
27
+
28
+ //added -1 on jd1 to comply isna rulling
29
+ jd1 = jd - delta;
30
+ l = jd - 1948440 + 10632;
31
+ n = intPart((l - 1) / 10631);
32
+ l = l - 10631 * n + 354;
33
+ j = intPart((10985 - l) / 5316) * intPart(50 * l / 17719) + intPart(l / 5670) * intPart(43 * l / 15238);
34
+ l = l - intPart((30 - j) / 15) * intPart(17719 * j / 50) - intPart(j / 16) * intPart(15238 * j / 43) + 29;
35
+ m = intPart(24 * l / 709);
36
+ d = l - intPart(709 * m / 24);
37
+ y = 30 * n + j - 30;
38
+ return {
39
+ d: d,
40
+ m: m,
41
+ y: y,
42
+ dateOfWeek: jd1 % 7,
43
+ dayName: weekDay(jd1 % 7)
44
+ };
45
+ }
46
+ function IslToGreg(arg) {
47
+ var d = parseInt(arg.HDay.value);
48
+ var m = parseInt(arg.HMonth.value);
49
+ var y = parseInt(arg.HYear.value);
50
+ //added - delta=1 on jd to comply isna rulling
51
+ var jd = intPart((11 * y + 3) / 30) + 354 * y + 30 * m - intPart((m - 1) / 2) + d + 1948440 - 385 - delta;
52
+ var l, n, i, j, k;
53
+ if (jd > 2299160) {
54
+ l = jd + 68569;
55
+ n = intPart(4 * l / 146097);
56
+ l = l - intPart((146097 * n + 3) / 4);
57
+ i = intPart(4000 * (l + 1) / 1461001);
58
+ l = l - intPart(1461 * i / 4) + 31;
59
+ j = intPart(80 * l / 2447);
60
+ d = l - intPart(2447 * j / 80);
61
+ l = intPart(j / 11);
62
+ m = j + 2 - 12 * l;
63
+ y = 100 * (n - 49) + i + l;
64
+ } else {
65
+ j = jd + 1402;
66
+ k = intPart((j - 1) / 1461);
67
+ l = j - 1461 * k;
68
+ n = intPart((l - 1) / 365) - intPart(l / 1461);
69
+ i = l - 365 * n + 30;
70
+ j = intPart(80 * i / 2447);
71
+ d = i - intPart(2447 * j / 80);
72
+ i = intPart(j / 11);
73
+ m = j + 2 - 12 * i;
74
+ y = 4 * k + n + i - 4716;
75
+ }
76
+
77
+ //arg.CDay.value=d
78
+ //arg.CMonth.value=m
79
+ //arg.CYear.value=y
80
+
81
+ return {
82
+ d: d,
83
+ m: m,
84
+ y: y,
85
+ dateOfWeek: jd % 7,
86
+ dayName: weekDay(jd % 7)
87
+ };
88
+ }
89
+ function weekDay(wdn) {
90
+ if (wdn == 0) {
91
+ return "Mon";
92
+ }
93
+ if (wdn == 1) {
94
+ return "Tue";
95
+ }
96
+ if (wdn == 2) {
97
+ return "Wed";
98
+ }
99
+ if (wdn == 3) {
100
+ return "Thu";
101
+ }
102
+ if (wdn == 4) {
103
+ return "Fri";
104
+ }
105
+ if (wdn == 5) {
106
+ return "Sat";
107
+ }
108
+ if (wdn == 6) {
109
+ return "Sun";
110
+ }
111
+ return "";
112
+ }
113
+ function GregToHijri(gregDate) {
114
+ var hijriDate = GregToIsl({
115
+ CDay: {
116
+ value: gregDate.getDate()
117
+ },
118
+ CYear: {
119
+ value: gregDate.getFullYear()
120
+ },
121
+ CMonth: {
122
+ value: gregDate.getMonth() + 1
123
+ }
124
+ });
125
+ return {
126
+ year: hijriDate.y,
127
+ month: hijriDate.m,
128
+ date: hijriDate.d,
129
+ hours: gregDate.getHours(),
130
+ minutes: gregDate.getMinutes(),
131
+ seconds: gregDate.getSeconds(),
132
+ milliseconds: gregDate.getMilliseconds(),
133
+ day: hijriDate.dateOfWeek,
134
+ dayName: hijriDate.dayName
135
+ };
136
+ }
137
+ function HijriToGreg(hijriDate) {
138
+ var gregDate = IslToGreg({
139
+ HDay: {
140
+ value: hijriDate._date || hijriDate.date
141
+ },
142
+ HYear: {
143
+ value: hijriDate._year || hijriDate.year
144
+ },
145
+ HMonth: {
146
+ value: hijriDate._month || hijriDate.month
147
+ }
148
+ });
149
+ return new Date(gregDate.y, gregDate.m - 1, gregDate.d, hijriDate.getHours(), hijriDate.getMinutes(), hijriDate.getSeconds(), hijriDate.getMilliseconds());
150
+ }
151
+
152
+ exports.GregToHijri = GregToHijri;
153
+ exports.HijriToGreg = HijriToGreg;
154
+ exports.weekDay = weekDay;
@@ -0,0 +1,116 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var HijriDate = require('./HijriDate.js');
6
+
7
+ var dateFormat = function () {
8
+ var token = /P{1,4}|p{1,4}|d{1,2}|e{3,6}|M{1,4}|yy(?:yy)?|([Hhms])\1?|[a]{1,4}|[LloSZ]|('at')|"[^"]*"|'[^']*'/g,
9
+ pad = function pad(val, len) {
10
+ val = String(val);
11
+ len = len || 2;
12
+ while (val.length < len) val = "0" + val;
13
+ return val;
14
+ };
15
+
16
+ // Regexes and supporting functions are cached through closure
17
+ return function (date, mask) {
18
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
19
+ utc: false
20
+ };
21
+ var locales = HijriDate.default.locales,
22
+ defaultLocale = HijriDate.default.defaultLocale;
23
+ options.locale = options.locale || defaultLocale;
24
+ if (!locales[options.locale]) {
25
+ throw new Error("Locale ".concat(options.locale, " is not supported yet .\n Please, try to extend \"HijriDate.locales\" :\n i.e: HijriDate.locales.").concat(options.locale, " = {dayNames:[..14 items..], monthNames:[..24 items..]}\n "));
26
+ }
27
+ // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
28
+ if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
29
+ mask = date;
30
+ date = undefined;
31
+ }
32
+ mask = String(masks[mask] || mask || masks["default"]);
33
+
34
+ // Allow setting the utc argument via the mask
35
+ if (mask.slice(0, 4) == "UTC:") {
36
+ mask = mask.slice(4);
37
+ options.utc = true;
38
+ }
39
+ var _ = options.utc ? "getUTC" : "get",
40
+ d = date[_ + "Date"](),
41
+ D = date[_ + "Day"](),
42
+ M = date[_ + "Month"](),
43
+ mIndex = date[_ + "MonthIndex"](),
44
+ y = date[_ + "FullYear"](),
45
+ H = date[_ + "Hours"](),
46
+ m = date[_ + "Minutes"](),
47
+ s = date[_ + "Seconds"](),
48
+ L = date[_ + "Milliseconds"](),
49
+ o = options.utc ? 0 : date.getTimezoneOffset(),
50
+ flags = {
51
+ d: d,
52
+ dd: pad(d),
53
+ ddd: locales[options.locale].dayNames[D === 7 ? 0 : D + 1],
54
+ dddd: locales[options.locale].dayNames[(D === 7 ? 0 : D + 1) + 7],
55
+ ee: locales[options.locale].dayNames[D],
56
+ eee: locales[options.locale].dayNames[D + 7],
57
+ eeee: locales[options.locale].dayNames[D + 14],
58
+ eeeeee: locales[options.locale].dayNames[D],
59
+ M: M,
60
+ MM: pad(M),
61
+ MMM: locales[options.locale].monthNames[mIndex],
62
+ MMMM: locales[options.locale].monthNames[mIndex + 12],
63
+ yy: String(y).slice(2),
64
+ yyyy: y,
65
+ h: H % 12 || 12,
66
+ hh: pad(H % 12 || 12),
67
+ H: H,
68
+ HH: pad(H),
69
+ m: m,
70
+ mm: pad(m),
71
+ s: s,
72
+ ss: pad(s),
73
+ l: pad(L, 3),
74
+ L: pad(L > 99 ? Math.round(L / 10) : L),
75
+ a: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
76
+ aa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
77
+ aaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
78
+ aaaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
79
+ aaaaa: H < 12 ? locales[options.locale].am : locales[options.locale].pm,
80
+ "'at'": locales[options.locale].separator,
81
+ t: H < 12 ? "a" : "p",
82
+ tt: H < 12 ? "am" : "pm",
83
+ T: H < 12 ? "A" : "P",
84
+ TT: H < 12 ? "AM" : "PM",
85
+ // Z: options.utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
86
+ o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
87
+ S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
88
+ };
89
+ return mask.replace(token, function ($0) {
90
+ if ($0 === "P") return "".concat(flags.d, "/").concat(flags.M, "/").concat(flags.yyyy, " ");
91
+ if ($0.startsWith("PP")) return "".concat(flags.MMM, " ").concat(flags.dd, ", ").concat(flags.yyyy, " ");
92
+ if ($0 === "p") return "".concat(flags.h, ":").concat(flags.m, " ").concat(flags.a);
93
+ if ($0.startsWith("pp")) return "".concat(flags.hh, ":").concat(flags.mm, ":").concat(flags.ss, " ").concat(flags.a);
94
+ return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
95
+ });
96
+ };
97
+ }();
98
+
99
+ // Some common format strings
100
+ var masks = {
101
+ "default": "ddd MMM dd yyyy HH:mm:ss",
102
+ shortDate: "M/d/yy",
103
+ mediumDate: "MMM d, yyyy",
104
+ longDate: "MMMM d, yyyy",
105
+ fullDate: "dddd, MMMM d, yyyy",
106
+ shortTime: "h:mm TT",
107
+ mediumTime: "h:mm:ss TT",
108
+ longTime: "h:mm:ss TT Z",
109
+ isoDate: "yyyy-MM-dd",
110
+ isoTime: "HH:mm:ss",
111
+ isoDateTime: "yyyy-MM-dd'T'HH:mm:ss",
112
+ isoUtcDateTime: "UTC:yyyy-MM-dd'T'HH:mm:ss'Z'"
113
+ };
114
+
115
+ exports.default = dateFormat;
116
+ exports.masks = masks;