Skip to content

Commit 280d046

Browse files
[Fix] Allow passing Date()-objects to viewDate()
The datetimepicker was forcing passed in dates to be parsed with the local timeformat (see `actualFormat` in `initFormatting()`), even when passing actual moment.js-objects or Javascript Date-objects. This change allows using `Date()`-objects when setting `viewDate`.
1 parent 8980e3f commit 280d046

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/js/bootstrap-datetimepicker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@
142142

143143
if (d === undefined || d === null) {
144144
returnMoment = moment(); //TODO should this use format? and locale?
145+
} else if (moment.isDate(d) || moment.isMoment(d)) {
146+
// If the date that is passed in is already a Date() or moment() object,
147+
// pass it directly to moment.
148+
returnMoment = moment(d);
145149
} else if (hasTimeZone()) { // There is a string to parse and a default time zone
146150
// parse with the tz function which takes a default time zone if it is not in the format string
147151
returnMoment = moment.tz(d, parseFormats, options.useStrict, options.timeZone);

0 commit comments

Comments
 (0)