Skip to content

Commit f0cb465

Browse files
authored
Merge pull request Eonasdan#1853 from peergradeio/PR/set-date-with-moment
Allow passing a Date()-object to `viewDate()`
2 parents 108d27c + 280d046 commit f0cb465

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)