Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mds92 committed Feb 26, 2021
1 parent 4a43d76 commit 9981ec3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions dist/jquery.md.bootstrap.datetimepicker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.md.bootstrap.datetimepicker.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.md.bootstrap.datetimepicker.style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "md.bootstrappersiandatetimepicker",
"version": "3.10.0",
"version": "3.10.1",
"description": "Persian Date Time Picker with jQuery 3+ & Bootstrap 4+",
"license": "MIT",
"moduleResolution": "node",
Expand All @@ -16,7 +16,7 @@
},
"homepage": "https://github.com/Mds92/MD.BootstrapPersianDateTimePicker",
"dependencies": {
"@popperjs/core": "^2.4.4",
"@popperjs/core": "^2.8.5",
"bootstrap": "^4.5.3",
"jquery": "^3.5.1"
},
Expand Down
88 changes: 44 additions & 44 deletions src/jquery.md.bootstrap.datetimepicker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Bootstrap 4+ Persian Date Time Picker jQuery Plugin
* version : 3.10.0
* version : 3.10.1
* https://github.com/Mds92/MD.BootstrapPersianDateTimePicker
*
*
Expand All @@ -14,33 +14,33 @@

// #region jalali calendar

function toJalaali(gy, gm, gd) {
function toJalali(gy, gm, gd) {
return d2j(g2d(gy, gm, gd));
}

function toGregorian(jy, jm, jd) {
return d2g(j2d(jy, jm, jd));
}

function isValidJalaaliDate(jy, jm, jd) {
function isValidJalaliDate(jy, jm, jd) {
return jy >= -61 && jy <= 3177 &&
jm >= 1 && jm <= 12 &&
jd >= 1 && jd <= jalaaliMonthLength(jy, jm);
jd >= 1 && jd <= jalaliMonthLength(jy, jm);
}

function isLeapJalaaliYear(jy) {
function isLeapJalaliYear(jy) {
return jalCal(jy).leap === 0;
}

function jalaaliMonthLength(jy, jm) {
function jalaliMonthLength(jy, jm) {
if (jm <= 6) return 31;
if (jm <= 11) return 30;
if (isLeapJalaaliYear(jy)) return 30;
if (isLeapJalaliYear(jy)) return 30;
return 29;
}

function jalCal(jy) {
// Jalaali years starting the 33-year rule.
// Jalali years starting the 33-year rule.
var breaks = [-61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210, 1635, 2060, 2097, 2192, 2262, 2324, 2394, 2456, 3178],
bl = breaks.length,
gy = jy + 621,
Expand All @@ -53,9 +53,9 @@
i;

if (jy < jp || jy >= breaks[bl - 1])
throw new Error('Invalid Jalaali year ' + jy);
throw new Error('Invalid Jalali year ' + jy);

// Find the limiting years for the Jalaali year jy.
// Find the limiting years for the Jalali year jy.
for (i = 1; i < bl; i += 1) {
jm = breaks[i];
jump = jm - jp;
Expand All @@ -67,7 +67,7 @@
n = jy - jp;

// Find the number of leap years from AD 621 to the beginning
// of the current Jalaali year in the Persian calendar.
// of the current Jalali year in the Persian calendar.
leapJ = leapJ + div(n, 33) * 8 + div(mod(n, 33) + 3, 4);
if (mod(jump, 33) === 4 && jump - n === 4)
leapJ += 1;
Expand Down Expand Up @@ -122,7 +122,7 @@
k -= 186;
}
} else {
// Previous Jalaali year.
// Previous Jalali year.
jy -= 1;
k += 179;
if (r.leap === 1)
Expand Down Expand Up @@ -196,7 +196,7 @@
`;


var popverHtmlTemplate = `
var popoverHtmlTemplate = `
<div class="popover mds-bootstrap-persian-datetime-picker-popover" role="tooltip" ${mdDatePickerElementFlag}>
<div class="arrow"></div>
<h3 class="popover-header text-center" data-name="mds-datetimepicker-title"></h3>
Expand Down Expand Up @@ -805,7 +805,7 @@
}

function getDateTimeJsonPersian1(dateTime) {
var persianDate = toJalaali(dateTime.getFullYear(), dateTime.getMonth() + 1, dateTime.getDate());
var persianDate = toJalali(dateTime.getFullYear(), dateTime.getMonth() + 1, dateTime.getDate());
return {
year: persianDate.jy,
month: persianDate.jm,
Expand All @@ -826,7 +826,7 @@
}

function isLeapYear(persianYear) {
return isLeapJalaaliYear(persianYear);
return isLeapJalaliYear(persianYear);
}

function getDaysInMonthPersian(year, month) {
Expand Down Expand Up @@ -965,9 +965,9 @@
return getDateTime1(dateTimeJsonPersian.year, dateTimeJsonPersian.month, 1);
}

function parsePersianDateTime(persianDateTimeInString, dateSeperatorPattern) {
if (!dateSeperatorPattern) dateSeperatorPattern = "\/|-";
dateSeperatorPattern = new RegExp(dateSeperatorPattern, 'img');
function parsePersianDateTime(persianDateTimeInString, dateSeparatorPattern) {
if (!dateSeparatorPattern) dateSeparatorPattern = "\/|-";
dateSeparatorPattern = new RegExp(dateSeparatorPattern, 'img');
persianDateTimeInString = toEnglishNumber(persianDateTimeInString);

var month = 0,
Expand All @@ -976,37 +976,37 @@
hour = 0,
minute = 0,
second = 0,
miliSecond = 0,
millisecond = 0,
amPmEnum = amPm.none,
containMonthSeperator = dateSeperatorPattern.test(persianDateTimeInString);
containMonthSeparator = dateSeparatorPattern.test(persianDateTimeInString);

persianDateTimeInString = persianDateTimeInString.replace(/&nbsp;/img, ' ');
persianDateTimeInString = persianDateTimeInString.replace(/\s+/img, '-');
persianDateTimeInString = persianDateTimeInString.replace(/\\/img, '-');
persianDateTimeInString = persianDateTimeInString.replace(/ك/img, 'ک');
persianDateTimeInString = persianDateTimeInString.replace(/ي/img, 'ی');
persianDateTimeInString = persianDateTimeInString.replace(dateSeperatorPattern, '-');
persianDateTimeInString = persianDateTimeInString.replace(dateSeparatorPattern, '-');
persianDateTimeInString = '-' + persianDateTimeInString + '-';

// بدست آوردن ب.ظ یا ق.ظ
if (persianDateTimeInString.indexOf('ق.ظ') > -1)
amPmEnum = amPmEnum.AM;
amPmEnum = amPm.AM;
else if (persianDateTimeInString.indexOf('ب.ظ') > -1)
amPmEnum = amPmEnum.PM;
amPmEnum = amPm.PM;

if (persianDateTimeInString.indexOf(':') > -1) // رشته ورودی شامل ساعت نیز هست
{
persianDateTimeInString = persianDateTimeInString.replace(/-*:-*/img, ':');
hour = (persianDateTimeInString.match(/-\d{1,2}(?=:)/img)[0]).replace(/\D+/, '');
var minuteAndSecondAndMiliSecondMatch = persianDateTimeInString.match(/:\d{1,2}(?=:?)/img);
minute = minuteAndSecondAndMiliSecondMatch[0].replace(/\D+/, '');
if (minuteAndSecondAndMiliSecondMatch[1] != undefined)
second = minuteAndSecondAndMiliSecondMatch[1].replace(/\D+/, '');
if (minuteAndSecondAndMiliSecondMatch[2] != undefined)
miliSecond = minuteAndSecondAndMiliSecondMatch[2].replace(/\D+/, '');
var minuteAndSecondAndMillisecondMatch = persianDateTimeInString.match(/:\d{1,2}(?=:?)/img);
minute = minuteAndSecondAndMillisecondMatch[0].replace(/\D+/, '');
if (minuteAndSecondAndMillisecondMatch[1] != undefined)
second = minuteAndSecondAndMillisecondMatch[1].replace(/\D+/, '');
if (minuteAndSecondAndMillisecondMatch[2] != undefined)
millisecond = minuteAndSecondAndMillisecondMatch[2].replace(/\D+/, '');
}

if (containMonthSeperator) {
if (containMonthSeparator) {
var monthDayMath = persianDateTimeInString.match(/-\d{1,2}(?=-\d{1,2}[^:]|-)/img);

// بدست آوردن ماه
Expand Down Expand Up @@ -1049,7 +1049,7 @@
var numericHour = Number(hour);
var numericMinute = Number(minute);
var numericSecond = Number(second);
var numericMiliSecond = Number(miliSecond);
var numericMillisecond = Number(millisecond);

if (numericYear <= 0)
numericYear = persianDateTime[0];
Expand All @@ -1061,16 +1061,16 @@
numericDay = persianDateTime[2];

switch (amPmEnum) {
case amPmEnum.PM:
case amPm.PM:
if (numericHour < 12)
numericHour = numericHour + 12;
break;
case amPmEnum.AM:
case amPmEnum.None:
case amPm.AM:
case amPm.None:
break;
}

return getDateTime1(numericYear, numericMonth, numericDay, numericHour, numericMinute, numericSecond, numericMiliSecond);
return getDateTime1(numericYear, numericMonth, numericDay, numericHour, numericMinute, numericSecond, numericMillisecond);
}

function parseGregorianDateTime(gregorianDateTimeString) {
Expand Down Expand Up @@ -1368,7 +1368,7 @@
selectMonth11ButtonCssClass: '',
selectMonth12ButtonCssClass: '',
},
holiDaysDateNumbers = [],
holidaysDateNumbers = [],
disabledDatesNumber = [],
specialDatesNumber = [],
disableBeforeDateTimeJson = {},
Expand Down Expand Up @@ -1402,7 +1402,7 @@
selectedDateToShowTemp = getClonedDate(selectedDateToShow);
}
for (i = 0; i < setting.holiDays.length; i++) {
holiDaysDateNumbers.push(convertToNumber1(getDateTimeJson1(setting.holiDays[i])));
holidaysDateNumbers.push(convertToNumber1(getDateTimeJson1(setting.holiDays[i])));
}
for (i = 0; i < setting.disabledDates.length; i++) {
disabledDatesNumber.push(convertToNumber1(getDateTimeJson1(setting.disabledDates[i])));
Expand Down Expand Up @@ -1433,7 +1433,7 @@
selectedDateToShowTemp = getClonedDate(selectedDateToShow);
}
for (i = 0; i < setting.holiDays.length; i++) {
holiDaysDateNumbers.push(convertToNumber1(getDateTimeJsonPersian1(setting.holiDays[i])));
holidaysDateNumbers.push(convertToNumber1(getDateTimeJsonPersian1(setting.holiDays[i])));
}
for (i = 0; i < setting.disabledDates.length; i++) {
disabledDatesNumber.push(convertToNumber1(getDateTimeJsonPersian1(setting.disabledDates[i])));
Expand Down Expand Up @@ -1540,8 +1540,8 @@
}

// روزهای تعطیل
for (j = 0; j < holiDaysDateNumbers.length; j++) {
if (holiDaysDateNumbers[j] != currentDateNumber) continue;
for (j = 0; j < holidaysDateNumbers.length; j++) {
if (holidaysDateNumbers[j] != currentDateNumber) continue;
$td.addClass('text-danger');
break;
}
Expand Down Expand Up @@ -2032,9 +2032,9 @@
else if (!setting.enableTimePicker && !setting.textFormat) setting.textFormat = 'yyyy/MM/dd';
if (setting.enableTimePicker && !setting.dateFormat) setting.dateFormat = 'yyyy/MM/dd HH:mm:ss';
else if (!setting.enableTimePicker && !setting.dateFormat) setting.dateFormat = 'yyyy/MM/dd';
var uniqeId = new Date().getTime();
var uniqueId = new Date().getTime();
$this.data(mdPluginName, setting);
$this.attr('data-uniqueid', uniqeId);
$this.attr('data-uniqueid', uniqueId);
if (setting.rangeSelector && setting.selectedRangeDate != undefined) {
setSelectedRangeData(setting);
triggerChangeCalling = false;
Expand All @@ -2053,7 +2053,7 @@
placement: setting.placement,
title: ' ',
trigger: 'manual',
template: popverHtmlTemplate,
template: popoverHtmlTemplate,
sanitize: false,
}).on(setting.trigger, function () {
triggerStart = true;
Expand Down Expand Up @@ -2083,7 +2083,7 @@
setting.selectedDateToShow = setting.selectedDate != undefined ? getClonedDate(setting.selectedDate) : new Date();
var calendarHtml = getDateTimePickerHtml(setting);
$(mdDatePickerElementSelector).find('[data-name="mds-datetimepicker-body"]').html(calendarHtml);
$(mdDatePickerElementSelector).find('[data-buttonselector]').attr('data-buttonselector', uniqeId);
$(mdDatePickerElementSelector).find('[data-buttonselector]').attr('data-buttonselector', uniqueId);
$(mdDatePickerElementSelector).modal('show');
});
}
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
banner: `
Bootstrap 4+ Persian Date Time Picker jQuery Plugin
https://github.com/Mds92/MD.BootstrapPersianDateTimePicker
version : 3.10.0
version : 3.10.1
Written By Mohammad Dayyan, Mordad 1397 - 1400
[email protected] - @mdssoft
Expand Down

0 comments on commit 9981ec3

Please sign in to comment.