Merge pull request #644 from ethaizone/patch-yearOffset

Fix yearOffset implement.
This commit is contained in:
Valeriy 2018-02-16 15:04:45 +05:00 committed by GitHub
commit 3c9e025af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1304,9 +1304,7 @@ var datetimepickerFactory = function ($) {
d.setDate(date.getDate()); d.setDate(date.getDate());
} }
if (options.yearOffset) { d.setFullYear(d.getFullYear());
d.setFullYear(d.getFullYear() + options.yearOffset);
}
if (!norecursion && options.defaultTime) { if (!norecursion && options.defaultTime) {
time = _this.strtotime(options.defaultTime); time = _this.strtotime(options.defaultTime);
@ -1478,7 +1476,12 @@ var datetimepickerFactory = function ($) {
}; };
_this.str = function () { _this.str = function () {
return dateHelper.formatDate(_this.currentTime, options.format); var format = options.format;
if (options.yearOffset) {
format = format.replace('Y', _this.currentTime.getFullYear() + options.yearOffset);
format = format.replace('y', String(_this.currentTime.getFullYear() + options.yearOffset).substring(2, 4));
}
return dateHelper.formatDate(_this.currentTime, format);
}; };
_this.currentTime = this.now(); _this.currentTime = this.now();
}; };
@ -1751,7 +1754,7 @@ var datetimepickerFactory = function ($) {
calendar.html(table); calendar.html(table);
month_picker.find('.xdsoft_label span').eq(0).text(options.i18n[globalLocale].months[_xdsoft_datetime.currentTime.getMonth()]); month_picker.find('.xdsoft_label span').eq(0).text(options.i18n[globalLocale].months[_xdsoft_datetime.currentTime.getMonth()]);
month_picker.find('.xdsoft_label span').eq(1).text(_xdsoft_datetime.currentTime.getFullYear()); month_picker.find('.xdsoft_label span').eq(1).text(_xdsoft_datetime.currentTime.getFullYear() + options.yearOffset);
// generate timebox // generate timebox
time = ''; time = '';
@ -1817,8 +1820,8 @@ var datetimepickerFactory = function ($) {
opt = ''; opt = '';
for (i = parseInt(options.yearStart, 10) + options.yearOffset; i <= parseInt(options.yearEnd, 10) + options.yearOffset; i += 1) { for (i = parseInt(options.yearStart, 10); i <= parseInt(options.yearEnd, 10); i += 1) {
opt += '<div class="xdsoft_option ' + (_xdsoft_datetime.currentTime.getFullYear() === i ? 'xdsoft_current' : '') + '" data-value="' + i + '">' + i + '</div>'; opt += '<div class="xdsoft_option ' + (_xdsoft_datetime.currentTime.getFullYear() === i ? 'xdsoft_current' : '') + '" data-value="' + i + '">' + (i + options.yearOffset) + '</div>';
} }
yearselect.children().eq(0) yearselect.children().eq(0)
.html(opt); .html(opt);
@ -2181,6 +2184,9 @@ var datetimepickerFactory = function ($) {
ct = options.value || ((input && input.val && input.val()) ? input.val() : ''); ct = options.value || ((input && input.val && input.val()) ? input.val() : '');
if (ct) { if (ct) {
ct = _xdsoft_datetime.strToDateTime(ct); ct = _xdsoft_datetime.strToDateTime(ct);
if (options.yearOffset) {
ct = new Date(ct.getFullYear() - options.yearOffset, ct.getMonth(), ct.getDate(), ct.getHours(), ct.getMinutes(), ct.getSeconds(), ct.getMilliseconds());
}
} else if (options.defaultDate) { } else if (options.defaultDate) {
ct = _xdsoft_datetime.strToDateTime(options.defaultDate); ct = _xdsoft_datetime.strToDateTime(options.defaultDate);
if (options.defaultTime) { if (options.defaultTime) {