import moment from 'moment';
const Datetimepicker = ((element, options) => {
    class Datetimepicker {
        constructor(element, options){
            this.element = $(element);
            this.options = $.extend(true, {}, DEFAULTS, options);
            this.unset = true;
            this.component = false;
            this.widget = false;
            this.minViewModeNumber = 0;
            this.keyState = {};
            if (this.element.is('input')) {
                this.input = this.element;
            } else {
                this.input = this.element.find(this.options.datepickerInput);
                if (this.input.length === 0) {
                    this.input = this.element.find('input');
                } else if (!this.input.is('input')) {
                    throw new Error('CSS class "' + this.options.datepickerInput + '" cannot be applied to non input element');
                }
            }
            if (this.element.hasClass('input-group')) {
                if (this.element.find('.datepickerbutton').length === 0) {
                    this.component = this.element.find('.input-group-addon');
                } else {
                    this.component = this.element.find('.datepickerbutton');
                }
            }
            if (!this.options.inline && !this.input.is('input')) {
                throw new Error('Could not initialize DateTimePicker without an input element');
            }
            this._date = this._getMoment();
            this._viewDate = this._date.clone();
            $.extend(true, this.options, this._dataToOptions());
            this.setOptions(this.options);
            this._initFormatting();
            this._attachDatePickerElementEvents();
            if (this.input.prop('disabled')) {
                this.disable();
            }
            if (this.input.is('input') && this.input.val().trim().length !== 0) {
                this._setValue(this._parseInputDate(this.input.val().trim()), 'first');
            }
            else if (this.options.defaultDate && this.input.attr('placeholder') === undefined) {
                this._setValue(this.options.defaultDate, 'first');
            }
            if (this.options.inline) {
                this._show();
            }
        }
		
        
        
        _hasTimeZone () {
            return moment.tz !== undefined && this.options.timeZone !== undefined && this.options.timeZone !== null && this.options.timeZone !== '';
        }
        _getMoment (d) {
            var returnMoment;
            if (d === undefined || d === null) {
                returnMoment = moment(); 
            } else if (this._hasTimeZone()) { 
                returnMoment = moment.tz(d, this.parseFormats, this.options.useStrict, this.options.timeZone);
            } else {
                returnMoment = moment(d, this.parseFormats, this.options.useStrict);
            }
            if (this._hasTimeZone()) {
                returnMoment.tz(this.options.timeZone);
            }
            return returnMoment;
        }
        _isEnabled (granularity) {
            if (typeof granularity !== 'string' || granularity.length > 1) {
                throw new TypeError('isEnabled expects a single character string parameter');
            }
            switch (granularity) {
                case 'y':
                    return this.actualFormat.indexOf('Y') !== -1;
                case 'M':
                    return this.actualFormat.indexOf('M') !== -1;
                case 'd':
                    return this.actualFormat.toLowerCase().indexOf('d') !== -1;
                case 'h':
                case 'H':
                    return this.actualFormat.toLowerCase().indexOf('h') !== -1;
                case 'm':
                    return this.actualFormat.indexOf('m') !== -1;
                case 's':
                    return this.actualFormat.indexOf('s') !== -1;
                default:
                    return false;
            }
        }
        _hasTime () {
            return (this._isEnabled('h') || this._isEnabled('m') || this._isEnabled('s'));
        }
        _hasDate () {
            return (this._isEnabled('y') || this._isEnabled('M') || this._isEnabled('d'));
        }
        _getDatePickerTemplate () {
            var headTemplate = $('<thead>')
                    .append($('<tr>')
                        .append($('<th>').addClass('prev').attr('data-action', 'previous')
                            .append($('<span>').addClass(this.options.icons.previous))
                            )
                        .append($('<th>').addClass('picker-switch').attr('data-action', 'pickerSwitch').attr('colspan', (this.options.calendarWeeks ? '6' : '5')))
                        .append($('<th>').addClass('next').attr('data-action', 'next')
                            .append($('<span>').addClass(this.options.icons.next))
                            )
                        ),
                contTemplate = $('<tbody>')
                    .append($('<tr>')
                        .append($('<td>').attr('colspan', (this.options.calendarWeeks ? '8' : '7')))
                        );
            return [
                $('<div>').addClass('datepicker-days')
                    .append($('<table>').addClass('table-condensed')
                        .append(headTemplate)
                        .append($('<tbody>'))
                        ),
                $('<div>').addClass('datepicker-months')
                    .append($('<table>').addClass('table-condensed')
                        .append(headTemplate.clone())
                        .append(contTemplate.clone())
                        ),
                $('<div>').addClass('datepicker-years')
                    .append($('<table>').addClass('table-condensed')
                        .append(headTemplate.clone())
                        .append(contTemplate.clone())
                        ),
                $('<div>').addClass('datepicker-decades')
                    .append($('<table>').addClass('table-condensed')
                        .append(headTemplate.clone())
                        .append(contTemplate.clone())
                        )
            ];
        }
        _getTimePickerMainTemplate () {
            var topRow = $('<tr>'),
                middleRow = $('<tr>'),
                bottomRow = $('<tr>');
            if (this._isEnabled('h')) {
                topRow.append($('<td>')
                    .append($('<a>').attr({ href: '#', tabindex: '-1', 'title': this.options.tooltips.incrementHour }).addClass('btn').attr('data-action', 'incrementHours').append($('<span>').addClass(this.options.icons.up))));
                middleRow.append($('<td>')
                    .append($('<span>').addClass('timepicker-hour').attr({ 'data-time-component': 'hours', 'title': this.options.tooltips.pickHour }).attr('data-action', 'showHours')));
                bottomRow.append($('<td>')
                    .append($('<a>').attr({ href: '#', tabindex: '-1', 'title': this.options.tooltips.decrementHour }).addClass('btn').attr('data-action', 'decrementHours').append($('<span>').addClass(this.options.icons.down))));
            }
            if (this._isEnabled('m')) {
                if (this._isEnabled('h')) {
                    topRow.append($('<td>').addClass('separator'));
                    middleRow.append($('<td>').addClass('separator').html(':'));
                    bottomRow.append($('<td>').addClass('separator'));
                }
                topRow.append($('<td>')
                    .append($('<a>').attr({ href: '#', tabindex: '-1', 'title': this.options.tooltips.incrementMinute }).addClass('btn').attr('data-action', 'incrementMinutes')
                        .append($('<span>').addClass(this.options.icons.up))));
                middleRow.append($('<td>')
                    .append($('<span>').addClass('timepicker-minute').attr({ 'data-time-component': 'minutes', 'title': this.options.tooltips.pickMinute }).attr('data-action', 'showMinutes')));
                bottomRow.append($('<td>')
                    .append($('<a>').attr({ href: '#', tabindex: '-1', 'title': this.options.tooltips.decrementMinute }).addClass('btn').attr('data-action', 'decrementMinutes')
                        .append($('<span>').addClass(this.options.icons.down))));
            }
            if (this._isEnabled('s')) {
                if (this._isEnabled('m')) {
                    topRow.append($('<td>').addClass('separator'));
                    middleRow.append($('<td>').addClass('separator').html(':'));
                    bottomRow.append($('<td>').addClass('separator'));
                }
                topRow.append($('<td>')
                    .append($('<a>').attr({ href: '#', tabindex: '-1', 'title': this.options.tooltips.incrementSecond }).addClass('btn').attr('data-action', 'incrementSeconds')
                        .append($('<span>').addClass(this.options.icons.up))));
                middleRow.append($('<td>')
                    .append($('<span>').addClass('timepicker-second').attr({ 'data-time-component': 'seconds', 'title': this.options.tooltips.pickSecond }).attr('data-action', 'showSeconds')));
                bottomRow.append($('<td>')
                    .append($('<a>').attr({ href: '#', tabindex: '-1', 'title': this.options.tooltips.decrementSecond }).addClass('btn').attr('data-action', 'decrementSeconds')
                        .append($('<span>').addClass(this.options.icons.down))));
            }
            if (!this.use24Hours) {
                topRow.append($('<td>').addClass('separator'));
                middleRow.append($('<td>')
                    .append($('<button>').addClass('btn btn-primary').attr({ 'data-action': 'togglePeriod', tabindex: '-1', 'title': this.options.tooltips.togglePeriod })));
                bottomRow.append($('<td>').addClass('separator'));
            }
            return $('<div>').addClass('timepicker-picker')
                .append($('<table>').addClass('table-condensed')
                    .append([topRow, middleRow, bottomRow]));
        }
        _getTimePickerTemplate () {
            var hoursView = $('<div>').addClass('timepicker-hours')
                    .append($('<table>').addClass('table-condensed')),
                minutesView = $('<div>').addClass('timepicker-minutes')
                    .append($('<table>').addClass('table-condensed')),
                secondsView = $('<div>').addClass('timepicker-seconds')
                    .append($('<table>').addClass('table-condensed')),
                ret = [this._getTimePickerMainTemplate()];
            if (this._isEnabled('h')) {
                ret.push(hoursView);
            }
            if (this._isEnabled('m')) {
                ret.push(minutesView);
            }
            if (this._isEnabled('s')) {
                ret.push(secondsView);
            }
            return ret;
        }
        _getToolbar () {
            var row = [];
            if (this.options.showTodayButton) {
                row.push($('<td>').append($('<a>').attr({ 'data-action': 'today', 'title': this.options.tooltips.today }).append($('<span>').addClass(this.options.icons.today))));
            }
            if (!this.options.sideBySide && this._hasDate() && this._hasTime()) {
                row.push($('<td>').append($('<a>').attr({ 'data-action': 'togglePicker', 'title': this.options.tooltips.selectTime }).append($('<span>').addClass(this.options.icons.time))));
            }
            if (this.options.showClear) {
                row.push($('<td>').append($('<a>').attr({ 'data-action': 'clear', 'title': this.options.tooltips.clear }).append($('<span>').addClass(this.options.icons.clear))));
            }
            if (this.options.showClose) {
                row.push($('<td>').append($('<a>').attr({ 'data-action': 'close', 'title': this.options.tooltips.close }).append($('<span>').addClass(this.options.icons.close))));
            }
            return $('<table>').addClass('table-condensed').append($('<tbody>').append($('<tr>').append(row)));
        }
        _getTemplate () {
            var template = $('<div>').addClass('cd-datetimepicker-widget dropdown-menu'),
                dateView = $('<div>').addClass('datepicker').append(this._getDatePickerTemplate()),
                timeView = $('<div>').addClass('timepicker').append(this._getTimePickerTemplate()),
                content = $('<ul>').addClass('list-unstyled'),
                toolbar = $('<li>').addClass('picker-switch' + (this.options.collapse ? ' accordion-toggle' : '')).append(this._getToolbar());
            if (this.options.inline) {
                template.removeClass('dropdown-menu');
            }
            if (this.use24Hours) {
                template.addClass('usetwentyfour');
            }
            if (this._isEnabled('s') && !this.use24Hours) {
                template.addClass('wider');
            }
            if (this.options.sideBySide && this._hasDate() && this._hasTime()) {
                template.addClass('timepicker-sbs');
                if (this.options.toolbarPlacement === 'top') {
                    template.append(toolbar);
                }
                template.append(
                    $('<div>').addClass('cd-row')
                        .append(dateView.addClass('cd-md-6'))
                        .append(timeView.addClass('cd-md-6'))
                );
                if (this.options.toolbarPlacement === 'bottom') {
                    template.append(toolbar);
                }
                return template;
            }
            if (this.options.toolbarPlacement === 'top') {
                content.append(toolbar);
            }
            if (this._hasDate()) {
                content.append($('<li>').addClass((this.options.collapse && this._hasTime() ? 'collapse in' : '')).append(dateView));
            }
            if (this.options.toolbarPlacement === 'default') {
                content.append(toolbar);
            }
            if (this._hasTime()) {
                content.append($('<li>').addClass((this.options.collapse && this._hasDate() ? 'collapse' : '')).append(timeView));
            }
            if (this.options.toolbarPlacement === 'bottom') {
                content.append(toolbar);
            }
            return template.append(content);
        }
        _dataToOptions () {
            var eData,
                dataOptions = {};
            if (this.element.is('input') || this.options.inline) {
                eData = this.element.data();
            } else {
                eData = this.element.find('input').data();
            }
            if (eData.dateOptions && eData.dateOptions instanceof Object) {
                dataOptions = $.extend(true, dataOptions, eData.dateOptions);
            }
            $.each(this.options, function (key) {
                var attributeName = 'date' + key.charAt(0).toUpperCase() + key.slice(1);
                if (eData[attributeName] !== undefined) {
                    dataOptions[key] = eData[attributeName];
                }
            });
            return dataOptions;
        }
        _place = () => {
            var position = (this.component || this.element).position(),
                offset = (this.component || this.element).offset(),
                vertical = this.options.widgetPositioning.vertical,
                horizontal = this.options.widgetPositioning.horizontal,
                parent;
            if (this.options.widgetParent) {
                parent = this.options.widgetParent.append(this.widget);
                position = this.options.widgetParent.get(0).tagName == 'BODY' ? offset : position;
            } else if (this.element.is('input')) {
                parent = this.element.after(this.widget).parent();
            } else if (this.options.inline) {
                parent = this.element.append(this.widget);
                return;
            } else {
                parent = this.element;
                this.element.children().first().after(this.widget);
            }
            if (vertical === 'auto') {
                if (offset.top + this.widget.height() * 1.5 >= $(window).height() + $(window).scrollTop() &&
                    this.widget.height() + this.element.outerHeight() < offset.top) {
                    vertical = 'top';
                } else {
                    vertical = 'bottom';
                }
            }
            if (horizontal === 'auto') {
                if (parent.width() < offset.left + this.widget.outerWidth() / 2 &&
                    offset.left + this.widget.outerWidth() > $(window).width()) {
                    horizontal = 'right';
                } else {
                    horizontal = 'left';
                }
            }
            if (vertical === 'top') {
                this.widget.addClass('top').removeClass('bottom');
            } else {
                this.widget.addClass('bottom').removeClass('top');
            }
            if (horizontal === 'right') {
                this.widget.addClass('pull-right');
            } else {
                this.widget.removeClass('pull-right');
            }
            if (parent.css('position') !== 'relative') {
                parent = parent.parents().filter(function () {
                    return $(this).css('position') === 'relative';
                }).first();
            }
            if (parent.length === 0) {
                throw new Error('datetimepicker component should be placed within a relative positioned container');
            }
            this.widget.css({
                top: vertical === 'top' ? 'auto' : position.top + this.element.outerHeight(),
                bottom: vertical === 'top' ? parent.outerHeight() - (parent === this.element ? 0 : position.top) : 'auto',
                left: horizontal === 'left' ? (parent === this.element ? 0 : position.left) : 'auto',
                right: horizontal === 'left' ? 'auto' : parent.outerWidth() - this.element.outerWidth() - (parent === this.element ? 0 : position.left)
            });
        }
        _notifyEvent (e) {
            if (e.type === 'dp.change' && ((e.date && e.date.isSame(e.oldDate)) || (!e.date && !e.oldDate))) {
                return;
            }
            this.element.trigger(e);
        }
        _viewUpdate (e) {
            if (e === 'y') {
                e = 'YYYY';
            }
            this._notifyEvent({
                type: 'dp.update',
                change: e,
                viewDate: this._viewDate.clone()
            });
        }
        _showMode (dir) {
            if (!this.widget) {
                return;
            }
            if (dir) {
                this.currentViewMode = Math.max(this.minViewModeNumber, Math.min(3, this.currentViewMode + dir));
            }
            this.widget.find('.datepicker > div').hide().filter('.datepicker-' + datePickerModes[this.currentViewMode].clsName).show();
        }
        _fillDow () {
            var row = $('<tr>'),
                currentDate = this._viewDate.clone().startOf('w').startOf('d');
            
            if (this.options.calendarWeeks === true) {
                row.append($('<th>').addClass('cw').text('\u5468'));
            }
            while (currentDate.isBefore(this._viewDate.clone().endOf('w'))) {
                row.append($('<th>').addClass('dow').text(currentDate.format('dd')));
                currentDate.add(1, 'd');
            }
            
            this.widget.find('.datepicker-days thead').append(row);
        }
        _isInDisabledDates (testDate) {
            return this.options.disabledDates[testDate.format('YYYY-MM-DD')] === true;
        }
        _isInEnabledDates (testDate) {
            return this.options.enabledDates[testDate.format('YYYY-MM-DD')] === true;
        }
        _isInDisabledHours (testDate) {
            return this.options.disabledHours[testDate.format('H')] === true;
        }
        _isInEnabledHours (testDate) {
            return this.options.enabledHours[testDate.format('H')] === true;
        }
        _isValid (targetMoment, granularity) {
            if (!targetMoment.isValid()) {
                return false;
            }
            if (this.options.disabledDates && granularity === 'd' && this._isInDisabledDates(targetMoment)) {
                return false;
            }
            if (this.options.enabledDates && granularity === 'd' && !this._isInEnabledDates(targetMoment)) {
                return false;
            }
            if (this.options.minDate && targetMoment.isBefore(this.options.minDate, granularity)) {
                return false;
            }
            if (this.options.maxDate && targetMoment.isAfter(this.options.maxDate, granularity)) {
                return false;
            }
            if (this.options.daysOfWeekDisabled && granularity === 'd' && this.options.daysOfWeekDisabled.indexOf(targetMoment.day()) !== -1) {
                return false;
            }
            if (this.options.disabledHours && (granularity === 'h' || granularity === 'm' || granularity === 's') && this._isInDisabledHours(targetMoment)) {
                return false;
            }
            if (this.options.enabledHours && (granularity === 'h' || granularity === 'm' || granularity === 's') && !this._isInEnabledHours(targetMoment)) {
                return false;
            }
            if (this.options.disabledTimeIntervals && (granularity === 'h' || granularity === 'm' || granularity === 's')) {
                var found = false;
                $.each(this.options.disabledTimeIntervals, function () {
                    if (targetMoment.isBetween(this[0], this[1])) {
                        found = true;
                        return false;
                    }
                });
                if (found) {
                    return false;
                }
            }
            return true;
        }
        _fillMonths () {
            var spans = [],
                monthsShort = this._viewDate.clone().startOf('y').startOf('d');
            while (monthsShort.isSame(this._viewDate, 'y')) {
                spans.push($('<span>').attr('data-action', 'selectMonth').addClass('month').text(monthsShort.format('MMM')));
                monthsShort.add(1, 'M');
            }
            this.widget.find('.datepicker-months td').empty().append(spans);
        }
        _updateMonths () {
            var self = this, monthsView = this.widget.find('.datepicker-months'),
                monthsViewHeader = monthsView.find('th'),
                months = monthsView.find('tbody').find('span');
            monthsViewHeader.eq(0).find('span').attr('title', this.options.tooltips.prevYear);
            monthsViewHeader.eq(1).attr('title', this.options.tooltips.selectYear);
            monthsViewHeader.eq(2).find('span').attr('title', this.options.tooltips.nextYear);
            monthsView.find('.disabled').removeClass('disabled');
            if (!this._isValid(this._viewDate.clone().subtract(1, 'y'), 'y')) {
                monthsViewHeader.eq(0).addClass('disabled');
            }
            monthsViewHeader.eq(1).text(this._viewDate.year());
            if (!this._isValid(this._viewDate.clone().add(1, 'y'), 'y')) {
                monthsViewHeader.eq(2).addClass('disabled');
            }
            months.removeClass('active');
            if (this._date.isSame(this._viewDate, 'y') && !this.unset) {
                months.eq(this._date.month()).addClass('active');
            }
            months.each(function (index) {
                if (!self._isValid(self._viewDate.clone().month(index), 'M')) {
                    $(this).addClass('disabled');
                }
            });
        }
        _updateYears () {
            var yearsView = this.widget.find('.datepicker-years'),
                yearsViewHeader = yearsView.find('th'),
                startYear = this._viewDate.clone().subtract(5, 'y'),
                endYear = this._viewDate.clone().add(6, 'y'),
                html = '';
            yearsViewHeader.eq(0).find('span').attr('title', this.options.tooltips.prevDecade);
            yearsViewHeader.eq(1).attr('title', this.options.tooltips.selectDecade);
            yearsViewHeader.eq(2).find('span').attr('title', this.options.tooltips.nextDecade);
            yearsView.find('.disabled').removeClass('disabled');
            if (this.options.minDate && this.options.minDate.isAfter(startYear, 'y')) {
                yearsViewHeader.eq(0).addClass('disabled');
            }
            yearsViewHeader.eq(1).text(startYear.year() + '-' + endYear.year());
            if (this.options.maxDate && this.options.maxDate.isBefore(endYear, 'y')) {
                yearsViewHeader.eq(2).addClass('disabled');
            }
            while (!startYear.isAfter(endYear, 'y')) {
                html += '<span data-action="selectYear" class="year' + (startYear.isSame(this._date, 'y') && !this.unset ? ' active' : '') + (!this._isValid(startYear, 'y') ? ' disabled' : '') + '">' + startYear.year() + '</span>';
                startYear.add(1, 'y');
            }
            yearsView.find('td').html(html);
        }
        _updateDecades () {
            var decadesView = this.widget.find('.datepicker-decades'),
                decadesViewHeader = decadesView.find('th'),
                startDecade = moment({ y: this._viewDate.year() - (this._viewDate.year() % 100) - 1 }),
                endDecade = startDecade.clone().add(100, 'y'),
                startedAt = startDecade.clone(),
                minDateDecade = false,
                maxDateDecade = false,
                endDecadeYear,
                html = '';
            decadesViewHeader.eq(0).find('span').attr('title', this.options.tooltips.prevCentury);
            decadesViewHeader.eq(2).find('span').attr('title', this.options.tooltips.nextCentury);
            decadesView.find('.disabled').removeClass('disabled');
            if (startDecade.isSame(moment({ y: 1900 })) || (this.options.minDate && this.options.minDate.isAfter(startDecade, 'y'))) {
                decadesViewHeader.eq(0).addClass('disabled');
            }
            decadesViewHeader.eq(1).text(startDecade.year() + '-' + endDecade.year());
            if (startDecade.isSame(moment({ y: 2000 })) || (this.options.maxDate && this.options.maxDate.isBefore(endDecade, 'y'))) {
                decadesViewHeader.eq(2).addClass('disabled');
            }
            while (!startDecade.isAfter(endDecade, 'y')) {
                endDecadeYear = startDecade.year() + 12;
                minDateDecade = this.options.minDate && this.options.minDate.isAfter(startDecade, 'y') && this.options.minDate.year() <= endDecadeYear;
                maxDateDecade = this.options.maxDate && this.options.maxDate.isAfter(startDecade, 'y') && this.options.maxDate.year() <= endDecadeYear;
                html += '<span data-action="selectDecade" class="decade' + (this._date.isAfter(startDecade) && this._date.year() <= endDecadeYear ? ' active' : '') +
                    (!this._isValid(startDecade, 'y') && !minDateDecade && !maxDateDecade ? ' disabled' : '') + '" data-selection="' + (startDecade.year() + 6) + '">' + (startDecade.year() + 1) + ' - ' + (startDecade.year() + 12) + '</span>';
                startDecade.add(12, 'y');
            }
            html += '<span></span><span></span><span></span>'; 
            decadesView.find('td').html(html);
            decadesViewHeader.eq(1).text((startedAt.year() + 1) + '-' + (startDecade.year()));
        }
        _fillDate () {
            var daysView = this.widget.find('.datepicker-days'),
                daysViewHeader = daysView.find('th'),
                currentDate,
                html = [],
                row,
                clsName,
                i;
            if (!this._hasDate()) {
                return;
            }
            daysViewHeader.eq(0).find('span').attr('title', this.options.tooltips.prevMonth);
            daysViewHeader.eq(1).attr('title', this.options.tooltips.selectMonth);
            daysViewHeader.eq(2).find('span').attr('title', this.options.tooltips.nextMonth);
            daysView.find('.disabled').removeClass('disabled');
            daysViewHeader.eq(1).text(this._viewDate.format(this.options.dayViewHeaderFormat));
            if (!this._isValid(this._viewDate.clone().subtract(1, 'M'), 'M')) {
                daysViewHeader.eq(0).addClass('disabled');
            }
            if (!this._isValid(this._viewDate.clone().add(1, 'M'), 'M')) {
                daysViewHeader.eq(2).addClass('disabled');
            }
            currentDate = this._viewDate.clone().startOf('M').startOf('w').startOf('d');
            for (i = 0; i < 42; i++) { 
                if (currentDate.weekday() === 0) {
                    row = $('<tr>');
                    if (this.options.calendarWeeks) {
                        row.append('<td class="cw">' + currentDate.week() + '</td>');
                    }
                    html.push(row);
                }
                clsName = '';
                if (currentDate.isBefore(this._viewDate, 'M')) {
                    clsName += ' old';
                }
                if (currentDate.isAfter(this._viewDate, 'M')) {
                    clsName += ' new';
                }
                if (currentDate.isSame(this._date, 'd') && !this.unset) {
                    clsName += ' active';
                }
                if (!this._isValid(currentDate, 'd')) {
                    clsName += ' disabled';
                }
                if (currentDate.isSame(this._getMoment(), 'd')) {
                    clsName += ' today';
                }
                if (currentDate.day() === 0 || currentDate.day() === 6) {
                    clsName += ' weekend';
                }
                row.append('<td data-action="selectDay" data-day="' + currentDate.format('L') + '" class="day' + clsName + '">' + currentDate.date() + '</td>');
                currentDate.add(1, 'd');
            }
            daysView.find('tbody').empty().append(html);
            this._updateMonths();
            this._updateYears();
            this._updateDecades();
        }
        _fillHours () {
            var table = this.widget.find('.timepicker-hours table'),
                currentHour = this._viewDate.clone().startOf('d'),
                html = [],
                row = $('<tr>');
            if (this._viewDate.hour() > 11 && !this.use24Hours) {
                currentHour.hour(12);
            }
            while (currentHour.isSame(this._viewDate, 'd') && (this.use24Hours || (this._viewDate.hour() < 12 && currentHour.hour() < 12) || this._viewDate.hour() > 11)) {
                if (currentHour.hour() % 4 === 0) {
                    row = $('<tr>');
                    html.push(row);
                }
                row.append('<td data-action="selectHour" class="hour' + (!this._isValid(currentHour, 'h') ? ' disabled' : '') + '">' + currentHour.format(this.use24Hours ? 'HH' : 'hh') + '</td>');
                currentHour.add(1, 'h');
            }
            table.empty().append(html);
        }
        _fillMinutes () {
            var table = this.widget.find('.timepicker-minutes table'),
                currentMinute = this._viewDate.clone().startOf('h'),
                html = [],
                row = $('<tr>'),
                step = this.options.stepping === 1 ? 5 : this.options.stepping;
            while (this._viewDate.isSame(currentMinute, 'h')) {
                if (currentMinute.minute() % (step * 4) === 0) {
                    row = $('<tr>');
                    html.push(row);
                }
                row.append('<td data-action="selectMinute" class="minute' + (!this._isValid(currentMinute, 'm') ? ' disabled' : '') + '">' + currentMinute.format('mm') + '</td>');
                currentMinute.add(step, 'm');
            }
            table.empty().append(html);
        }
        _fillSeconds () {
            var table = this.widget.find('.timepicker-seconds table'),
                currentSecond = this._viewDate.clone().startOf('m'),
                html = [],
                row = $('<tr>');
            while (this._viewDate.isSame(currentSecond, 'm')) {
                if (currentSecond.second() % 20 === 0) {
                    row = $('<tr>');
                    html.push(row);
                }
                row.append('<td data-action="selectSecond" class="second' + (!this._isValid(currentSecond, 's') ? ' disabled' : '') + '">' + currentSecond.format('ss') + '</td>');
                currentSecond.add(5, 's');
            }
            table.empty().append(html);
        }
        _fillTime () {
            var toggle, newDate, timeComponents = this.widget.find('.timepicker span[data-time-component]'),
                switchTime = this.widget.find('.picker-switch span.glyphicon-time');
            if (!this.use24Hours) {
                toggle = this.widget.find('.timepicker [data-action=togglePeriod]');
                newDate = this._date.clone().add((this._date.hours() >= 12) ? -12 : 12, 'h');
                toggle.text(this._date.format('A'));
                if (this._isValid(newDate, 'h')) {
                    toggle.removeClass('disabled');
                } else {
                    toggle.addClass('disabled');
                }
            }
            switchTime.text(this._date.format(this.options.timeViewHeaderFormat));
            timeComponents.filter('[data-time-component=hours]').text(this._date.format(this.use24Hours ? 'HH' : 'hh'));
            timeComponents.filter('[data-time-component=minutes]').text(this._date.format('mm'));
            timeComponents.filter('[data-time-component=seconds]').text(this._date.format('ss'));
            this._fillHours();
            this._fillMinutes();
            this._fillSeconds();
        }
        _update () {
            if (!this.widget) {
                return;
            }
            this._fillDate();
            this._fillTime();
        }
        _setValue (targetMoment, type) {
            var oldDate = this.unset ? null : this._date;
            if (!targetMoment) {
                this.unset = true;
                this.input.val('');
                this.element.data('date', '');
                this._notifyEvent({
                    type: 'dp.change',
                    date: false,
                    oldDate: oldDate
                });
                this._update();
                return;
            }
            targetMoment = targetMoment.clone().locale(this.options.locale);
            if (this._hasTimeZone()) {
                targetMoment.tz(this.options.timeZone);
            }
            if (this.options.stepping !== 1) {
                targetMoment.minutes((Math.round(targetMoment.minutes() / this.options.stepping) * this.options.stepping)).seconds(0);
            }
            if (type && type == 'first' && this.options.displayDefault || this._isValid(targetMoment)) {
                this._date = targetMoment;
                this._viewDate = this._date.clone(); 
                this.input.val(this._date.format(this.actualFormat));
                this.element.data('date', this._date.format(this.actualFormat));
                this.unset = false;
                this._update();
                this._notifyEvent({
                    type: 'dp.change',
                    date: this._date.clone(),
                    oldDate: oldDate
                });
            } else {
                if (!this.options.keepInvalid) {
                    this.input.val(this.unset ? '' : this._date.format(this.actualFormat));
                } else {
                    this._notifyEvent({
                        type: 'dp.change',
                        date: targetMoment,
                        oldDate: oldDate
                    });
                }
                this._notifyEvent({
                    type: 'dp.error',
                    date: targetMoment,
                    oldDate: oldDate
                });
            }
        }
        
        _hide = () => {
            var transitioning = false;
            if (!this.widget) {
                return this;
            }
            this.widget.find('.collapse').each(function () {
                var collapseData = $(this).data('collapse');
                if (collapseData && collapseData.transitioning) {
                    transitioning = true;
                    return false;
                }
                return true;
            });
            if (transitioning) {
                return this;
            }
            if (this.component && this.component.hasClass('btn')) {
                this.component.toggleClass('active');
            }
            this.widget.hide();
            $(window).off('resize', this._place);
            this.widget.off('click', '[data-action]');
            this.widget.off('mousedown', false);
            this.widget.remove();
            this.widget = false;
            this._notifyEvent({
                type: 'dp.hide',
                date: this._date.clone()
            });
            this.input.blur();
            this.currentViewMode = 0;
            this._viewDate = this._date.clone();
            return this;
        }
        _clear () {
            this._setValue(null);
        }
        _parseInputDate (inputDate) {
            if (this.options.parseInputDate === undefined) {
                if (!moment.isMoment(inputDate)) {
                    inputDate = this._getMoment(inputDate);
                }
            } else {
                inputDate = this.options.parseInputDate(inputDate);
            }
            return inputDate;
        }
        
        static actions = {
            next: function () {
                var navFnc = datePickerModes[this.currentViewMode].navFnc;
                this._viewDate.add(datePickerModes[this.currentViewMode].navStep, navFnc);
                this._fillDate();
                this._viewUpdate(navFnc);
            },
            previous: function () {
                var navFnc = datePickerModes[this.currentViewMode].navFnc;
                this._viewDate.subtract(datePickerModes[this.currentViewMode].navStep, navFnc);
                this._fillDate();
                this._viewUpdate(navFnc);
            },
            pickerSwitch: function () {
                this._showMode(1);
            },
            selectMonth: function (e) {
                var month = $(e.target).closest('tbody').find('span').index($(e.target));
                this._viewDate.month(month);
                if (this.currentViewMode === this.minViewModeNumber) {
                    this._setValue(this._date.clone().year(this._viewDate.year()).month(this._viewDate.month()));
                    if (!this.options.inline) {
                        this._hide();
                    }
                } else {
                    this._showMode(-1);
                    this._fillDate();
                }
                this._viewUpdate('M');
            },
            selectYear: function (e) {
                var year = parseInt($(e.target).text(), 10) || 0;
                this._viewDate.year(year);
                if (this.currentViewMode === this.minViewModeNumber) {
                    this._setValue(this._date.clone().year(this._viewDate.year()));
                    if (!this.options.inline) {
                        this._hide();
                    }
                } else {
                    this._showMode(-1);
                    this._fillDate();
                }
                this._viewUpdate('YYYY');
            },
            selectDecade: function (e) {
                var year = parseInt($(e.target).data('selection'), 10) || 0;
                this._viewDate.year(year);
                if (this.currentViewMode === this.minViewModeNumber) {
                    this._setValue(this._date.clone().year(this._viewDate.year()));
                    if (!this.options.inline) {
                        this._hide();
                    }
                } else {
                    this._showMode(-1);
                    this._fillDate();
                }
                this._viewUpdate('YYYY');
            },
            selectDay: function (e) {
                var day = this._viewDate.clone();
                if ($(e.target).is('.old')) {
                    day.subtract(1, 'M');
                }
                if ($(e.target).is('.new')) {
                    day.add(1, 'M');
                }
                this._setValue(day.date(parseInt($(e.target).text(), 10)));
                if (!this._hasTime() && !this.options.keepOpen && !this.options.inline) {
                    this._hide();
                }
            },
            incrementHours: function () {
                var newDate = this._date.clone().add(1, 'h');
                if (this._isValid(newDate, 'h')) {
                    this._setValue(newDate);
                }
            },
            incrementMinutes: function () {
                var newDate = this._date.clone().add(this.options.stepping, 'm');
                if (this._isValid(newDate, 'm')) {
                    this._setValue(newDate);
                }
            },
            incrementSeconds: function () {
                var newDate = this._date.clone().add(1, 's');
                if (this._isValid(newDate, 's')) {
                    this._setValue(newDate);
                }
            },
            decrementHours: function () {
                var newDate = this._date.clone().subtract(1, 'h');
                if (this._isValid(newDate, 'h')) {
                    this._setValue(newDate);
                }
            },
            decrementMinutes: function () {
                var newDate = this._date.clone().subtract(this.options.stepping, 'm');
                if (this._isValid(newDate, 'm')) {
                    this._setValue(newDate);
                }
            },
            decrementSeconds: function () {
                var newDate = this._date.clone().subtract(1, 's');
                if (this._isValid(newDate, 's')) {
                    this._setValue(newDate);
                }
            },
            togglePeriod: function () {
                this._setValue(this._date.clone().add((this._date.hours() >= 12) ? -12 : 12, 'h'));
            },
            togglePicker: function (e) {
                var $this = $(e.target),
                    $parent = $this.closest('ul'),
                    expanded = $parent.find('.in'),
                    closed = $parent.find('.collapse:not(.in)'),
                    collapseData;
                if (expanded && expanded.length) {
                    collapseData = expanded.data('collapse');
                    if (collapseData && collapseData.transitioning) {
                        return;
                    }
                    if (expanded.collapse) { 
                        expanded.collapse('hide');
                        closed.collapse('show');
                    } else { 
                        expanded.removeClass('in');
                        closed.addClass('in');
                    }
                    if ($this.is('span')) {
                        if($this.hasClass(this.options.icons.date)){
                            $this.text(this._date.format(this.options.timeViewHeaderFormat));
                        }else{
                            $this.text(this._date.format(this.options.dayViewHeaderFormat));
                        }
                        $this.toggleClass(this.options.icons.time + ' ' + this.options.icons.date);
                    } else {
                        if($this.find('span').hasClass(this.options.icons.date)){
                            $this.find('span').text(this._date.format(this.options.timeViewHeaderFormat));
                        }else{
                            $this.find('span').text(this._date.format(this.options.dayViewHeaderFormat));
                        }
                        $this.find('span').toggleClass(this.options.icons.time + ' ' + this.options.icons.date);
                    }
                }
            },
            showPicker: function () {
                this.widget.find('.timepicker > div:not(.timepicker-picker)').hide();
                this.widget.find('.timepicker .timepicker-picker').show();
            },
            showHours: function () {
                this.widget.find('.timepicker .timepicker-picker').hide();
                this.widget.find('.timepicker .timepicker-hours').show();
            },
            showMinutes: function () {
                this.widget.find('.timepicker .timepicker-picker').hide();
                this.widget.find('.timepicker .timepicker-minutes').show();
            },
            showSeconds: function () {
                this.widget.find('.timepicker .timepicker-picker').hide();
                this.widget.find('.timepicker .timepicker-seconds').show();
            },
            selectHour: function (e) {
                var hour = parseInt($(e.target).text(), 10);
                if (!this.use24Hours) {
                    if (this._date.hours() >= 12) {
                        if (hour !== 12) {
                            hour += 12;
                        }
                    } else {
                        if (hour === 12) {
                            hour = 0;
                        }
                    }
                }
                this._setValue(this._date.clone().hours(hour));
                Datetimepicker.actions.showPicker.call(this);
            },
            selectMinute: function (e) {
                this._setValue(this._date.clone().minutes(parseInt($(e.target).text(), 10)));
                Datetimepicker.actions.showPicker.call(this);
            },
            selectSecond: function (e) {
                this._setValue(this._date.clone().seconds(parseInt($(e.target).text(), 10)));
                Datetimepicker.actions.showPicker.call(this);
            },
            clear: Datetimepicker._clear,
            today: function () {
                var todaysDate = this._getMoment();
                if (this._isValid(todaysDate, 'd')) {
                    this._setValue(todaysDate);
                }
            },
            close: Datetimepicker._hide
        };
        _doAction (e) {
            if ($(e.currentTarget).is('.disabled')) {
                return false;
            }
            Datetimepicker.actions[$(e.currentTarget).data('action')].apply(this, arguments);
            return false;
        }
        
        _show = () => {
            var currentMoment,
                useCurrentGranularity = {
                    'year': function (m) {
                        return m.month(0).date(1).hours(0).seconds(0).minutes(0);
                    },
                    'month': function (m) {
                        return m.date(1).hours(0).seconds(0).minutes(0);
                    },
                    'day': function (m) {
                        return m.hours(0).seconds(0).minutes(0);
                    },
                    'hour': function (m) {
                        return m.seconds(0).minutes(0);
                    },
                    'minute': function (m) {
                        return m.seconds(0);
                    }
                };
            if (this.input.prop('disabled') || (!this.options.ignoreReadonly && this.input.prop('readonly')) || this.widget) {
                return this;
            }
            if (this.input.val() !== undefined && this.input.val().trim().length !== 0) {
                this._setValue(this._parseInputDate(this.input.val().trim()));
            } else if (this.unset && this.options.useCurrent && (this.options.inline || (this.input.is('input') && this.input.val().trim().length === 0))) {
                currentMoment = this._getMoment();
                if (typeof this.options.useCurrent === 'string') {
                    currentMoment = useCurrentGranularity[this.options.useCurrent](currentMoment);
                }
                this._setValue(currentMoment);
            }
            this.widget = this._getTemplate();
            this._fillDow();
            this._fillMonths();
            this.widget.find('.timepicker-hours').hide();
            this.widget.find('.timepicker-minutes').hide();
            this.widget.find('.timepicker-seconds').hide();
            this._update();
            this._showMode();
            $(window).on('resize', this._place);
            this.widget.on('click', '[data-action]', this._doAction.bind(this)); 
            this.widget.on('mousedown', false);
            if (this.component && this.component.hasClass('btn')) {
                this.component.toggleClass('active');
            }
            this._place();
            this.widget.show();
            if (this.options.focusOnShow && !this.input.is(':focus')) {
                this.input.focus();
            }
            this._notifyEvent({
                type: 'dp.show'
            });
            return this;
        }
        
        _toggle = () => {
            return (this.widget ? this._hide() : this._show());
        }
        _keydown = (e) => {
            var handler = null,
                index,
                index2,
                pressedKeys = [],
                pressedModifiers = {},
                currentKey = e.which,
                keyBindKeys,
                allModifiersPressed,
                pressed = 'p';
            this.keyState[currentKey] = pressed;
            for (index in this.keyState) {
                if (this.keyState.hasOwnProperty(index) && this.keyState[index] === pressed) {
                    pressedKeys.push(index);
                    if (parseInt(index, 10) !== currentKey) {
                        pressedModifiers[index] = true;
                    }
                }
            }
            for (index in this.options.keyBinds) {
                if (this.options.keyBinds.hasOwnProperty(index) && typeof (this.options.keyBinds[index]) === 'function') {
                    keyBindKeys = index.split(' ');
                    if (keyBindKeys.length === pressedKeys.length && keyMap[currentKey] === keyBindKeys[keyBindKeys.length - 1]) {
                        allModifiersPressed = true;
                        for (index2 = keyBindKeys.length - 2; index2 >= 0; index2--) {
                            if (!(keyMap[keyBindKeys[index2]] in pressedModifiers)) {
                                allModifiersPressed = false;
                                break;
                            }
                        }
                        if (allModifiersPressed) {
                            handler = this.options.keyBinds[index];
                            break;
                        }
                    }
                }
            }
            if (handler) {
                handler.call(this, this.widget);
                e.stopPropagation();
                e.preventDefault();
            }
        }
        _keyup = (e) => {
            this.keyState[e.which] = 'r';
            e.stopPropagation();
            e.preventDefault();
        }
        _change = (e) => {
            var val = $(e.target).val().trim(),
                parsedDate = val ? this._parseInputDate(val) : null;
            this._setValue(parsedDate);
            e.stopImmediatePropagation();
            return false;
        }
        _attachDatePickerElementEvents () {
            this.input.on({
                'change': this._change,
                'blur': this.options.debug ? '' : this._hide,
                'keydown': this._keydown,
                'keyup': this._keyup,
                'focus': this.options.allowInputToggle ? this._show : ''
            });
            if (this.element.is('input')) {
                this.input.on({
                    'focus': this._show
                });
            } else if (this.component) {
                this.component.on('click', this._toggle);
                this.component.on('mousedown', false);
            }
        }
        _detachDatePickerElementEvents () {
            this.input.off({
                'change': this._change,
                'blur': this._blur,
                'keydown': this._keydown,
                'keyup': this._keyup,
                'focus': this.options.allowInputToggle ? this._hide : ''
            });
            if (this.element.is('input')) {
                this.input.off({
                    'focus': this._show
                });
            } else if (this.component) {
                this.component.off('click', this._toggle);
                this.component.off('mousedown', false);
            }
        }
        _indexGivenDates (givenDatesArray) {
            var self = this, givenDatesIndexed = {};
            $.each(givenDatesArray, function () {
                var dDate = self._parseInputDate(this);
                if (dDate.isValid()) {
                    givenDatesIndexed[dDate.format('YYYY-MM-DD')] = true;
                }
            });
            return (Object.keys(givenDatesIndexed).length) ? givenDatesIndexed : false;
        }
        _indexGivenHours (givenHoursArray) {
            var givenHoursIndexed = {};
            $.each(givenHoursArray, function () {
                givenHoursIndexed[this] = true;
            });
            return (Object.keys(givenHoursIndexed).length) ? givenHoursIndexed : false;
        }
        _initFormatting () {
            var self = this;
            var format = this.options.format || 'L LT';
            this.actualFormat = format.replace(/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g, function (formatInput) {
                var newinput = self._date.localeData().longDateFormat(formatInput) || formatInput;
                return newinput.replace(/(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g, function (formatInput2) { 
                    return self._date.localeData().longDateFormat(formatInput2) || formatInput2;
                });
            });
            this.parseFormats = this.options.extraFormats ? this.options.extraFormats.slice() : [];
            if (this.parseFormats.indexOf(format) < 0 && this.parseFormats.indexOf(this.actualFormat) < 0) {
                this.parseFormats.push(this.actualFormat);
            }
            this.use24Hours = (this.actualFormat.toLowerCase().indexOf('a') < 1 && this.actualFormat.replace(/\[.*?\]/g, '').indexOf('h') < 1);
            if (this._isEnabled('y')) {
                this.minViewModeNumber = 2;
            }
            if (this._isEnabled('M')) {
                this.minViewModeNumber = 1;
            }
            if (this._isEnabled('d')) {
                this.minViewModeNumber = 0;
            }
            this.currentViewMode = Math.max(this.minViewModeNumber, this.currentViewMode);
            if (!this.unset) {
                this._setValue(this._date);
            }
        }
        
        destroy () {
            this._hide();
            this._detachDatePickerElementEvents();
            this.element.removeData('DateTimePicker');
            this.element.removeData('date');
        }
        toggle = this._toggle;
        show = this._show;
        hide = this._hide;
        disable () {
            this._hide();
            if (this.component && this.component.hasClass('btn')) {
                this.component.addClass('disabled');
            }
            this.input.prop('disabled', true);
            return this;
        }
        enable () {
            if (this.component && this.component.hasClass('btn')) {
                this.component.removeClass('disabled');
            }
            this.input.prop('disabled', false);
            return this;
        }
        ignoreReadonly (ignoreReadonly) {
            if (arguments.length === 0) {
                return this.options.ignoreReadonly;
            }
            if (typeof ignoreReadonly !== 'boolean') {
                throw new TypeError('ignoreReadonly () expects a boolean parameter');
            }
            this.options.ignoreReadonly = ignoreReadonly;
            return this;
        }
        setOptions (newOptions) {
            var self = this;
            if (arguments.length === 0) {
                return $.extend(true, {}, this.options);
            }
            if (!(newOptions instanceof Object)) {
                throw new TypeError('options() options parameter should be an object');
            }
            $.extend(true, this.options, newOptions);
            $.each(this.options, function (key, value) {
                if (self[key] !== undefined) {
                    self[key](value);
                } else {
                    throw new TypeError('option ' + key + ' is not recognized!');
                }
            });
            return this;
        }
        date (newDate) {
            if (arguments.length === 0) {
                if (this.unset) {
                    return null;
                }
                return this._date.clone();
            }
            if (newDate !== null && typeof newDate !== 'string' && !moment.isMoment(newDate) && !(newDate instanceof this._date)) {
                throw new TypeError('date() parameter must be one of [null, string, moment or Date]');
            }
            this._setValue(newDate === null ? null : this._parseInputDate(newDate));
            return this;
        }
        format (newFormat) {
            if (arguments.length === 0) {
                return this.options.format;
            }
            if ((typeof newFormat !== 'string') && ((typeof newFormat !== 'boolean') || (newFormat !== false))) {
                throw new TypeError('format() expects a string or boolean:false parameter ' + newFormat);
            }
            this.options.format = newFormat;
            if (this.actualFormat) {
                this._initFormatting(); 
            }
            return this;
        }
        timeZone (newZone) {
            if (arguments.length === 0) {
                return this.options.timeZone;
            }
            if (typeof newZone !== 'string') {
                throw new TypeError('newZone() expects a string parameter');
            }
            this.options.timeZone = newZone;
            return this;
        }
        dayViewHeaderFormat (newFormat) {
            if (arguments.length === 0) {
                return this.options.dayViewHeaderFormat;
            }
            if (typeof newFormat !== 'string') {
                throw new TypeError('dayViewHeaderFormat() expects a string parameter');
            }
            this.options.dayViewHeaderFormat = newFormat;
            return this;
        }
        timeViewHeaderFormat (newFormat) {
            if (arguments.length === 0) {
                return this.options.timeViewHeaderFormat;
            }
            if (typeof newFormat !== 'string') {
                throw new TypeError('timeViewHeaderFormat() expects a string parameter');
            }
            this.options.timeViewHeaderFormat = newFormat;
            return this;
        }
        extraFormats (formats) {
            if (arguments.length === 0) {
                return this.options.extraFormats;
            }
            if (formats !== false && !(formats instanceof Array)) {
                throw new TypeError('extraFormats() expects an array or false parameter');
            }
            this.options.extraFormats = formats;
            if (this.parseFormats) {
                this._initFormatting(); 
            }
            return this;
        }
        disabledDates (dates) {
            if (arguments.length === 0) {
                return (this.options.disabledDates ? $.extend({}, this.options.disabledDates) : this.options.disabledDates);
            }
            if (!dates) {
                this.options.disabledDates = false;
                this._update();
                return this;
            }
            if (!(dates instanceof Array)) {
                throw new TypeError('disabledDates() expects an array parameter');
            }
            this.options.disabledDates = this._indexGivenDates(dates);
            this.options.enabledDates = false;
            this._update();
            return this;
        }
        enabledDates (dates) {
            if (arguments.length === 0) {
                return (this.options.enabledDates ? $.extend({}, this.options.enabledDates) : this.options.enabledDates);
            }
            if (!dates) {
                this.options.enabledDates = false;
                this._update();
                return this;
            }
            if (!(dates instanceof Array)) {
                throw new TypeError('enabledDates() expects an array parameter');
            }
            this.options.enabledDates = this._indexGivenDates(dates);
            this.options.disabledDates = false;
            this._update();
            return this;
        }
        daysOfWeekDisabled (daysOfWeekDisabled) {
            if (arguments.length === 0) {
                return this.options.daysOfWeekDisabled.splice(0);
            }
            if ((typeof daysOfWeekDisabled === 'boolean') && !daysOfWeekDisabled) {
                this.options.daysOfWeekDisabled = false;
                this._update();
                return this;
            }
            if (!(daysOfWeekDisabled instanceof Array)) {
                throw new TypeError('daysOfWeekDisabled() expects an array parameter');
            }
            this.options.daysOfWeekDisabled = daysOfWeekDisabled.reduce(function (previousValue, currentValue) {
                currentValue = parseInt(currentValue, 10);
                if (currentValue > 6 || currentValue < 0 || isNaN(currentValue)) {
                    return previousValue;
                }
                if (previousValue.indexOf(currentValue) === -1) {
                    previousValue.push(currentValue);
                }
                return previousValue;
            }, []).sort();
            if (this.options.useCurrent && !this.options.keepInvalid) {
                var tries = 0;
                while (!this._isValid(this._date, 'd')) {
                    this._date.add(1, 'd');
                    if (tries === 31) {
                        throw 'Tried 31 times to find a valid date';
                    }
                    tries++;
                }
                this._setValue(this._date);
            }
            this._update();
            return this;
        }
        maxDate (maxDate) {
            if (arguments.length === 0) {
                return this.options.maxDate ? this.options.maxDate.clone() : this.options.maxDate;
            }
            if ((typeof maxDate === 'boolean') && maxDate === false) {
                this.options.maxDate = false;
                this._update();
                return this;
            }
            if (typeof maxDate === 'string') {
                if (maxDate === 'now' || maxDate === 'moment') {
                    maxDate = this._getMoment();
                }
            }
            var parsedDate = this._parseInputDate(maxDate);
            if (!parsedDate.isValid()) {
                throw new TypeError('maxDate() Could not parse date parameter: ' + maxDate);
            }
            if (this.options.minDate && parsedDate.isBefore(this.options.minDate)) {
                throw new TypeError('maxDate() date parameter is before options.minDate: ' + parsedDate.format(this.actualFormat));
            }
            this.options.maxDate = parsedDate;
            if (this.options.useCurrent && !this.options.keepInvalid && this._date.isAfter(maxDate)) {
                this._setValue(this.options.maxDate);
            }
            if (this._viewDate.isAfter(parsedDate)) {
                this._viewDate = parsedDate.clone().subtract(this.options.stepping, 'm');
            }
            this._update();
            return this;
        }
        minDate (minDate) {
            if (arguments.length === 0) {
                return this.options.minDate ? this.options.minDate.clone() : this.options.minDate;
            }
            if ((typeof minDate === 'boolean') && minDate === false) {
                this.options.minDate = false;
                this._update();
                return this;
            }
            if (typeof minDate === 'string') {
                if (minDate === 'now' || minDate === 'moment') {
                    minDate = this._getMoment();
                }
            }
            var parsedDate = this._parseInputDate(minDate);
            if (!parsedDate.isValid()) {
                throw new TypeError('minDate() Could not parse date parameter: ' + minDate);
            }
            if (this.options.maxDate && parsedDate.isAfter(this.options.maxDate)) {
                throw new TypeError('minDate() date parameter is after options.maxDate: ' + parsedDate.format(this.actualFormat));
            }
            this.options.minDate = parsedDate;
            if (this.options.useCurrent && !this.options.keepInvalid && this._date.isBefore(minDate)) {
                this._setValue(this.options.minDate);
            }
            if (this._viewDate.isBefore(parsedDate)) {
                this._viewDate = parsedDate.clone().add(this.options.stepping, 'm');
            }
            this._update();
            return this;
        }
        defaultDate (defaultDate) {
            if (arguments.length === 0) {
                return this.options.defaultDate ? this.options.defaultDate.clone() : this.options.defaultDate;
            }
            if (!defaultDate) {
                this.options.defaultDate = false;
                return this;
            }
            if (typeof defaultDate === 'string') {
                if (defaultDate === 'now' || defaultDate === 'moment') {
                    defaultDate = this._getMoment();
                } else {
                    defaultDate = this._getMoment(defaultDate);
                }
            }
            var parsedDate = this._parseInputDate(defaultDate);
            if (!parsedDate.isValid()) {
                throw new TypeError('defaultDate() Could not parse date parameter: ' + defaultDate);
            }
            if (!this._isValid(parsedDate)) {
                throw new TypeError('defaultDate() date passed is invalid according to component setup validations');
            }
            this.options.defaultDate = parsedDate;
            if ((this.options.defaultDate && this.options.inline) || this.input.val().trim() === '') {
                this._setValue(this.options.defaultDate);
            }
            return this;
        }
        locale (locale) {
            if (arguments.length === 0) {
                return this.options.locale;
            }
            if (!moment.localeData(locale)) {
                throw new TypeError('locale() locale ' + locale + ' is not loaded from moment locales!');
            }
            this.options.locale = locale;
            this._date.locale(this.options.locale);
            this._viewDate.locale(this.options.locale);
            if (this.actualFormat) {
                this._initFormatting(); 
            }
            if (this.widget) {
                this._hide();
                this._show();
            }
            return this;
        }
        stepping (stepping) {
            if (arguments.length === 0) {
                return this.options.stepping;
            }
            stepping = parseInt(stepping, 10);
            if (isNaN(stepping) || stepping < 1) {
                stepping = 1;
            }
            this.options.stepping = stepping;
            return this;
        }
        useCurrent (useCurrent) {
            var useCurrentoptions = ['year', 'month', 'day', 'hour', 'minute'];
            if (arguments.length === 0) {
                return this.options.useCurrent;
            }
            if ((typeof useCurrent !== 'boolean') && (typeof useCurrent !== 'string')) {
                throw new TypeError('useCurrent() expects a boolean or string parameter');
            }
            if (typeof useCurrent === 'string' && useCurrentOptions.indexOf(useCurrent.toLowerCase()) === -1) {
                throw new TypeError('useCurrent() expects a string parameter of ' + useCurrentOptions.join(', '));
            }
            this.options.useCurrent = useCurrent;
            return this;
        }
        displayDefault (displayDefault) {
            if (arguments.length === 0) {
                return this.options.displayDefault;
            }
            if (typeof displayDefault !== 'boolean') {
                throw new TypeError('displayDefault() expects a boolean parameter');
            }
            this.options.displayDefault = displayDefault;
            return this;
        }
        collapse (collapse) {
            if (arguments.length === 0) {
                return this.options.collapse;
            }
            if (typeof collapse !== 'boolean') {
                throw new TypeError('collapse() expects a boolean parameter');
            }
            if (this.options.collapse === collapse) {
                return this;
            }
            this.options.collapse = collapse;
            if (this.widget) {
                this._hide();
                this._show();
            }
            return this;
        }
        icons (icons) {
            if (arguments.length === 0) {
                return $.extend({}, this.options.icons);
            }
            if (!(icons instanceof Object)) {
                throw new TypeError('icons() expects parameter to be an Object');
            }
            $.extend(this.options.icons, icons);
            if (this.widget) {
                this._hide();
                this._show();
            }
            return this;
        }
        tooltips (tooltips) {
            if (arguments.length === 0) {
                return $.extend({}, this.options.tooltips);
            }
            if (!(tooltips instanceof Object)) {
                throw new TypeError('tooltips() expects parameter to be an Object');
            }
            $.extend(this.options.tooltips, tooltips);
            if (this.widget) {
                this._hide();
                this._show();
            }
            return this;
        }
        useStrict (useStrict) {
            if (arguments.length === 0) {
                return this.options.useStrict;
            }
            if (typeof useStrict !== 'boolean') {
                throw new TypeError('useStrict() expects a boolean parameter');
            }
            this.options.useStrict = useStrict;
            return this;
        }
        sideBySide (sideBySide) {
            if (arguments.length === 0) {
                return this.options.sideBySide;
            }
            if (typeof sideBySide !== 'boolean') {
                throw new TypeError('sideBySide() expects a boolean parameter');
            }
            this.options.sideBySide = sideBySide;
            if (this.widget) {
                this._hide();
                this._show();
            }
            return this;
        }
        viewMode (viewMode) {
            if (arguments.length === 0) {
                return this.options.viewMode;
            }
            if (typeof viewMode !== 'string') {
                throw new TypeError('viewMode() expects a string parameter');
            }
            if (viewModes.indexOf(viewMode) === -1) {
                throw new TypeError('viewMode() parameter must be one of (' + viewModes.join(', ') + ') value');
            }
            this.options.viewMode = viewMode;
            this.currentViewMode = Math.max(viewModes.indexOf(viewMode), this.minViewModeNumber);
            this._showMode();
            return this;
        }
        toolbarPlacement (toolbarPlacement) {
            if (arguments.length === 0) {
                return this.options.toolbarPlacement;
            }
            if (typeof toolbarPlacement !== 'string') {
                throw new TypeError('toolbarPlacement() expects a string parameter');
            }
            if (toolbarPlacements.indexOf(toolbarPlacement) === -1) {
                throw new TypeError('toolbarPlacement() parameter must be one of (' + toolbarPlacements.join(', ') + ') value');
            }
            this.options.toolbarPlacement = toolbarPlacement;
            if (this.widget) {
                this._hide();
                this._show();
            }
            return this;
        }
        widgetPositioning (widgetPositioning) {
            if (arguments.length === 0) {
                return $.extend({}, this.options.widgetPositioning);
            }
            if (({}).toString.call(widgetPositioning) !== '[object Object]') {
                throw new TypeError('widgetPositioning() expects an object variable');
            }
            if (widgetPositioning.horizontal) {
                if (typeof widgetPositioning.horizontal !== 'string') {
                    throw new TypeError('widgetPositioning() horizontal variable must be a string');
                }
                widgetPositioning.horizontal = widgetPositioning.horizontal.toLowerCase();
                if (horizontalModes.indexOf(widgetPositioning.horizontal) === -1) {
                    throw new TypeError('widgetPositioning() expects horizontal parameter to be one of (' + horizontalModes.join(', ') + ')');
                }
                this.options.widgetPositioning.horizontal = widgetPositioning.horizontal;
            }
            if (widgetPositioning.vertical) {
                if (typeof widgetPositioning.vertical !== 'string') {
                    throw new TypeError('widgetPositioning() vertical variable must be a string');
                }
                widgetPositioning.vertical = widgetPositioning.vertical.toLowerCase();
                if (verticalModes.indexOf(widgetPositioning.vertical) === -1) {
                    throw new TypeError('widgetPositioning() expects vertical parameter to be one of (' + verticalModes.join(', ') + ')');
                }
                this.options.widgetPositioning.vertical = widgetPositioning.vertical;
            }
            this._update();
            return this;
        }
        calendarWeeks (calendarWeeks) {
            if (arguments.length === 0) {
                return this.options.calendarWeeks;
            }
            if (typeof calendarWeeks !== 'boolean') {
                throw new TypeError('calendarWeeks() expects parameter to be a boolean value');
            }
            this.options.calendarWeeks = calendarWeeks;
            this._update();
            return this;
        }
        showTodayButton (showTodayButton) {
            if (arguments.length === 0) {
                return this.options.showTodayButton;
            }
            if (typeof showTodayButton !== 'boolean') {
                throw new TypeError('showTodayButton() expects a boolean parameter');
            }
            this.options.showTodayButton = showTodayButton;
            if (this.widget) {
                this._hide();
                this._show();
            }
            return this;
        }
        showClear (showClear) {
            if (arguments.length === 0) {
                return this.options.showClear;
            }
            if (typeof showClear !== 'boolean') {
                throw new TypeError('showClear() expects a boolean parameter');
            }
            this.options.showClear = showClear;
            if (this.widget) {
                this._hide();
                this._show();
            }
            return this;
        }
        widgetParent (widgetParent) {
            if (arguments.length === 0) {
                return this.options.widgetParent;
            }
            if (typeof widgetParent === 'string') {
                widgetParent = $(widgetParent);
            }
            if (widgetParent !== null && (typeof widgetParent !== 'string' && !(widgetParent instanceof $))) {
                throw new TypeError('widgetParent() expects a string or a jQuery object parameter');
            }
            this.options.widgetParent = widgetParent;
            if (this.widget) {
                this._hide();
                this._show();
            }
            return this;
        }
        keepOpen (keepOpen) {
            if (arguments.length === 0) {
                return this.options.keepOpen;
            }
            if (typeof keepOpen !== 'boolean') {
                throw new TypeError('keepOpen() expects a boolean parameter');
            }
            this.options.keepOpen = keepOpen;
            return this;
        }
        focusOnShow (focusOnShow) {
            if (arguments.length === 0) {
                return this.options.focusOnShow;
            }
            if (typeof focusOnShow !== 'boolean') {
                throw new TypeError('focusOnShow() expects a boolean parameter');
            }
            this.options.focusOnShow = focusOnShow;
            return this;
        }
        inline (inline) {
            if (arguments.length === 0) {
                return this.options.inline;
            }
            if (typeof inline !== 'boolean') {
                throw new TypeError('inline() expects a boolean parameter');
            }
            this.options.inline = inline;
            return this;
        }
        clear () {
            this._clear();
            return this;
        }
        keyBinds (keyBinds) {
            if (arguments.length === 0) {
                return this.options.keyBinds;
            }
            this.options.keyBinds = keyBinds;
            return this;
        }
        getMoment (d) {
            return this._getMoment(d);
        }
        debug (debug) {
            if (typeof debug !== 'boolean') {
                throw new TypeError('debug() expects a boolean parameter');
            }
            this.options.debug = debug;
            return this;
        }
        allowInputToggle (allowInputToggle) {
            if (arguments.length === 0) {
                return this.options.allowInputToggle;
            }
            if (typeof allowInputToggle !== 'boolean') {
                throw new TypeError('allowInputToggle() expects a boolean parameter');
            }
            this.options.allowInputToggle = allowInputToggle;
            return this;
        }
        showClose (showClose) {
            if (arguments.length === 0) {
                return this.options.showClose;
            }
            if (typeof showClose !== 'boolean') {
                throw new TypeError('showClose() expects a boolean parameter');
            }
            this.options.showClose = showClose;
            return this;
        }
        keepInvalid (keepInvalid) {
            if (arguments.length === 0) {
                return this.options.keepInvalid;
            }
            if (typeof keepInvalid !== 'boolean') {
                throw new TypeError('keepInvalid() expects a boolean parameter');
            }
            this.options.keepInvalid = keepInvalid;
            return this;
        }
        datepickerInput (datepickerInput) {
            if (arguments.length === 0) {
                return this.options.datepickerInput;
            }
            if (typeof datepickerInput !== 'string') {
                throw new TypeError('datepickerInput() expects a string parameter');
            }
            this.options.datepickerInput = datepickerInput;
            return this;
        }
        parseInputDate (parseInputDate) {
            if (arguments.length === 0) {
                return this.options.parseInputDate;
            }
            if (typeof this._parseInputDate !== 'function') {
                throw new TypeError('parseInputDate() sholud be as function');
            }
            this.options.parseInputDate = this._parseInputDate;
            return this;
        }
        disabledTimeIntervals (disabledTimeIntervals) {
            if (arguments.length === 0) {
                return (this.options.disabledTimeIntervals ? $.extend({}, this.options.disabledTimeIntervals) : this.options.disabledTimeIntervals);
            }
            if (!disabledTimeIntervals) {
                this.options.disabledTimeIntervals = false;
                this._update();
                return this;
            }
            if (!(disabledTimeIntervals instanceof Array)) {
                throw new TypeError('disabledTimeIntervals() expects an array parameter');
            }
            this.options.disabledTimeIntervals = disabledTimeIntervals;
            this._update();
            return this;
        }
        disabledHours (hours) {
            if (arguments.length === 0) {
                return (this.options.disabledHours ? $.extend({}, this.options.disabledHours) : this.options.disabledHours);
            }
            if (!hours) {
                this.options.disabledHours = false;
                this._update();
                return this;
            }
            if (!(hours instanceof Array)) {
                throw new TypeError('disabledHours() expects an array parameter');
            }
            this.options.disabledHours = this._indexGivenHours(hours);
            this.options.enabledHours = false;
            if (this.options.useCurrent && !this.options.keepInvalid) {
                var tries = 0;
                while (!this._isValid(this._date, 'h')) {
                    this._date.add(1, 'h');
                    if (tries === 24) {
                        throw 'Tried 24 times to find a valid date';
                    }
                    tries++;
                }
                this._setValue(this._date);
            }
            this._update();
            return this;
        }
        enabledHours (hours) {
            if (arguments.length === 0) {
                return (this.options.enabledHours ? $.extend({}, this.options.enabledHours) : this.options.enabledHours);
            }
            if (!hours) {
                this.options.enabledHours = false;
                this._update();
                return this;
            }
            if (!(hours instanceof Array)) {
                throw new TypeError('enabledHours() expects an array parameter');
            }
            this.options.enabledHours = this._indexGivenHours(hours);
            this.options.disabledHours = false;
            if (this.options.useCurrent && !this.options.keepInvalid) {
                var tries = 0;
                while (!this._isValid(this._date, 'h')) {
                    this._date.add(1, 'h');
                    if (tries === 24) {
                        throw 'Tried 24 times to find a valid date';
                    }
                    tries++;
                }
                this._setValue(this._date);
            }
            this._update();
            return this;
        }
        
        viewDate (newDate) {
            if (arguments.length === 0) {
                return this._viewDate.clone();
            }
            if (!newDate) {
                this._viewDate = this._date.clone();
                return this;
            }
            if (typeof newDate !== 'string' && !moment.isMoment(newDate) && !(newDate instanceof Date)) {
                throw new TypeError('viewDate() parameter must be one of [string, moment or Date]');
            }
            this._viewDate = this._parseInputDate(newDate);
            this._viewUpdate();
            return this;
        }        
        weekStart (weekStart){
            if (typeof weekStart !== 'number') {
                throw new TypeError('weekStart() expects a number parameter');
            }
            if(weekStart < 0 || weekStart > 7) {
                throw new TypeError('weekStart() expects a greater than 0 and less than 7 parameter');
            }
            this.options.weekStart = weekStart;
            return this;
        }
    }
    const DEFAULTS = {
        timeZone: '',
        format: false,
        dayViewHeaderFormat: 'MMMM YYYY',
        timeViewHeaderFormat: 'hh:mm a',
        extraFormats: false,
        stepping: 1,
        minDate: false,
        maxDate: false,
        useCurrent: true,
        displayDefault: false, 
        collapse: true,
        locale: moment.locale(),
        defaultDate: false,
        disabledDates: false,
        enabledDates: false,
        icons: {
            time: 'glyphicon glyphicon-time',
            date: 'glyphicon glyphicon-calendar',
            up: 'glyphicon glyphicon-chevron-up',
            down: 'glyphicon glyphicon-chevron-down',
            previous: 'glyphicon glyphicon-chevron-left',
            next: 'glyphicon glyphicon-chevron-right',
            today: 'glyphicon glyphicon-screenshot',
            clear: 'glyphicon glyphicon-trash',
            close: 'glyphicon glyphicon-remove'
        },
        tooltips: {
            today: 'Go to today',
            clear: 'Clear selection',
            close: 'Close the picker',
            selectMonth: 'Select Month',
            prevMonth: 'Previous Month',
            nextMonth: 'Next Month',
            selectYear: 'Select Year',
            prevYear: 'Previous Year',
            nextYear: 'Next Year',
            selectDecade: 'Select Decade',
            prevDecade: 'Previous Decade',
            nextDecade: 'Next Decade',
            prevCentury: 'Previous Century',
            nextCentury: 'Next Century',
            pickHour: 'Pick Hour',
            incrementHour: 'Increment Hour',
            decrementHour: 'Decrement Hour',
            pickMinute: 'Pick Minute',
            incrementMinute: 'Increment Minute',
            decrementMinute: 'Decrement Minute',
            pickSecond: 'Pick Second',
            incrementSecond: 'Increment Second',
            decrementSecond: 'Decrement Second',
            togglePeriod: 'Toggle Period',
            selectTime: 'Select Time'
        },
        useStrict: false,
        sideBySide: false,
        daysOfWeekDisabled: false,
        calendarWeeks: false,
        viewMode: 'days',
        toolbarPlacement: 'default',
        showTodayButton: false,
        showClear: false,
        showClose: false,
        widgetPositioning: {
            horizontal: 'auto',
            vertical: 'auto'
        },
        widgetParent: null,
        ignoreReadonly: false,
        keepOpen: false,
        focusOnShow: true,
        inline: false,
        keepInvalid: false,
        datepickerInput: '.datepickerinput',
        keyBinds: {
            up: function (widget) {
                if (!widget) {
                    return;
                }
                var d = this.date() || this.getMoment();
                if (widget.find('.datepicker').is(':visible')) {
                    this.date(d.clone().subtract(7, 'd'));
                } else {
                    this.date(d.clone().add(this.stepping(), 'm'));
                }
            },
            down: function (widget) {
                if (!widget) {
                    this._show();
                    return;
                }
                var d = this.date() || this.getMoment();
                if (widget.find('.datepicker').is(':visible')) {
                    this.date(d.clone().add(7, 'd'));
                } else {
                    this.date(d.clone().subtract(this.stepping(), 'm'));
                }
            },
            'control up': function (widget) {
                if (!widget) {
                    return;
                }
                var d = this.date() || this.getMoment();
                if (widget.find('.datepicker').is(':visible')) {
                    this.date(d.clone().subtract(1, 'y'));
                } else {
                    this.date(d.clone().add(1, 'h'));
                }
            },
            'control down': function (widget) {
                if (!widget) {
                    return;
                }
                var d = this.date() || this.getMoment();
                if (widget.find('.datepicker').is(':visible')) {
                    this.date(d.clone().add(1, 'y'));
                } else {
                    this.date(d.clone().subtract(1, 'h'));
                }
            },
            left: function (widget) {
                if (!widget) {
                    return;
                }
                var d = this.date() || this.getMoment();
                if (widget.find('.datepicker').is(':visible')) {
                    this.date(d.clone().subtract(1, 'd'));
                }
            },
            right: function (widget) {
                if (!widget) {
                    return;
                }
                var d = this.date() || this.getMoment();
                if (widget.find('.datepicker').is(':visible')) {
                    this.date(d.clone().add(1, 'd'));
                }
            },
            pageUp: function (widget) {
                if (!widget) {
                    return;
                }
                var d = this.date() || this.getMoment();
                if (widget.find('.datepicker').is(':visible')) {
                    this.date(d.clone().subtract(1, 'M'));
                }
            },
            pageDown: function (widget) {
                if (!widget) {
                    return;
                }
                var d = this.date() || this.getMoment();
                if (widget.find('.datepicker').is(':visible')) {
                    this.date(d.clone().add(1, 'M'));
                }
            },
            enter: function () {
                this._hide();
            },
            escape: function () {
                this._hide();
            },
            'control space': function (widget) {
                if (!widget) {
                    return;
                }
                if (widget.find('.timepicker').is(':visible')) {
                    widget.find('.btn[data-action="togglePeriod"]').click();
                }
            },
            t: function () {
                this.date(this.getMoment());
            },
            'delete': function () {
                this.clear();
            }
        },
        debug: false,
        allowInputToggle: false,
        disabledTimeIntervals: false,
        disabledHours: false,
        enabledHours: false,
        viewDate: false
    };
    let datePickerModes = [{
            clsName: 'days',
            navFnc: 'M',
            navStep: 1
        },{
            clsName: 'months',
            navFnc: 'y',
            navStep: 1
        },{
            clsName: 'years',
            navFnc: 'y',
            navStep: 10
        },{
            clsName: 'decades',
            navFnc: 'y',
            navStep: 100
        }];
    let viewModes = ['days', 'months', 'years', 'decades'];
    let verticalModes = ['top', 'bottom', 'auto'];
    let horizontalModes = ['left', 'right', 'auto'];
    let toolbarPlacements = ['default', 'top', 'bottom'];
    let keyMap = {
            'up': 38,
            38: 'up',
            'down': 40,
            40: 'down',
            'left': 37,
            37: 'left',
            'right': 39,
            39: 'right',
            'tab': 9,
            9: 'tab',
            'escape': 27,
            27: 'escape',
            'enter': 13,
            13: 'enter',
            'pageUp': 33,
            33: 'pageUp',
            'pageDown': 34,
            34: 'pageDown',
            'shift': 16,
            16: 'shift',
            'control': 17,
            17: 'control',
            'space': 32,
            32: 'space',
            't': 84,
            84: 't',
            'delete': 46,
            46: 'delete'
        };
        
    let dates = {
            days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
            daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
            daysMin: ["\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u65E5"],
            months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
            monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
        };
    $.fn.datetimepicker = function (options) {
        options = options || {};
        var args = Array.prototype.slice.call(arguments, 1),
            isInstance = true,
            thisMethods = ['destroy', 'hide', 'show', 'toggle'],
            returnValue;
        if (typeof options === 'object') {
            return this.each(function () {
                var $this = $(this);
                if (!$this.data('DateTimePicker')) {
                    options = $.extend(true, {}, DEFAULTS, options);
                    $this.data('DateTimePicker', new Datetimepicker($this, options));
                }
            });
        } else if (typeof options === 'string') {
            this.each(function () {
                var $this = $(this),
                    instance = $this.data('DateTimePicker');
                if (!instance) {
                    throw new Error('cd-datetimepicker("' + options + '") method was called on an element that is not using DateTimePicker');
                }
                returnValue = instance[options].apply(instance, args);
                isInstance = returnValue === instance;
            });
            if (isInstance || $.inArray(options, thisMethods) > -1) {
                return this;
            }
            return returnValue;
        }
        throw new TypeError('Invalid arguments for DateTimePicker: ' + options);
    };
    return Datetimepicker;
})();
export default Datetimepicker;