Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Remove leading zeros from days. #137

Open
wants to merge 3 commits into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 31 additions & 59 deletions js/bootstrap-material-datetimepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,33 +552,21 @@

if (typeof (this.minDate) !== 'undefined' && this.minDate !== null)
{
var _minDate = moment(this.minDate);
var _date = moment(date);
var _minDate = moment(this.minDate).second(0).millisecond(0);
var _date = moment(date).second(0).millisecond(0);

if (!checkHour && !checkMinute)
{
_minDate.hour(0);
_minDate.minute(0);

_date.hour(0);
_date.minute(0);
_minDate.hour(0).minute(0);
_date.hour(0).minute(0);
}

_minDate.second(0);
_date.second(0);
_minDate.millisecond(0);
_date.millisecond(0);

if (!checkMinute)
{
_date.minute(0);
_minDate.minute(0);

_return = (parseInt(_date.format("X")) >= parseInt(_minDate.format("X")));
} else
{
_return = (parseInt(_date.format("X")) >= parseInt(_minDate.format("X")));
}
_return = _date.isSameOrAfter(_minDate);
}

return _return;
Expand All @@ -589,43 +577,32 @@

if (typeof (this.maxDate) !== 'undefined' && this.maxDate !== null)
{
var _maxDate = moment(this.maxDate);
var _date = moment(date);
var _maxDate = moment(this.maxDate).second(0).millisecond(0);
var _date = moment(date).second(0).millisecond(0);

if (!checkTime && !checkMinute)
{
_maxDate.hour(0);
_maxDate.minute(0);

_date.hour(0);
_date.minute(0);
_maxDate.hour(0).minute(0);
_date.hour(0).minute(0);
}

_maxDate.second(0);
_date.second(0);
_maxDate.millisecond(0);
_date.millisecond(0);

if (!checkMinute)
{
_date.minute(0);
_maxDate.minute(0);

_return = (parseInt(_date.format("X")) <= parseInt(_maxDate.format("X")));
} else
{
_return = (parseInt(_date.format("X")) <= parseInt(_maxDate.format("X")));
}
_return = _date.isSameOrBefore(_maxDate);
}

return _return;
},
rotateElement: function (el, deg)
{
var val = 'rotate(' + deg + 'deg)';
$(el).css
({
WebkitTransform: 'rotate(' + deg + 'deg)',
'-moz-transform': 'rotate(' + deg + 'deg)'
WebkitTransform: val,
'-moz-transform': val
});
},
showDate: function (date)
Expand All @@ -634,26 +611,21 @@
{
this.$dtpElement.find('.dtp-actual-day').html(date.locale(this.params.lang).format('dddd'));
this.$dtpElement.find('.dtp-actual-month').html(date.locale(this.params.lang).format('MMM').toUpperCase());
this.$dtpElement.find('.dtp-actual-num').html(date.locale(this.params.lang).format('DD'));
this.$dtpElement.find('.dtp-actual-num').html(date.locale(this.params.lang).format('D'));
this.$dtpElement.find('.dtp-actual-year').html(date.locale(this.params.lang).format('YYYY'));
}
},
showTime: function (date)
{
if (date)
{
var minutes = date.minute();
var content = ((this.params.shortTime) ? date.format('hh') : date.format('HH')) + ':' + ((minutes.toString().length == 2) ? minutes : '0' + minutes) + ((this.params.shortTime) ? ' ' + date.format('A') : '');
var content = date.format(this.params.shortTime ? 'hh:mm A' : 'HH:mm');

if (this.params.date)
this.$dtpElement.find('.dtp-actual-time').html(content);
else
{
if (this.params.shortTime)
this.$dtpElement.find('.dtp-actual-day').html(date.format('A'));
else
this.$dtpElement.find('.dtp-actual-day').html('&nbsp;');

this.$dtpElement.find('.dtp-actual-day').html(this.params.shortTime ? date.format('A') : '&nbsp;');
this.$dtpElement.find('.dtp-actual-maxtime').html(content);
}
}
Expand Down Expand Up @@ -695,7 +667,7 @@
}
}
}
_calendar.days.push(moment(startOfMonth).locale(this.params.lang).date(i));
_calendar.days.push(startOfMonth.clone().locale(this.params.lang).date(i));
}
}

Expand All @@ -719,20 +691,21 @@
{
if (i % 7 == 0)
_template += '</tr><tr>';
_template += '<td data-date="' + moment(calendar.days[i]).locale(this.params.lang).format("D") + '">';
var day = moment(calendar.days[i]).locale(this.params.lang).format("D");
_template += '<td data-date="' + day + '">';
if (calendar.days[i] != 0)
{
if (this.isBeforeMaxDate(moment(calendar.days[i]), false, false) === false || this.isAfterMinDate(moment(calendar.days[i]), false, false) === false)
{
_template += '<span class="dtp-select-day">' + moment(calendar.days[i]).locale(this.params.lang).format("DD") + '</span>';
_template += '<span class="dtp-select-day">' + day + '</span>';
} else
{
if (moment(calendar.days[i]).locale(this.params.lang).format("DD") === moment(this.currentDate).locale(this.params.lang).format("DD"))
if (day === moment(this.currentDate).locale(this.params.lang).format("D"))
{
_template += '<a href="javascript:void(0);" class="dtp-select-day selected">' + moment(calendar.days[i]).locale(this.params.lang).format("DD") + '</a>';
_template += '<a href="javascript:void(0);" class="dtp-select-day selected">' + day + '</a>';
} else
{
_template += '<a href="javascript:void(0);" class="dtp-select-day">' + moment(calendar.days[i]).locale(this.params.lang).format("DD") + '</a>';
_template += '<a href="javascript:void(0);" class="dtp-select-day">' + day + '</a>';
}
}

Expand Down Expand Up @@ -815,16 +788,15 @@
toggleTime: function (value, isHours)
{
var result = false;
var _date = moment(this.currentDate);

if (isHours)
{
var _date = moment(this.currentDate);
_date.hour(this.convertHours(value)).minute(0).second(0);

result = !(this.isAfterMinDate(_date, true, false) === false || this.isBeforeMaxDate(_date, true, false) === false);
} else
{
var _date = moment(this.currentDate);
_date.minute(value).second(0);

result = !(this.isAfterMinDate(_date, true, true) === false || this.isBeforeMaxDate(_date, true, true) === false);
Expand Down Expand Up @@ -982,22 +954,22 @@
},
_onMonthBeforeClick: function ()
{
this.currentDate.subtract(1, 'months');
this.currentDate.subtract(1, 'M');
this.initDate(this.currentDate);
},
_onMonthAfterClick: function ()
{
this.currentDate.add(1, 'months');
this.currentDate.add(1, 'M');
this.initDate(this.currentDate);
},
_onYearBeforeClick: function ()
{
this.currentDate.subtract(1, 'years');
this.currentDate.subtract(1, 'y');
this.initDate(this.currentDate);
},
_onYearAfterClick: function ()
{
this.currentDate.add(1, 'years');
this.currentDate.add(1, 'y');
this.initDate(this.currentDate);
},
_onSelectDate: function (e)
Expand Down Expand Up @@ -1040,7 +1012,7 @@

if (this.params.shortTime === true && this.isPM())
{
this.currentDate.add(12, 'hours');
this.currentDate.add(12, 'h');
}

this.showTime(this.currentDate);
Expand Down Expand Up @@ -1092,7 +1064,7 @@

if (this.currentDate.hour() >= 12)
{
if (this.currentDate.subtract(12, 'hours'))
if (this.currentDate.subtract(12, 'h'))
this.showTime(this.currentDate);
}
this.toggleTime((this.currentView === 1));
Expand All @@ -1104,7 +1076,7 @@

if (this.currentDate.hour() < 12)
{
if (this.currentDate.add(12, 'hours'))
if (this.currentDate.add(12, 'h'))
this.showTime(this.currentDate);
}
this.toggleTime((this.currentView === 1));
Expand Down