Skip to content

Commit 989d8c8

Browse files
committed
feat(DateRangePicker): allow to format the selected date into a string according to a custom format when the selection type is set to week, month, and year
1 parent 8d3f1a9 commit 989d8c8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

js/src/date-range-picker.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import EventHandler from './dom/event-handler.js'
1313
import Manipulator from './dom/manipulator.js'
1414
import SelectorEngine from './dom/selector-engine.js'
1515
import { defineJQueryPlugin, isRTL } from './util/index.js'
16-
import { getLocalDateFromString } from './util/calendar.js'
16+
import { convertToDateObject, getLocalDateFromString } from './util/calendar.js'
1717

1818
/**
1919
* Constants
@@ -806,17 +806,19 @@ class DateRangePicker extends BaseComponent {
806806
}
807807

808808
_formatDate(date) {
809+
if (this._config.inputDateFormat) {
810+
return this._config.inputDateFormat(
811+
date instanceof Date ? new Date(date) : convertToDateObject(date, this._config.selectionType)
812+
)
813+
}
814+
809815
if (this._config.selectionType !== 'day') {
810816
return date
811817
}
812818

813819
const _date = new Date(date)
814820

815-
return this._config.inputDateFormat ?
816-
this._config.inputDateFormat(_date) :
817-
(this._config.timepicker ?
818-
_date.toLocaleString(this._config.locale) :
819-
_date.toLocaleDateString(this._config.locale))
821+
return this._config.timepicker ? _date.toLocaleString(this._config.locale) : _date.toLocaleDateString(this._config.locale)
820822
}
821823

822824
_getButtonClasses(classes) {

0 commit comments

Comments
 (0)