@mui/x-date-pickers 6.18.7 → 6.19.2

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 (136) hide show
  1. package/AdapterDateFns/AdapterDateFns.d.ts +4 -24
  2. package/AdapterDateFns/AdapterDateFns.js +11 -272
  3. package/AdapterDateFnsBase/AdapterDateFnsBase.d.ts +65 -0
  4. package/AdapterDateFnsBase/AdapterDateFnsBase.js +308 -0
  5. package/AdapterDateFnsBase/index.d.ts +1 -0
  6. package/AdapterDateFnsBase/index.js +1 -0
  7. package/AdapterDateFnsBase/package.json +6 -0
  8. package/AdapterDateFnsJalali/AdapterDateFnsJalali.d.ts +1 -0
  9. package/AdapterDateFnsV3/AdapterDateFnsV3.d.ts +88 -0
  10. package/AdapterDateFnsV3/AdapterDateFnsV3.js +358 -0
  11. package/AdapterDateFnsV3/index.d.ts +1 -0
  12. package/AdapterDateFnsV3/index.js +1 -0
  13. package/AdapterDateFnsV3/package.json +6 -0
  14. package/AdapterLuxon/AdapterLuxon.js +0 -1
  15. package/CHANGELOG.md +106 -0
  16. package/DateCalendar/useCalendarState.js +0 -1
  17. package/DatePicker/DatePickerToolbar.d.ts +2 -2
  18. package/DatePicker/DatePickerToolbar.js +2 -7
  19. package/DateTimePicker/DateTimePickerTabs.js +6 -3
  20. package/DigitalClock/DigitalClock.js +1 -0
  21. package/DigitalClock/DigitalClock.types.d.ts +5 -0
  22. package/MonthCalendar/MonthCalendar.js +0 -1
  23. package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  24. package/MultiSectionDigitalClock/MultiSectionDigitalClock.types.d.ts +5 -0
  25. package/PickersLayout/pickersLayoutClasses.js +3 -2
  26. package/PickersLayout/usePickerLayout.js +2 -1
  27. package/TimeClock/Clock.js +0 -1
  28. package/TimeClock/ClockPointer.js +0 -1
  29. package/TimeClock/TimeClock.js +1 -0
  30. package/TimeClock/TimeClock.types.d.ts +5 -0
  31. package/YearCalendar/YearCalendar.js +0 -1
  32. package/hooks/useClearableField.d.ts +1 -1
  33. package/hooks/useClearableField.js +3 -3
  34. package/index.js +1 -1
  35. package/internals/hooks/useClockReferenceDate.js +0 -1
  36. package/internals/hooks/useField/useField.utils.js +0 -2
  37. package/internals/hooks/useViews.js +0 -1
  38. package/internals/models/helpers.d.ts +1 -0
  39. package/internals/models/props/tabs.d.ts +1 -0
  40. package/legacy/AdapterDateFns/AdapterDateFns.js +278 -529
  41. package/legacy/AdapterDateFnsBase/AdapterDateFnsBase.js +308 -0
  42. package/legacy/AdapterDateFnsBase/index.js +1 -0
  43. package/legacy/AdapterDateFnsV3/AdapterDateFnsV3.js +376 -0
  44. package/legacy/AdapterDateFnsV3/index.js +1 -0
  45. package/legacy/AdapterLuxon/AdapterLuxon.js +0 -1
  46. package/legacy/AdapterMomentHijri/AdapterMomentHijri.js +5 -6
  47. package/legacy/AdapterMomentJalaali/AdapterMomentJalaali.js +5 -6
  48. package/legacy/DateCalendar/PickersSlideTransition.js +8 -9
  49. package/legacy/DateCalendar/useCalendarState.js +0 -1
  50. package/legacy/DatePicker/DatePickerToolbar.js +2 -7
  51. package/legacy/DateTimePicker/DateTimePickerTabs.js +6 -3
  52. package/legacy/DigitalClock/DigitalClock.js +1 -0
  53. package/legacy/MonthCalendar/MonthCalendar.js +0 -1
  54. package/legacy/MonthCalendar/PickersMonth.js +4 -5
  55. package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  56. package/legacy/PickersDay/PickersDay.js +5 -6
  57. package/legacy/PickersLayout/PickersLayout.js +5 -6
  58. package/legacy/PickersLayout/pickersLayoutClasses.js +3 -2
  59. package/legacy/PickersLayout/usePickerLayout.js +2 -1
  60. package/legacy/TimeClock/Clock.js +0 -1
  61. package/legacy/TimeClock/ClockNumber.js +4 -5
  62. package/legacy/TimeClock/ClockPointer.js +0 -1
  63. package/legacy/TimeClock/TimeClock.js +1 -0
  64. package/legacy/TimePicker/TimePickerToolbar.js +1 -2
  65. package/legacy/YearCalendar/PickersYear.js +4 -5
  66. package/legacy/YearCalendar/YearCalendar.js +0 -1
  67. package/legacy/hooks/useClearableField.js +3 -3
  68. package/legacy/index.js +1 -1
  69. package/legacy/internals/components/PickersModalDialog.js +3 -4
  70. package/legacy/internals/hooks/useClockReferenceDate.js +0 -1
  71. package/legacy/internals/hooks/useField/useField.utils.js +0 -2
  72. package/legacy/internals/hooks/useViews.js +0 -1
  73. package/legacy/locales/index.js +1 -0
  74. package/legacy/locales/plPL.js +0 -1
  75. package/legacy/locales/svSE.js +0 -1
  76. package/legacy/locales/urPK.js +0 -1
  77. package/locales/index.d.ts +1 -0
  78. package/locales/index.js +1 -0
  79. package/locales/plPL.js +0 -1
  80. package/locales/svSE.js +0 -1
  81. package/locales/urPK.js +0 -1
  82. package/modern/AdapterDateFns/AdapterDateFns.js +11 -271
  83. package/modern/AdapterDateFnsBase/AdapterDateFnsBase.js +307 -0
  84. package/modern/AdapterDateFnsBase/index.js +1 -0
  85. package/modern/AdapterDateFnsV3/AdapterDateFnsV3.js +358 -0
  86. package/modern/AdapterDateFnsV3/index.js +1 -0
  87. package/modern/AdapterLuxon/AdapterLuxon.js +0 -1
  88. package/modern/DateCalendar/useCalendarState.js +0 -1
  89. package/modern/DatePicker/DatePickerToolbar.js +2 -7
  90. package/modern/DateTimePicker/DateTimePickerTabs.js +6 -3
  91. package/modern/DigitalClock/DigitalClock.js +1 -0
  92. package/modern/MonthCalendar/MonthCalendar.js +0 -1
  93. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  94. package/modern/PickersLayout/pickersLayoutClasses.js +3 -2
  95. package/modern/PickersLayout/usePickerLayout.js +2 -1
  96. package/modern/TimeClock/Clock.js +0 -1
  97. package/modern/TimeClock/ClockPointer.js +0 -1
  98. package/modern/TimeClock/TimeClock.js +1 -0
  99. package/modern/YearCalendar/YearCalendar.js +0 -1
  100. package/modern/hooks/useClearableField.js +3 -3
  101. package/modern/index.js +1 -1
  102. package/modern/internals/hooks/useClockReferenceDate.js +0 -1
  103. package/modern/internals/hooks/useField/useField.utils.js +0 -2
  104. package/modern/internals/hooks/useViews.js +0 -1
  105. package/modern/locales/index.js +1 -0
  106. package/modern/locales/plPL.js +0 -1
  107. package/modern/locales/svSE.js +0 -1
  108. package/modern/locales/urPK.js +0 -1
  109. package/node/AdapterDateFns/AdapterDateFns.js +11 -271
  110. package/node/AdapterDateFnsBase/AdapterDateFnsBase.js +315 -0
  111. package/node/AdapterDateFnsBase/index.js +12 -0
  112. package/node/AdapterDateFnsV3/AdapterDateFnsV3.js +366 -0
  113. package/node/AdapterDateFnsV3/index.js +12 -0
  114. package/node/AdapterLuxon/AdapterLuxon.js +0 -1
  115. package/node/DateCalendar/useCalendarState.js +0 -1
  116. package/node/DatePicker/DatePickerToolbar.js +0 -4
  117. package/node/DateTimePicker/DateTimePickerTabs.js +7 -4
  118. package/node/DigitalClock/DigitalClock.js +1 -0
  119. package/node/MonthCalendar/MonthCalendar.js +0 -1
  120. package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  121. package/node/PickersLayout/pickersLayoutClasses.js +5 -3
  122. package/node/PickersLayout/usePickerLayout.js +2 -1
  123. package/node/TimeClock/Clock.js +0 -1
  124. package/node/TimeClock/ClockPointer.js +0 -1
  125. package/node/TimeClock/TimeClock.js +1 -0
  126. package/node/YearCalendar/YearCalendar.js +0 -1
  127. package/node/hooks/useClearableField.js +3 -3
  128. package/node/index.js +1 -1
  129. package/node/internals/hooks/useClockReferenceDate.js +0 -1
  130. package/node/internals/hooks/useField/useField.utils.js +0 -2
  131. package/node/internals/hooks/useViews.js +0 -1
  132. package/node/locales/index.js +11 -0
  133. package/node/locales/plPL.js +0 -1
  134. package/node/locales/svSE.js +0 -1
  135. package/node/locales/urPK.js +0 -1
  136. package/package.json +2 -2
@@ -1,7 +1,11 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
2
  import _createClass from "@babel/runtime/helpers/esm/createClass";
4
3
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
+ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
6
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
7
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
5
9
  /* eslint-disable class-methods-use-this */
6
10
  import addDays from 'date-fns/addDays';
7
11
  import addSeconds from 'date-fns/addSeconds';
@@ -60,202 +64,7 @@ import isWithinInterval from 'date-fns/isWithinInterval';
60
64
  import defaultLocale from 'date-fns/locale/en-US';
61
65
  // @ts-ignore
62
66
  import longFormatters from 'date-fns/_lib/format/longFormatters';
63
- var formatTokenMap = {
64
- // Year
65
- y: {
66
- sectionType: 'year',
67
- contentType: 'digit',
68
- maxLength: 4
69
- },
70
- yy: 'year',
71
- yyy: {
72
- sectionType: 'year',
73
- contentType: 'digit',
74
- maxLength: 4
75
- },
76
- yyyy: 'year',
77
- // Month
78
- M: {
79
- sectionType: 'month',
80
- contentType: 'digit',
81
- maxLength: 2
82
- },
83
- MM: 'month',
84
- MMMM: {
85
- sectionType: 'month',
86
- contentType: 'letter'
87
- },
88
- MMM: {
89
- sectionType: 'month',
90
- contentType: 'letter'
91
- },
92
- L: {
93
- sectionType: 'month',
94
- contentType: 'digit',
95
- maxLength: 2
96
- },
97
- LL: 'month',
98
- LLL: {
99
- sectionType: 'month',
100
- contentType: 'letter'
101
- },
102
- LLLL: {
103
- sectionType: 'month',
104
- contentType: 'letter'
105
- },
106
- // Day of the month
107
- d: {
108
- sectionType: 'day',
109
- contentType: 'digit',
110
- maxLength: 2
111
- },
112
- dd: 'day',
113
- do: {
114
- sectionType: 'day',
115
- contentType: 'digit-with-letter'
116
- },
117
- // Day of the week
118
- E: {
119
- sectionType: 'weekDay',
120
- contentType: 'letter'
121
- },
122
- EE: {
123
- sectionType: 'weekDay',
124
- contentType: 'letter'
125
- },
126
- EEE: {
127
- sectionType: 'weekDay',
128
- contentType: 'letter'
129
- },
130
- EEEE: {
131
- sectionType: 'weekDay',
132
- contentType: 'letter'
133
- },
134
- EEEEE: {
135
- sectionType: 'weekDay',
136
- contentType: 'letter'
137
- },
138
- i: {
139
- sectionType: 'weekDay',
140
- contentType: 'digit',
141
- maxLength: 1
142
- },
143
- ii: 'weekDay',
144
- iii: {
145
- sectionType: 'weekDay',
146
- contentType: 'letter'
147
- },
148
- iiii: {
149
- sectionType: 'weekDay',
150
- contentType: 'letter'
151
- },
152
- e: {
153
- sectionType: 'weekDay',
154
- contentType: 'digit',
155
- maxLength: 1
156
- },
157
- ee: 'weekDay',
158
- eee: {
159
- sectionType: 'weekDay',
160
- contentType: 'letter'
161
- },
162
- eeee: {
163
- sectionType: 'weekDay',
164
- contentType: 'letter'
165
- },
166
- eeeee: {
167
- sectionType: 'weekDay',
168
- contentType: 'letter'
169
- },
170
- eeeeee: {
171
- sectionType: 'weekDay',
172
- contentType: 'letter'
173
- },
174
- c: {
175
- sectionType: 'weekDay',
176
- contentType: 'digit',
177
- maxLength: 1
178
- },
179
- cc: 'weekDay',
180
- ccc: {
181
- sectionType: 'weekDay',
182
- contentType: 'letter'
183
- },
184
- cccc: {
185
- sectionType: 'weekDay',
186
- contentType: 'letter'
187
- },
188
- ccccc: {
189
- sectionType: 'weekDay',
190
- contentType: 'letter'
191
- },
192
- cccccc: {
193
- sectionType: 'weekDay',
194
- contentType: 'letter'
195
- },
196
- // Meridiem
197
- a: 'meridiem',
198
- aa: 'meridiem',
199
- aaa: 'meridiem',
200
- // Hours
201
- H: {
202
- sectionType: 'hours',
203
- contentType: 'digit',
204
- maxLength: 2
205
- },
206
- HH: 'hours',
207
- h: {
208
- sectionType: 'hours',
209
- contentType: 'digit',
210
- maxLength: 2
211
- },
212
- hh: 'hours',
213
- // Minutes
214
- m: {
215
- sectionType: 'minutes',
216
- contentType: 'digit',
217
- maxLength: 2
218
- },
219
- mm: 'minutes',
220
- // Seconds
221
- s: {
222
- sectionType: 'seconds',
223
- contentType: 'digit',
224
- maxLength: 2
225
- },
226
- ss: 'seconds'
227
- };
228
- var defaultFormats = {
229
- year: 'yyyy',
230
- month: 'LLLL',
231
- monthShort: 'MMM',
232
- dayOfMonth: 'd',
233
- weekday: 'EEEE',
234
- weekdayShort: 'EEEEEE',
235
- hours24h: 'HH',
236
- hours12h: 'hh',
237
- meridiem: 'aa',
238
- minutes: 'mm',
239
- seconds: 'ss',
240
- fullDate: 'PP',
241
- fullDateWithWeekday: 'PPPP',
242
- keyboardDate: 'P',
243
- shortDate: 'MMM d',
244
- normalDate: 'd MMMM',
245
- normalDateWithWeekday: 'EEE, MMM d',
246
- monthAndYear: 'LLLL yyyy',
247
- monthAndDate: 'MMMM d',
248
- fullTime: 'p',
249
- fullTime12h: 'hh:mm aa',
250
- fullTime24h: 'HH:mm',
251
- fullDateTime: 'PP p',
252
- fullDateTime12h: 'PP hh:mm aa',
253
- fullDateTime24h: 'PP HH:mm',
254
- keyboardDateTime: 'P p',
255
- keyboardDateTime12h: 'P hh:mm aa',
256
- keyboardDateTime24h: 'P HH:mm'
257
- };
258
-
67
+ import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
259
68
  /**
260
69
  * Based on `@date-io/date-fns`
261
70
  *
@@ -281,339 +90,279 @@ var defaultFormats = {
281
90
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
282
91
  * SOFTWARE.
283
92
  */
284
- export var AdapterDateFns = /*#__PURE__*/_createClass(function AdapterDateFns() {
285
- var _this = this;
286
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
287
- _locale = _ref.locale,
288
- formats = _ref.formats;
289
- _classCallCheck(this, AdapterDateFns);
290
- this.isMUIAdapter = true;
291
- this.isTimezoneCompatible = false;
292
- this.lib = 'date-fns';
293
- this.locale = void 0;
294
- this.formats = void 0;
295
- this.formatTokenMap = formatTokenMap;
296
- this.escapedCharacters = {
297
- start: "'",
298
- end: "'"
299
- };
300
- this.date = function (value) {
301
- if (typeof value === 'undefined') {
302
- return new Date();
93
+ export var AdapterDateFns = /*#__PURE__*/function (_ref) {
94
+ _inherits(AdapterDateFns, _ref);
95
+ function AdapterDateFns() {
96
+ var _this;
97
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
98
+ locale = _ref2.locale,
99
+ formats = _ref2.formats;
100
+ _classCallCheck(this, AdapterDateFns);
101
+ if (typeof addDays !== 'function') {
102
+ throw new Error(['MUI: The `date-fns` package v3.x is not compatible with this adapter.', 'Please, install v2.x of the package or use the `AdapterDateFnsV3` instead.'].join('\n'));
303
103
  }
304
- if (value === null) {
305
- return null;
306
- }
307
- return new Date(value);
308
- };
309
- this.dateWithTimezone = function (value) {
310
- return _this.date(value);
311
- };
312
- this.getTimezone = function () {
313
- return 'default';
314
- };
315
- this.setTimezone = function (value) {
316
- return value;
317
- };
318
- this.toJsDate = function (value) {
319
- return value;
320
- };
321
- this.parseISO = function (isoString) {
322
- return parseISO(isoString);
323
- };
324
- this.toISO = function (value) {
325
- return formatISO(value, {
326
- format: 'extended'
327
- });
328
- };
329
- this.parse = function (value, format) {
330
- if (value === '') {
331
- return null;
332
- }
333
- return dateFnsParse(value, format, new Date(), {
334
- locale: _this.locale
335
- });
336
- };
337
- this.getCurrentLocaleCode = function () {
338
- var _this$locale;
339
- return ((_this$locale = _this.locale) == null ? void 0 : _this$locale.code) || 'en-US';
340
- };
341
- // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
342
- // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
343
- this.is12HourCycleInCurrentLocale = function () {
344
- if (_this.locale) {
345
- return /a/.test(_this.locale.formatLong.time());
346
- }
347
-
348
- // By default, date-fns is using en-US locale with am/pm enabled
349
- return true;
350
- };
351
- this.expandFormat = function (format) {
352
- var longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
353
-
354
- // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
355
- return format.match(longFormatRegexp).map(function (token) {
356
- var firstCharacter = token[0];
357
- if (firstCharacter === 'p' || firstCharacter === 'P') {
358
- var longFormatter = longFormatters[firstCharacter];
359
- var locale = _this.locale || defaultLocale;
360
- return longFormatter(token, locale.formatLong, {});
104
+ _this = _callSuper(this, AdapterDateFns, [{
105
+ locale: locale != null ? locale : defaultLocale,
106
+ formats: formats,
107
+ longFormatters: longFormatters
108
+ }]);
109
+ _this.parseISO = function (isoString) {
110
+ return parseISO(isoString);
111
+ };
112
+ _this.toISO = function (value) {
113
+ return formatISO(value, {
114
+ format: 'extended'
115
+ });
116
+ };
117
+ _this.parse = function (value, format) {
118
+ if (value === '') {
119
+ return null;
361
120
  }
362
- return token;
363
- }).join('');
364
- };
365
- this.getFormatHelperText = function (format) {
366
- return _this.expandFormat(format).replace(/(aaa|aa|a)/g, '(a|p)m').toLocaleLowerCase();
367
- };
368
- this.isNull = function (value) {
369
- return value === null;
370
- };
371
- this.isValid = function (value) {
372
- return isValid(_this.date(value));
373
- };
374
- this.format = function (value, formatKey) {
375
- return _this.formatByString(value, _this.formats[formatKey]);
376
- };
377
- this.formatByString = function (value, formatString) {
378
- return dateFnsFormat(value, formatString, {
379
- locale: _this.locale
380
- });
381
- };
382
- this.formatNumber = function (numberToFormat) {
383
- return numberToFormat;
384
- };
385
- this.getDiff = function (value, comparing, unit) {
386
- switch (unit) {
387
- case 'years':
388
- return differenceInYears(value, _this.date(comparing));
389
- case 'quarters':
390
- return differenceInQuarters(value, _this.date(comparing));
391
- case 'months':
392
- return differenceInMonths(value, _this.date(comparing));
393
- case 'weeks':
394
- return differenceInWeeks(value, _this.date(comparing));
395
- case 'days':
396
- return differenceInDays(value, _this.date(comparing));
397
- case 'hours':
398
- return differenceInHours(value, _this.date(comparing));
399
- case 'minutes':
400
- return differenceInMinutes(value, _this.date(comparing));
401
- case 'seconds':
402
- return differenceInSeconds(value, _this.date(comparing));
403
- default:
404
- {
405
- return differenceInMilliseconds(value, _this.date(comparing));
406
- }
407
- }
408
- };
409
- this.isEqual = function (value, comparing) {
410
- if (value === null && comparing === null) {
411
- return true;
412
- }
413
- return isEqual(value, comparing);
414
- };
415
- this.isSameYear = function (value, comparing) {
416
- return isSameYear(value, comparing);
417
- };
418
- this.isSameMonth = function (value, comparing) {
419
- return isSameMonth(value, comparing);
420
- };
421
- this.isSameDay = function (value, comparing) {
422
- return isSameDay(value, comparing);
423
- };
424
- this.isSameHour = function (value, comparing) {
425
- return isSameHour(value, comparing);
426
- };
427
- this.isAfter = function (value, comparing) {
428
- return isAfter(value, comparing);
429
- };
430
- this.isAfterYear = function (value, comparing) {
431
- return isAfter(value, endOfYear(comparing));
432
- };
433
- this.isAfterDay = function (value, comparing) {
434
- return isAfter(value, endOfDay(comparing));
435
- };
436
- this.isBefore = function (value, comparing) {
437
- return isBefore(value, comparing);
438
- };
439
- this.isBeforeYear = function (value, comparing) {
440
- return isBefore(value, startOfYear(comparing));
441
- };
442
- this.isBeforeDay = function (value, comparing) {
443
- return isBefore(value, startOfDay(comparing));
444
- };
445
- this.isWithinRange = function (value, _ref2) {
446
- var _ref3 = _slicedToArray(_ref2, 2),
447
- start = _ref3[0],
448
- end = _ref3[1];
449
- return isWithinInterval(value, {
450
- start: start,
451
- end: end
452
- });
453
- };
454
- this.startOfYear = function (value) {
455
- return startOfYear(value);
456
- };
457
- this.startOfMonth = function (value) {
458
- return startOfMonth(value);
459
- };
460
- this.startOfWeek = function (value) {
461
- return startOfWeek(value, {
462
- locale: _this.locale
463
- });
464
- };
465
- this.startOfDay = function (value) {
466
- return startOfDay(value);
467
- };
468
- this.endOfYear = function (value) {
469
- return endOfYear(value);
470
- };
471
- this.endOfMonth = function (value) {
472
- return endOfMonth(value);
473
- };
474
- this.endOfWeek = function (value) {
475
- return endOfWeek(value, {
476
- locale: _this.locale
477
- });
478
- };
479
- this.endOfDay = function (value) {
480
- return endOfDay(value);
481
- };
482
- this.addYears = function (value, amount) {
483
- return addYears(value, amount);
484
- };
485
- this.addMonths = function (value, amount) {
486
- return addMonths(value, amount);
487
- };
488
- this.addWeeks = function (value, amount) {
489
- return addWeeks(value, amount);
490
- };
491
- this.addDays = function (value, amount) {
492
- return addDays(value, amount);
493
- };
494
- this.addHours = function (value, amount) {
495
- return addHours(value, amount);
496
- };
497
- this.addMinutes = function (value, amount) {
498
- return addMinutes(value, amount);
499
- };
500
- this.addSeconds = function (value, amount) {
501
- return addSeconds(value, amount);
502
- };
503
- this.getYear = function (value) {
504
- return getYear(value);
505
- };
506
- this.getMonth = function (value) {
507
- return getMonth(value);
508
- };
509
- this.getDate = function (value) {
510
- return getDate(value);
511
- };
512
- this.getHours = function (value) {
513
- return getHours(value);
514
- };
515
- this.getMinutes = function (value) {
516
- return getMinutes(value);
517
- };
518
- this.getSeconds = function (value) {
519
- return getSeconds(value);
520
- };
521
- this.getMilliseconds = function (value) {
522
- return getMilliseconds(value);
523
- };
524
- this.setYear = function (value, year) {
525
- return setYear(value, year);
526
- };
527
- this.setMonth = function (value, month) {
528
- return setMonth(value, month);
529
- };
530
- this.setDate = function (value, date) {
531
- return setDate(value, date);
532
- };
533
- this.setHours = function (value, hours) {
534
- return setHours(value, hours);
535
- };
536
- this.setMinutes = function (value, minutes) {
537
- return setMinutes(value, minutes);
538
- };
539
- this.setSeconds = function (value, seconds) {
540
- return setSeconds(value, seconds);
541
- };
542
- this.setMilliseconds = function (value, milliseconds) {
543
- return setMilliseconds(value, milliseconds);
544
- };
545
- this.getDaysInMonth = function (value) {
546
- return getDaysInMonth(value);
547
- };
548
- this.getNextMonth = function (value) {
549
- return addMonths(value, 1);
550
- };
551
- this.getPreviousMonth = function (value) {
552
- return addMonths(value, -1);
553
- };
554
- this.getMonthArray = function (value) {
555
- var firstMonth = startOfYear(value);
556
- var monthArray = [firstMonth];
557
- while (monthArray.length < 12) {
558
- var prevMonth = monthArray[monthArray.length - 1];
559
- monthArray.push(_this.getNextMonth(prevMonth));
560
- }
561
- return monthArray;
562
- };
563
- this.mergeDateAndTime = function (dateParam, timeParam) {
564
- return _this.setSeconds(_this.setMinutes(_this.setHours(dateParam, _this.getHours(timeParam)), _this.getMinutes(timeParam)), _this.getSeconds(timeParam));
565
- };
566
- this.getWeekdays = function () {
567
- var now = new Date();
568
- return eachDayOfInterval({
569
- start: startOfWeek(now, {
121
+ return dateFnsParse(value, format, new Date(), {
570
122
  locale: _this.locale
571
- }),
572
- end: endOfWeek(now, {
123
+ });
124
+ };
125
+ _this.isValid = function (value) {
126
+ return isValid(_this.date(value));
127
+ };
128
+ _this.format = function (value, formatKey) {
129
+ return _this.formatByString(value, _this.formats[formatKey]);
130
+ };
131
+ _this.formatByString = function (value, formatString) {
132
+ return dateFnsFormat(value, formatString, {
573
133
  locale: _this.locale
574
- })
575
- }).map(function (day) {
576
- return _this.formatByString(day, 'EEEEEE');
577
- });
578
- };
579
- this.getWeekArray = function (value) {
580
- var start = startOfWeek(startOfMonth(value), {
581
- locale: _this.locale
582
- });
583
- var end = endOfWeek(endOfMonth(value), {
584
- locale: _this.locale
585
- });
586
- var count = 0;
587
- var current = start;
588
- var nestedWeeks = [];
589
- while (isBefore(current, end)) {
590
- var weekNumber = Math.floor(count / 7);
591
- nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
592
- nestedWeeks[weekNumber].push(current);
593
- current = addDays(current, 1);
594
- count += 1;
595
- }
596
- return nestedWeeks;
597
- };
598
- this.getWeekNumber = function (value) {
599
- return getWeek(value, {
600
- locale: _this.locale
601
- });
602
- };
603
- this.getYearRange = function (start, end) {
604
- var startDate = startOfYear(start);
605
- var endDate = endOfYear(end);
606
- var years = [];
607
- var current = startDate;
608
- while (isBefore(current, endDate)) {
609
- years.push(current);
610
- current = addYears(current, 1);
611
- }
612
- return years;
613
- };
614
- this.getMeridiemText = function (ampm) {
615
- return ampm === 'am' ? 'AM' : 'PM';
616
- };
617
- this.locale = _locale;
618
- this.formats = _extends({}, defaultFormats, formats);
619
- });
134
+ });
135
+ };
136
+ _this.getDiff = function (value, comparing, unit) {
137
+ switch (unit) {
138
+ case 'years':
139
+ return differenceInYears(value, _this.date(comparing));
140
+ case 'quarters':
141
+ return differenceInQuarters(value, _this.date(comparing));
142
+ case 'months':
143
+ return differenceInMonths(value, _this.date(comparing));
144
+ case 'weeks':
145
+ return differenceInWeeks(value, _this.date(comparing));
146
+ case 'days':
147
+ return differenceInDays(value, _this.date(comparing));
148
+ case 'hours':
149
+ return differenceInHours(value, _this.date(comparing));
150
+ case 'minutes':
151
+ return differenceInMinutes(value, _this.date(comparing));
152
+ case 'seconds':
153
+ return differenceInSeconds(value, _this.date(comparing));
154
+ default:
155
+ {
156
+ return differenceInMilliseconds(value, _this.date(comparing));
157
+ }
158
+ }
159
+ };
160
+ _this.isEqual = function (value, comparing) {
161
+ if (value === null && comparing === null) {
162
+ return true;
163
+ }
164
+ return isEqual(value, comparing);
165
+ };
166
+ _this.isSameYear = function (value, comparing) {
167
+ return isSameYear(value, comparing);
168
+ };
169
+ _this.isSameMonth = function (value, comparing) {
170
+ return isSameMonth(value, comparing);
171
+ };
172
+ _this.isSameDay = function (value, comparing) {
173
+ return isSameDay(value, comparing);
174
+ };
175
+ _this.isSameHour = function (value, comparing) {
176
+ return isSameHour(value, comparing);
177
+ };
178
+ _this.isAfter = function (value, comparing) {
179
+ return isAfter(value, comparing);
180
+ };
181
+ _this.isAfterYear = function (value, comparing) {
182
+ return isAfter(value, endOfYear(comparing));
183
+ };
184
+ _this.isAfterDay = function (value, comparing) {
185
+ return isAfter(value, endOfDay(comparing));
186
+ };
187
+ _this.isBefore = function (value, comparing) {
188
+ return isBefore(value, comparing);
189
+ };
190
+ _this.isBeforeYear = function (value, comparing) {
191
+ return isBefore(value, startOfYear(comparing));
192
+ };
193
+ _this.isBeforeDay = function (value, comparing) {
194
+ return isBefore(value, startOfDay(comparing));
195
+ };
196
+ _this.isWithinRange = function (value, _ref3) {
197
+ var _ref4 = _slicedToArray(_ref3, 2),
198
+ start = _ref4[0],
199
+ end = _ref4[1];
200
+ return isWithinInterval(value, {
201
+ start: start,
202
+ end: end
203
+ });
204
+ };
205
+ _this.startOfYear = function (value) {
206
+ return startOfYear(value);
207
+ };
208
+ _this.startOfMonth = function (value) {
209
+ return startOfMonth(value);
210
+ };
211
+ _this.startOfWeek = function (value) {
212
+ return startOfWeek(value, {
213
+ locale: _this.locale
214
+ });
215
+ };
216
+ _this.startOfDay = function (value) {
217
+ return startOfDay(value);
218
+ };
219
+ _this.endOfYear = function (value) {
220
+ return endOfYear(value);
221
+ };
222
+ _this.endOfMonth = function (value) {
223
+ return endOfMonth(value);
224
+ };
225
+ _this.endOfWeek = function (value) {
226
+ return endOfWeek(value, {
227
+ locale: _this.locale
228
+ });
229
+ };
230
+ _this.endOfDay = function (value) {
231
+ return endOfDay(value);
232
+ };
233
+ _this.addYears = function (value, amount) {
234
+ return addYears(value, amount);
235
+ };
236
+ _this.addMonths = function (value, amount) {
237
+ return addMonths(value, amount);
238
+ };
239
+ _this.addWeeks = function (value, amount) {
240
+ return addWeeks(value, amount);
241
+ };
242
+ _this.addDays = function (value, amount) {
243
+ return addDays(value, amount);
244
+ };
245
+ _this.addHours = function (value, amount) {
246
+ return addHours(value, amount);
247
+ };
248
+ _this.addMinutes = function (value, amount) {
249
+ return addMinutes(value, amount);
250
+ };
251
+ _this.addSeconds = function (value, amount) {
252
+ return addSeconds(value, amount);
253
+ };
254
+ _this.getYear = function (value) {
255
+ return getYear(value);
256
+ };
257
+ _this.getMonth = function (value) {
258
+ return getMonth(value);
259
+ };
260
+ _this.getDate = function (value) {
261
+ return getDate(value);
262
+ };
263
+ _this.getHours = function (value) {
264
+ return getHours(value);
265
+ };
266
+ _this.getMinutes = function (value) {
267
+ return getMinutes(value);
268
+ };
269
+ _this.getSeconds = function (value) {
270
+ return getSeconds(value);
271
+ };
272
+ _this.getMilliseconds = function (value) {
273
+ return getMilliseconds(value);
274
+ };
275
+ _this.setYear = function (value, year) {
276
+ return setYear(value, year);
277
+ };
278
+ _this.setMonth = function (value, month) {
279
+ return setMonth(value, month);
280
+ };
281
+ _this.setDate = function (value, date) {
282
+ return setDate(value, date);
283
+ };
284
+ _this.setHours = function (value, hours) {
285
+ return setHours(value, hours);
286
+ };
287
+ _this.setMinutes = function (value, minutes) {
288
+ return setMinutes(value, minutes);
289
+ };
290
+ _this.setSeconds = function (value, seconds) {
291
+ return setSeconds(value, seconds);
292
+ };
293
+ _this.setMilliseconds = function (value, milliseconds) {
294
+ return setMilliseconds(value, milliseconds);
295
+ };
296
+ _this.getDaysInMonth = function (value) {
297
+ return getDaysInMonth(value);
298
+ };
299
+ _this.getNextMonth = function (value) {
300
+ return addMonths(value, 1);
301
+ };
302
+ _this.getPreviousMonth = function (value) {
303
+ return addMonths(value, -1);
304
+ };
305
+ _this.getMonthArray = function (value) {
306
+ var firstMonth = startOfYear(value);
307
+ var monthArray = [firstMonth];
308
+ while (monthArray.length < 12) {
309
+ var prevMonth = monthArray[monthArray.length - 1];
310
+ monthArray.push(_this.getNextMonth(prevMonth));
311
+ }
312
+ return monthArray;
313
+ };
314
+ _this.mergeDateAndTime = function (dateParam, timeParam) {
315
+ return _this.setSeconds(_this.setMinutes(_this.setHours(dateParam, _this.getHours(timeParam)), _this.getMinutes(timeParam)), _this.getSeconds(timeParam));
316
+ };
317
+ _this.getWeekdays = function () {
318
+ var now = new Date();
319
+ return eachDayOfInterval({
320
+ start: startOfWeek(now, {
321
+ locale: _this.locale
322
+ }),
323
+ end: endOfWeek(now, {
324
+ locale: _this.locale
325
+ })
326
+ }).map(function (day) {
327
+ return _this.formatByString(day, 'EEEEEE');
328
+ });
329
+ };
330
+ _this.getWeekArray = function (value) {
331
+ var start = startOfWeek(startOfMonth(value), {
332
+ locale: _this.locale
333
+ });
334
+ var end = endOfWeek(endOfMonth(value), {
335
+ locale: _this.locale
336
+ });
337
+ var count = 0;
338
+ var current = start;
339
+ var nestedWeeks = [];
340
+ while (isBefore(current, end)) {
341
+ var weekNumber = Math.floor(count / 7);
342
+ nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
343
+ nestedWeeks[weekNumber].push(current);
344
+ current = addDays(current, 1);
345
+ count += 1;
346
+ }
347
+ return nestedWeeks;
348
+ };
349
+ _this.getWeekNumber = function (value) {
350
+ return getWeek(value, {
351
+ locale: _this.locale
352
+ });
353
+ };
354
+ _this.getYearRange = function (start, end) {
355
+ var startDate = startOfYear(start);
356
+ var endDate = endOfYear(end);
357
+ var years = [];
358
+ var current = startDate;
359
+ while (isBefore(current, endDate)) {
360
+ years.push(current);
361
+ current = addYears(current, 1);
362
+ }
363
+ return years;
364
+ };
365
+ return _this;
366
+ }
367
+ return _createClass(AdapterDateFns);
368
+ }(AdapterDateFnsBase);