@ncds/ui-admin 1.5.1 → 1.5.3

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.
@@ -46,7 +46,8 @@ export var DatePicker = /** @class */function () {
46
46
  var buttons = (_a = options.buttons, _a === void 0 ? [] : _a),
47
47
  size = options.size,
48
48
  autoComplete = (_b = options.autoComplete, _b === void 0 ? 'off' : _b),
49
- datePickerOptions = options.datePickerOptions;
49
+ datePickerOptions = options.datePickerOptions,
50
+ onValidationError = options.onValidationError;
50
51
  this.validateWrapper(wrapper);
51
52
  this.validationDependencies((buttons === null || buttons === void 0 ? void 0 : buttons.length) > 0);
52
53
  this.instanceId = DatePicker.instanceCounter++;
@@ -57,6 +58,7 @@ export var DatePicker = /** @class */function () {
57
58
  this.separator = '~';
58
59
  this.autoComplete = autoComplete;
59
60
  this.dateFormat = datePickerOptions[0].options.enableTime ? CONSTANTS.FORMATS.DATE_TIME : CONSTANTS.FORMATS.DATE;
61
+ this.onValidationError = onValidationError;
60
62
  this.init();
61
63
  }
62
64
  DatePicker.prototype.validateWrapper = function (wrapper) {
@@ -211,82 +213,409 @@ export var DatePicker = /** @class */function () {
211
213
  return '';
212
214
  });
213
215
  };
214
- this.flatpickrInstances = createFlatpickrInstances(datePickerOptions);
216
+ this.flatpickrInstances = createFlatpickrInstances(this.datePickerOptions);
215
217
  var dates = calcInitDates(datePickerOptions);
216
218
  this.setMultipleDates(dates);
217
219
  };
218
220
  DatePicker.prototype.initializeFlatpickr = function (input, options, wrapper) {
219
- var _a, _b;
221
+ var _this = this;
222
+ var _a;
220
223
  // flatpickr locale 설정 확인
221
- var locale = options.locale || 'ko';
222
- // flatpickr locale 로드되었는지 확인
223
- if (!((_a = flatpickr === null || flatpickr === void 0 ? void 0 : flatpickr.l10ns) === null || _a === void 0 ? void 0 : _a[locale])) {
224
- console.warn("flatpickr locale '".concat(locale, "' is not loaded. Available locales:"), Object.keys((flatpickr === null || flatpickr === void 0 ? void 0 : flatpickr.l10ns) || {}));
225
- if (locale === 'ko') flatpickr.l10ns.ko = Korean;else options.locale = undefined;
224
+ var locale = typeof options.locale === 'string' ? options.locale : 'ko';
225
+ this.setupFlatpickrLocale(locale, options);
226
+ var onInputHandler = this.createInputHandler();
227
+ var onHourInputHandler = this.createHourInputHandler();
228
+ var onMinuteInputHandler = this.createMinuteInputHandler();
229
+ var onMouseDown = this.createMouseDownHandler(wrapper);
230
+ // onBlur 핸들러 추가하여 입력 전 날짜 저장
231
+ var onBlurHandler = this.createBlurHandler();
232
+ document.addEventListener('mousedown', onMouseDown, true);
233
+ return flatpickr(input, __assign(__assign({}, options), {
234
+ allowInput: (_a = options.allowInput) !== null && _a !== void 0 ? _a : true,
235
+ appendTo: wrapper,
236
+ time_24hr: true,
237
+ defaultHour: options.defaultHour || 0,
238
+ defaultMinute: options.defaultMinute || 0,
239
+ locale: locale,
240
+ formatDate: function (date, format, locale) {
241
+ try {
242
+ // 유효한 날짜인지 확인
243
+ if (!date || !(date instanceof Date) || isNaN(date.getTime())) {
244
+ return '';
245
+ }
246
+ // moment로 포맷팅
247
+ var momentDate = moment(date);
248
+ if (!momentDate.isValid()) {
249
+ return '';
250
+ }
251
+ // format을 moment 형식으로 변환
252
+ var momentFormat = _this.convertFlatpickrFormatToMoment(format);
253
+ return momentDate.format(momentFormat);
254
+ } catch (error) {
255
+ // 오류 발생 시 빈 문자열 반환 (232-23 같은 잘못된 날짜 처리)
256
+ return '';
257
+ }
258
+ },
259
+ onChange: this.createOnChangeHandler(options),
260
+ onReady: this.createOnReadyHandler(onInputHandler, onHourInputHandler, onMinuteInputHandler, onBlurHandler),
261
+ onDestroy: this.createOnDestroyHandler(onInputHandler, onHourInputHandler, onMinuteInputHandler, onMouseDown, onBlurHandler)
262
+ }));
263
+ };
264
+ DatePicker.prototype.createBlurHandler = function () {
265
+ var _this = this;
266
+ return function (e) {
267
+ var target = e.target;
268
+ var inputIndex = _this.findFlatpickrInstanceIndexByInput(target);
269
+ if (inputIndex < 0) return;
270
+ // blur 시점에 현재 selectedDates를 저장 (입력 전 상태)
271
+ var instance = _this.flatpickrInstances[inputIndex];
272
+ if (instance && instance.selectedDates.length > 0) {
273
+ // 이전 날짜를 별도로 저장 (onChange에서 사용)
274
+ instance._previousDateBeforeInput = instance.selectedDates[0];
275
+ }
276
+ };
277
+ };
278
+ DatePicker.prototype.setupFlatpickrLocale = function (locale, options) {
279
+ var _a;
280
+ if ((_a = flatpickr === null || flatpickr === void 0 ? void 0 : flatpickr.l10ns) === null || _a === void 0 ? void 0 : _a[locale]) {
281
+ return;
282
+ }
283
+ console.warn("flatpickr locale '".concat(locale, "' is not loaded. Available locales:"), Object.keys((flatpickr === null || flatpickr === void 0 ? void 0 : flatpickr.l10ns) || {}));
284
+ if (locale === 'ko') {
285
+ flatpickr.l10ns.ko = Korean;
286
+ } else {
287
+ options.locale = undefined;
226
288
  }
227
- var onInputHandler = function (e) {
289
+ };
290
+ DatePicker.prototype.createInputHandler = function () {
291
+ var _this = this;
292
+ return function (e) {
228
293
  var target = e.target;
229
294
  var input = target.value;
295
+ var instance = _this.findFlatpickrInstanceByInput(target);
296
+ if (!instance) return;
297
+ // 빈 입력 처리
298
+ if (!input || input.trim() === '') {
299
+ _this.clearInputValue(target, instance);
300
+ return;
301
+ }
302
+ // 숫자나 하이픈이 없는 경우 처리
303
+ if (!/[0-9]/.test(input)) {
304
+ _this.restorePreviousDate(target, instance);
305
+ return;
306
+ }
230
307
  var formattedInput = formatDateInput(input);
231
- if (formattedInput === input) return;
232
- target.value = formattedInput;
308
+ // 포맷팅만 수행
309
+ if (formattedInput !== input) {
310
+ target.value = formattedInput;
311
+ return;
312
+ }
313
+ // 완전한 날짜 형식이지만 유효하지 않은 경우 처리
314
+ if (formattedInput && formattedInput.length >= 10) {
315
+ var parsedDate = moment(formattedInput);
316
+ if (!parsedDate.isValid()) {
317
+ _this.restorePreviousDate(target, instance);
318
+ }
319
+ }
233
320
  };
234
- var onHourInputHandler = function (e) {
321
+ };
322
+ DatePicker.prototype.findFlatpickrInstanceByInput = function (input) {
323
+ var index = this.findFlatpickrInstanceIndexByInput(input);
324
+ return index >= 0 ? this.flatpickrInstances[index] : null;
325
+ };
326
+ DatePicker.prototype.clearInputValue = function (target, instance) {
327
+ target.value = '';
328
+ instance.setDate('', false);
329
+ };
330
+ DatePicker.prototype.restorePreviousDate = function (target, instance) {
331
+ var hasPreviousDate = instance.selectedDates.length > 0;
332
+ if (!hasPreviousDate) {
333
+ this.clearInputValue(target, instance);
334
+ return;
335
+ }
336
+ var previousDate = instance.selectedDates[0];
337
+ var isValidDate = previousDate instanceof Date && !isNaN(previousDate.getTime());
338
+ if (isValidDate) {
339
+ target.value = moment(previousDate).format(this.dateFormat);
340
+ instance.setDate(previousDate, false);
341
+ } else {
342
+ this.clearInputValue(target, instance);
343
+ }
344
+ };
345
+ DatePicker.prototype.createHourInputHandler = function () {
346
+ return function (e) {
235
347
  var target = e.target;
236
348
  var input = target.value;
237
349
  var formattedInput = formatHourInput(input);
238
350
  if (formattedInput === input) return;
239
351
  target.value = formattedInput;
240
352
  };
241
- var onMinuteInputHandler = function (e) {
353
+ };
354
+ DatePicker.prototype.createMinuteInputHandler = function () {
355
+ return function (e) {
242
356
  var target = e.target;
243
357
  var input = target.value;
244
358
  var formattedInput = formatMinuteInput(input);
245
359
  if (formattedInput === input) return;
246
360
  target.value = formattedInput;
247
361
  };
248
- // 외부 클릭 시 시간 입력 강제 blur 처리
249
- var handleMouseDown = function (e) {
362
+ };
363
+ DatePicker.prototype.createMouseDownHandler = function (wrapper) {
364
+ return function (e) {
250
365
  var flatpickrCalendar = wrapper.querySelector('.flatpickr-calendar.open');
251
- if (flatpickrCalendar && !flatpickrCalendar.contains(e.target)) {
252
- var timeInputs = flatpickrCalendar.querySelectorAll('.flatpickr-time input');
253
- timeInputs.forEach(function (input) {
254
- if (document.activeElement === input) {
255
- input.blur();
366
+ if (!flatpickrCalendar) return;
367
+ if (flatpickrCalendar.contains(e.target)) return;
368
+ var timeInputs = flatpickrCalendar.querySelectorAll('.flatpickr-time input');
369
+ timeInputs.forEach(function (input) {
370
+ if (document.activeElement === input) {
371
+ input.blur();
372
+ }
373
+ });
374
+ };
375
+ };
376
+ DatePicker.prototype.createOnChangeHandler = function (options) {
377
+ var _this = this;
378
+ return function (selectedDates, dateStr, instance) {
379
+ try {
380
+ var inputIndex = _this.findFlatpickrInstanceIndexByInput(instance.input);
381
+ if (inputIndex < 0) return;
382
+ // blur 시 저장한 이전 날짜 사용
383
+ var previousDate = instance._previousDateBeforeInput;
384
+ // selectedDates가 비어있거나 첫 번째 날짜가 유효하지 않은 경우 처리
385
+ if (!selectedDates || selectedDates.length === 0 || !selectedDates[0] || !(selectedDates[0] instanceof Date) || !_this.isValidDate(selectedDates[0])) {
386
+ // 유효하지 않은 날짜는 이전 값으로 복원하거나 빈 값으로 처리
387
+ if (previousDate && _this.isValidDate(previousDate)) {
388
+ // 이전 값이 있으면 이전 값으로 복원
389
+ instance.selectedDates = [previousDate];
390
+ instance.setDate(previousDate, false);
391
+ } else {
392
+ // 이전 값이 없으면 빈 값으로 처리
393
+ instance.selectedDates = [];
394
+ instance.setDate('', false);
256
395
  }
257
- });
396
+ // 원본 onChange는 호출하지 않음
397
+ return;
398
+ }
399
+ // 유효한 날짜인 경우에만 원본 onChange 호출
400
+ _this.invokeOriginalOnChange(options.onChange, selectedDates, dateStr, instance);
401
+ var selectedDate = selectedDates[0];
402
+ // minDate/maxDate 검증
403
+ _this.validateAndRestoreIfNeeded(selectedDate, instance, inputIndex, previousDate);
404
+ // 검증 후 현재 날짜를 이전 날짜로 업데이트
405
+ if (_this.isValidDate(selectedDate)) {
406
+ instance._previousDateBeforeInput = selectedDate;
407
+ _this.flatpickrInstances[inputIndex].selectedDates = [selectedDate];
408
+ }
409
+ } catch (error) {
410
+ // 오류 발생 시 이전 값으로 복원
411
+ var previousDate = instance._previousDateBeforeInput;
412
+ if (previousDate && _this.isValidDate(previousDate)) {
413
+ instance.selectedDates = [previousDate];
414
+ } else {
415
+ instance.selectedDates = [];
416
+ }
417
+ _this.restoreDateToInstance(instance, previousDate);
258
418
  }
259
419
  };
260
- document.addEventListener('mousedown', handleMouseDown, true);
261
- return flatpickr(input, __assign(__assign({}, options), {
262
- allowInput: (_b = options.allowInput) !== null && _b !== void 0 ? _b : true,
263
- appendTo: wrapper,
264
- time_24hr: true,
265
- defaultHour: options.defaultHour || 0,
266
- defaultMinute: options.defaultMinute || 0,
267
- locale: locale,
268
- onReady: function (selectedDates, dateStr, instance) {
269
- var _a;
270
- var input = instance.input;
271
- if (!input) return;
272
- var timeInputWrapper = (_a = input.parentElement) === null || _a === void 0 ? void 0 : _a.querySelector('.flatpickr-time');
273
- input.addEventListener('input', onInputHandler);
274
- if (!timeInputWrapper) return;
420
+ };
421
+ DatePicker.prototype.invokeOriginalOnChange = function (onChange, selectedDates, dateStr, instance) {
422
+ if (!onChange) return;
423
+ if (Array.isArray(onChange)) {
424
+ onChange.forEach(function (hook) {
425
+ void hook(selectedDates, dateStr, instance);
426
+ });
427
+ } else {
428
+ onChange(selectedDates, dateStr, instance);
429
+ }
430
+ };
431
+ DatePicker.prototype.isValidDate = function (date) {
432
+ return date instanceof Date && !isNaN(date.getTime());
433
+ };
434
+ DatePicker.prototype.validateAndRestoreIfNeeded = function (selectedDate, instance, inputIndex, previousDate) {
435
+ try {
436
+ var isValid = this.validateDate(selectedDate, inputIndex, previousDate);
437
+ if (!isValid) {
438
+ this.restoreDateToInstance(instance, previousDate);
439
+ } else {
440
+ // 유효한 경우에만 업데이트
441
+ instance._previousDateBeforeInput = selectedDate;
442
+ this.flatpickrInstances[inputIndex].selectedDates = [selectedDate];
443
+ }
444
+ } catch (error) {
445
+ // 오류 발생 시 이전 값으로 복원
446
+ this.restoreDateToInstance(instance, previousDate);
447
+ }
448
+ };
449
+ DatePicker.prototype.findFlatpickrInstanceIndexByInput = function (input) {
450
+ return this.flatpickrInstances.findIndex(function (inst) {
451
+ return inst.input === input;
452
+ });
453
+ };
454
+ DatePicker.prototype.restoreDateToInstance = function (instance, previousDate) {
455
+ try {
456
+ // setDate 호출 전에 날짜 유효성 확인
457
+ if (previousDate && this.isValidDate(previousDate)) {
458
+ // selectedDates 배열을 정리하여 formatting.js에서 오류가 발생하지 않도록 함
459
+ instance.selectedDates = [previousDate];
460
+ instance.setDate(previousDate, false);
461
+ } else {
462
+ // 빈 값으로 설정할 때도 selectedDates를 정리
463
+ instance.selectedDates = [];
464
+ instance.setDate('', false);
465
+ }
466
+ } catch (error) {
467
+ // setDate에서 오류 발생 시 selectedDates를 빈 배열로 설정
468
+ try {
469
+ instance.selectedDates = [];
470
+ instance.setDate('', false);
471
+ } catch (_a) {
472
+ // 최종 실패 시 무시
473
+ }
474
+ }
475
+ };
476
+ DatePicker.prototype.createOnReadyHandler = function (onInputHandler, onHourInputHandler, onMinuteInputHandler, onBlurHandler) {
477
+ return function (selectedDates, dateStr, instance) {
478
+ var _a;
479
+ var input = instance.input;
480
+ if (!input) return;
481
+ input.addEventListener('input', onInputHandler);
482
+ input.addEventListener('blur', onBlurHandler);
483
+ var timeInputWrapper = (_a = input.parentElement) === null || _a === void 0 ? void 0 : _a.querySelector('.flatpickr-time');
484
+ if (!timeInputWrapper) return;
485
+ var hourInput = timeInputWrapper.querySelector('.flatpickr-hour');
486
+ var minuteInput = timeInputWrapper.querySelector('.flatpickr-minute');
487
+ if (!hourInput || !minuteInput) return;
488
+ hourInput.addEventListener('input', onHourInputHandler);
489
+ minuteInput.addEventListener('input', onMinuteInputHandler);
490
+ };
491
+ };
492
+ DatePicker.prototype.createOnDestroyHandler = function (onInputHandler, onHourInputHandler, onMinuteInputHandler, onMouseDown, onBlurHandler) {
493
+ return function (selectedDates, dateStr, instance) {
494
+ var _a;
495
+ var input = instance.input;
496
+ if (!input) return;
497
+ input.removeEventListener('input', onInputHandler);
498
+ input.removeEventListener('blur', onBlurHandler);
499
+ // hourInput과 minuteInput에서 이벤트 리스너 제거 (input이 아님)
500
+ var timeInputWrapper = (_a = input.parentElement) === null || _a === void 0 ? void 0 : _a.querySelector('.flatpickr-time');
501
+ if (timeInputWrapper) {
275
502
  var hourInput = timeInputWrapper.querySelector('.flatpickr-hour');
276
503
  var minuteInput = timeInputWrapper.querySelector('.flatpickr-minute');
277
- if (!hourInput || !minuteInput) return;
278
- hourInput.addEventListener('input', onHourInputHandler);
279
- minuteInput.addEventListener('input', onMinuteInputHandler);
280
- },
281
- onDestroy: function (selectedDates, dateStr, instance) {
282
- var input = instance.input;
283
- if (!input) return;
284
- input.removeEventListener('input', onInputHandler);
285
- input.removeEventListener('input', onHourInputHandler);
286
- input.removeEventListener('input', onMinuteInputHandler);
287
- document.removeEventListener('mousedown', handleMouseDown, true);
504
+ if (hourInput) {
505
+ hourInput.removeEventListener('input', onHourInputHandler);
506
+ }
507
+ if (minuteInput) {
508
+ minuteInput.removeEventListener('input', onMinuteInputHandler);
509
+ }
288
510
  }
289
- }));
511
+ document.removeEventListener('mousedown', onMouseDown, true);
512
+ };
513
+ };
514
+ DatePicker.prototype.convertDateOption = function (dateOption) {
515
+ if (!dateOption) return undefined;
516
+ if (typeof dateOption === 'string' || dateOption instanceof Date) {
517
+ return dateOption;
518
+ }
519
+ if (typeof dateOption === 'number') {
520
+ return new Date(dateOption);
521
+ }
522
+ if (Array.isArray(dateOption) && dateOption.length > 0) {
523
+ return dateOption[0] instanceof Date ? dateOption[0] : new Date(dateOption[0]);
524
+ }
525
+ return undefined;
526
+ };
527
+ DatePicker.prototype.validateDate = function (date, index, previousDate) {
528
+ var _a;
529
+ var option = this.datePickerOptions[index];
530
+ if (!option) return true;
531
+ var minDate = (_a = option.options, _a.minDate),
532
+ maxDate = _a.maxDate;
533
+ if (!minDate && !maxDate) return true;
534
+ var inputDate = moment(date);
535
+ if (!inputDate.isValid()) return true;
536
+ var violations = this.checkDateViolations(inputDate, minDate, maxDate);
537
+ if (violations.length === 0) return true;
538
+ if (this.onValidationError) {
539
+ var error = {
540
+ index: index,
541
+ date: date,
542
+ minDate: this.convertDateOption(minDate),
543
+ maxDate: this.convertDateOption(maxDate),
544
+ violations: violations,
545
+ previousDate: previousDate
546
+ };
547
+ this.onValidationError(error);
548
+ }
549
+ return false;
550
+ };
551
+ DatePicker.prototype.checkDateViolations = function (inputDate, minDate, maxDate) {
552
+ var violations = [];
553
+ if (minDate) {
554
+ var min = moment(minDate);
555
+ if (min.isValid() && inputDate.isBefore(min, 'day')) {
556
+ violations.push('minDate');
557
+ }
558
+ }
559
+ if (maxDate) {
560
+ var max = moment(maxDate);
561
+ if (max.isValid() && inputDate.isAfter(max, 'day')) {
562
+ violations.push('maxDate');
563
+ }
564
+ }
565
+ return violations;
566
+ };
567
+ DatePicker.prototype.setDate = function (dates) {
568
+ var _this = this;
569
+ var startDate = dates[0],
570
+ endDate = dates[1];
571
+ var datesToSet = this.datePickerOptions.map(function (option, index) {
572
+ var date = index === 0 ? startDate : endDate;
573
+ return _this.formatDateForOption(date, option, index);
574
+ });
575
+ var period = this.calculatePeriod(datesToSet);
576
+ this.updateButtonsByPeriod(period);
577
+ this.setMultipleDates(datesToSet);
578
+ };
579
+ DatePicker.prototype.formatDateForOption = function (date, option, index) {
580
+ var _a, _b;
581
+ if (!date || date === '0000-00-00') return '';
582
+ var hasTime = (_a = option.options) === null || _a === void 0 ? void 0 : _a.enableTime;
583
+ var flatpickrFormat = ((_b = option.options) === null || _b === void 0 ? void 0 : _b.dateFormat) || (hasTime ? 'Y-m-d H:i' : 'Y-m-d');
584
+ var momentFormat = this.convertFlatpickrFormatToMoment(flatpickrFormat);
585
+ var momentDate = this.parseDateWithMultipleFormats(date, hasTime, momentFormat);
586
+ if (!momentDate || !momentDate.isValid()) return '';
587
+ var isValid = this.validateDate(momentDate.toDate(), index);
588
+ if (!isValid) return '';
589
+ return this.formatMomentDate(momentDate, date, hasTime, index, momentFormat);
590
+ };
591
+ DatePicker.prototype.parseDateWithMultipleFormats = function (date, hasTime, momentFormat) {
592
+ // hasTime이 true인 경우 (시간 포함 여부와 무관하게 moment로 파싱)
593
+ if (hasTime) {
594
+ var momentDate_1 = moment(date);
595
+ return momentDate_1.isValid() ? momentDate_1 : null;
596
+ }
597
+ // hasTime이 false인 경우 - 여러 형식으로 시도
598
+ var momentDate = moment(date);
599
+ if (momentDate.isValid()) {
600
+ return momentDate;
601
+ }
602
+ momentDate = moment(date, momentFormat, true);
603
+ if (momentDate.isValid()) {
604
+ return momentDate;
605
+ }
606
+ momentDate = moment(date, [momentFormat, 'YYYY-MM-DD', 'YYYY/MM/DD', 'MM/DD/YYYY'], true);
607
+ return momentDate.isValid() ? momentDate : null;
608
+ };
609
+ DatePicker.prototype.formatMomentDate = function (momentDate, originalDate, hasTime, index, momentFormat) {
610
+ // hasTime이 true이고 원본 날짜에 시간이 없는 경우
611
+ if (hasTime && !originalDate.includes(':')) {
612
+ return index === 0 ? momentDate.startOf('day').format(momentFormat) : momentDate.endOf('day').format(momentFormat);
613
+ }
614
+ return momentDate.format(momentFormat);
615
+ };
616
+ DatePicker.prototype.calculatePeriod = function (datesToSet) {
617
+ if (!datesToSet[0] || !datesToSet[1]) return null;
618
+ return moment(datesToSet[1]).diff(moment(datesToSet[0]), 'days');
290
619
  };
291
620
  DatePicker.prototype.updateDateWithButton = function (e) {
292
621
  var _this = this;
@@ -338,48 +667,6 @@ export var DatePicker = /** @class */function () {
338
667
  return hasTime ? moment().endOf('day').format(_this.dateFormat) : moment().format(_this.dateFormat);
339
668
  });
340
669
  };
341
- DatePicker.prototype.setDate = function (dates) {
342
- var _this = this;
343
- var startDate = dates[0],
344
- endDate = dates[1];
345
- var datesToSet = this.datePickerOptions.map(function (option, index) {
346
- var _a, _b;
347
- var date = index === 0 ? startDate : endDate;
348
- if (!date || date === '0000-00-00') return '';
349
- var hasTime = (_a = option.options) === null || _a === void 0 ? void 0 : _a.enableTime;
350
- var flatpickrFormat = ((_b = option.options) === null || _b === void 0 ? void 0 : _b.dateFormat) || (hasTime ? 'Y-m-d H:i' : 'Y-m-d');
351
- // dateFormat이 설정되어 있지 않을 때만 hasTime에 따라 기본값 설정
352
- // dateFormat이 설정되어 있으면 그 형식을 그대로 사용 (enableTime과 무관하게)
353
- var momentFormat = _this.convertFlatpickrFormatToMoment(flatpickrFormat);
354
- var momentDate;
355
- if (hasTime && !date.includes(':')) {
356
- // 시간이 없는 날짜 형식으로 파싱
357
- momentDate = moment(date);
358
- if (!momentDate.isValid()) return '';
359
- return index === 0 ? momentDate.startOf('day').format(momentFormat) : momentDate.endOf('day').format(momentFormat);
360
- }
361
- if (hasTime && date.includes(':')) {
362
- momentDate = moment(date);
363
- if (!momentDate.isValid()) return '';
364
- return momentDate.format(momentFormat);
365
- }
366
- // 시간이 없는 경우 (hasTime이 false이거나 date에 시간이 없는 경우)
367
- momentDate = moment(date);
368
- if (!momentDate.isValid()) {
369
- momentDate = moment(date, momentFormat, true);
370
- }
371
- // 둘 다 실패하면 다른 일반적인 형식들로 시도
372
- if (!momentDate.isValid()) {
373
- momentDate = moment(date, [momentFormat, 'YYYY-MM-DD', 'YYYY/MM/DD', 'MM/DD/YYYY'], true);
374
- }
375
- if (!momentDate.isValid()) return '';
376
- // dateFormat 형식으로 포맷팅하여 반환 (flatpickr가 표시하는 형식과 일치)
377
- return momentDate.format(momentFormat);
378
- });
379
- var period = datesToSet[0] && datesToSet[1] ? moment(datesToSet[1]).diff(moment(datesToSet[0]), 'days') : null;
380
- this.updateButtonsByPeriod(period);
381
- this.setMultipleDates(datesToSet);
382
- };
383
670
  // flatpickr 형식을 moment 형식으로 변환하는 헬퍼 메서드
384
671
  DatePicker.prototype.convertFlatpickrFormatToMoment = function (flatpickrFormat) {
385
672
  var map = {