|
1 | 1 | /* |
2 | 2 | * Bootstrap 4+ Persian Date Time Picker jQuery Plugin |
3 | | - * version : 3.10.0 |
| 3 | + * version : 3.10.1 |
4 | 4 | * https://github.com/Mds92/MD.BootstrapPersianDateTimePicker |
5 | 5 | * |
6 | 6 | * |
|
14 | 14 |
|
15 | 15 | // #region jalali calendar |
16 | 16 |
|
17 | | - function toJalaali(gy, gm, gd) { |
| 17 | + function toJalali(gy, gm, gd) { |
18 | 18 | return d2j(g2d(gy, gm, gd)); |
19 | 19 | } |
20 | 20 |
|
21 | 21 | function toGregorian(jy, jm, jd) { |
22 | 22 | return d2g(j2d(jy, jm, jd)); |
23 | 23 | } |
24 | 24 |
|
25 | | - function isValidJalaaliDate(jy, jm, jd) { |
| 25 | + function isValidJalaliDate(jy, jm, jd) { |
26 | 26 | return jy >= -61 && jy <= 3177 && |
27 | 27 | jm >= 1 && jm <= 12 && |
28 | | - jd >= 1 && jd <= jalaaliMonthLength(jy, jm); |
| 28 | + jd >= 1 && jd <= jalaliMonthLength(jy, jm); |
29 | 29 | } |
30 | 30 |
|
31 | | - function isLeapJalaaliYear(jy) { |
| 31 | + function isLeapJalaliYear(jy) { |
32 | 32 | return jalCal(jy).leap === 0; |
33 | 33 | } |
34 | 34 |
|
35 | | - function jalaaliMonthLength(jy, jm) { |
| 35 | + function jalaliMonthLength(jy, jm) { |
36 | 36 | if (jm <= 6) return 31; |
37 | 37 | if (jm <= 11) return 30; |
38 | | - if (isLeapJalaaliYear(jy)) return 30; |
| 38 | + if (isLeapJalaliYear(jy)) return 30; |
39 | 39 | return 29; |
40 | 40 | } |
41 | 41 |
|
42 | 42 | function jalCal(jy) { |
43 | | - // Jalaali years starting the 33-year rule. |
| 43 | + // Jalali years starting the 33-year rule. |
44 | 44 | var breaks = [-61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210, 1635, 2060, 2097, 2192, 2262, 2324, 2394, 2456, 3178], |
45 | 45 | bl = breaks.length, |
46 | 46 | gy = jy + 621, |
|
53 | 53 | i; |
54 | 54 |
|
55 | 55 | if (jy < jp || jy >= breaks[bl - 1]) |
56 | | - throw new Error('Invalid Jalaali year ' + jy); |
| 56 | + throw new Error('Invalid Jalali year ' + jy); |
57 | 57 |
|
58 | | - // Find the limiting years for the Jalaali year jy. |
| 58 | + // Find the limiting years for the Jalali year jy. |
59 | 59 | for (i = 1; i < bl; i += 1) { |
60 | 60 | jm = breaks[i]; |
61 | 61 | jump = jm - jp; |
|
67 | 67 | n = jy - jp; |
68 | 68 |
|
69 | 69 | // Find the number of leap years from AD 621 to the beginning |
70 | | - // of the current Jalaali year in the Persian calendar. |
| 70 | + // of the current Jalali year in the Persian calendar. |
71 | 71 | leapJ = leapJ + div(n, 33) * 8 + div(mod(n, 33) + 3, 4); |
72 | 72 | if (mod(jump, 33) === 4 && jump - n === 4) |
73 | 73 | leapJ += 1; |
|
122 | 122 | k -= 186; |
123 | 123 | } |
124 | 124 | } else { |
125 | | - // Previous Jalaali year. |
| 125 | + // Previous Jalali year. |
126 | 126 | jy -= 1; |
127 | 127 | k += 179; |
128 | 128 | if (r.leap === 1) |
|
196 | 196 | `; |
197 | 197 |
|
198 | 198 |
|
199 | | - var popverHtmlTemplate = ` |
| 199 | + var popoverHtmlTemplate = ` |
200 | 200 | <div class="popover mds-bootstrap-persian-datetime-picker-popover" role="tooltip" ${mdDatePickerElementFlag}> |
201 | 201 | <div class="arrow"></div> |
202 | 202 | <h3 class="popover-header text-center" data-name="mds-datetimepicker-title"></h3> |
|
805 | 805 | } |
806 | 806 |
|
807 | 807 | function getDateTimeJsonPersian1(dateTime) { |
808 | | - var persianDate = toJalaali(dateTime.getFullYear(), dateTime.getMonth() + 1, dateTime.getDate()); |
| 808 | + var persianDate = toJalali(dateTime.getFullYear(), dateTime.getMonth() + 1, dateTime.getDate()); |
809 | 809 | return { |
810 | 810 | year: persianDate.jy, |
811 | 811 | month: persianDate.jm, |
|
826 | 826 | } |
827 | 827 |
|
828 | 828 | function isLeapYear(persianYear) { |
829 | | - return isLeapJalaaliYear(persianYear); |
| 829 | + return isLeapJalaliYear(persianYear); |
830 | 830 | } |
831 | 831 |
|
832 | 832 | function getDaysInMonthPersian(year, month) { |
|
965 | 965 | return getDateTime1(dateTimeJsonPersian.year, dateTimeJsonPersian.month, 1); |
966 | 966 | } |
967 | 967 |
|
968 | | - function parsePersianDateTime(persianDateTimeInString, dateSeperatorPattern) { |
969 | | - if (!dateSeperatorPattern) dateSeperatorPattern = "\/|-"; |
970 | | - dateSeperatorPattern = new RegExp(dateSeperatorPattern, 'img'); |
| 968 | + function parsePersianDateTime(persianDateTimeInString, dateSeparatorPattern) { |
| 969 | + if (!dateSeparatorPattern) dateSeparatorPattern = "\/|-"; |
| 970 | + dateSeparatorPattern = new RegExp(dateSeparatorPattern, 'img'); |
971 | 971 | persianDateTimeInString = toEnglishNumber(persianDateTimeInString); |
972 | 972 |
|
973 | 973 | var month = 0, |
|
976 | 976 | hour = 0, |
977 | 977 | minute = 0, |
978 | 978 | second = 0, |
979 | | - miliSecond = 0, |
| 979 | + millisecond = 0, |
980 | 980 | amPmEnum = amPm.none, |
981 | | - containMonthSeperator = dateSeperatorPattern.test(persianDateTimeInString); |
| 981 | + containMonthSeparator = dateSeparatorPattern.test(persianDateTimeInString); |
982 | 982 |
|
983 | 983 | persianDateTimeInString = persianDateTimeInString.replace(/ /img, ' '); |
984 | 984 | persianDateTimeInString = persianDateTimeInString.replace(/\s+/img, '-'); |
985 | 985 | persianDateTimeInString = persianDateTimeInString.replace(/\\/img, '-'); |
986 | 986 | persianDateTimeInString = persianDateTimeInString.replace(/ك/img, 'ک'); |
987 | 987 | persianDateTimeInString = persianDateTimeInString.replace(/ي/img, 'ی'); |
988 | | - persianDateTimeInString = persianDateTimeInString.replace(dateSeperatorPattern, '-'); |
| 988 | + persianDateTimeInString = persianDateTimeInString.replace(dateSeparatorPattern, '-'); |
989 | 989 | persianDateTimeInString = '-' + persianDateTimeInString + '-'; |
990 | 990 |
|
991 | 991 | // بدست آوردن ب.ظ یا ق.ظ |
992 | 992 | if (persianDateTimeInString.indexOf('ق.ظ') > -1) |
993 | | - amPmEnum = amPmEnum.AM; |
| 993 | + amPmEnum = amPm.AM; |
994 | 994 | else if (persianDateTimeInString.indexOf('ب.ظ') > -1) |
995 | | - amPmEnum = amPmEnum.PM; |
| 995 | + amPmEnum = amPm.PM; |
996 | 996 |
|
997 | 997 | if (persianDateTimeInString.indexOf(':') > -1) // رشته ورودی شامل ساعت نیز هست |
998 | 998 | { |
999 | 999 | persianDateTimeInString = persianDateTimeInString.replace(/-*:-*/img, ':'); |
1000 | 1000 | hour = (persianDateTimeInString.match(/-\d{1,2}(?=:)/img)[0]).replace(/\D+/, ''); |
1001 | | - var minuteAndSecondAndMiliSecondMatch = persianDateTimeInString.match(/:\d{1,2}(?=:?)/img); |
1002 | | - minute = minuteAndSecondAndMiliSecondMatch[0].replace(/\D+/, ''); |
1003 | | - if (minuteAndSecondAndMiliSecondMatch[1] != undefined) |
1004 | | - second = minuteAndSecondAndMiliSecondMatch[1].replace(/\D+/, ''); |
1005 | | - if (minuteAndSecondAndMiliSecondMatch[2] != undefined) |
1006 | | - miliSecond = minuteAndSecondAndMiliSecondMatch[2].replace(/\D+/, ''); |
| 1001 | + var minuteAndSecondAndMillisecondMatch = persianDateTimeInString.match(/:\d{1,2}(?=:?)/img); |
| 1002 | + minute = minuteAndSecondAndMillisecondMatch[0].replace(/\D+/, ''); |
| 1003 | + if (minuteAndSecondAndMillisecondMatch[1] != undefined) |
| 1004 | + second = minuteAndSecondAndMillisecondMatch[1].replace(/\D+/, ''); |
| 1005 | + if (minuteAndSecondAndMillisecondMatch[2] != undefined) |
| 1006 | + millisecond = minuteAndSecondAndMillisecondMatch[2].replace(/\D+/, ''); |
1007 | 1007 | } |
1008 | 1008 |
|
1009 | | - if (containMonthSeperator) { |
| 1009 | + if (containMonthSeparator) { |
1010 | 1010 | var monthDayMath = persianDateTimeInString.match(/-\d{1,2}(?=-\d{1,2}[^:]|-)/img); |
1011 | 1011 |
|
1012 | 1012 | // بدست آوردن ماه |
|
1049 | 1049 | var numericHour = Number(hour); |
1050 | 1050 | var numericMinute = Number(minute); |
1051 | 1051 | var numericSecond = Number(second); |
1052 | | - var numericMiliSecond = Number(miliSecond); |
| 1052 | + var numericMillisecond = Number(millisecond); |
1053 | 1053 |
|
1054 | 1054 | if (numericYear <= 0) |
1055 | 1055 | numericYear = persianDateTime[0]; |
|
1061 | 1061 | numericDay = persianDateTime[2]; |
1062 | 1062 |
|
1063 | 1063 | switch (amPmEnum) { |
1064 | | - case amPmEnum.PM: |
| 1064 | + case amPm.PM: |
1065 | 1065 | if (numericHour < 12) |
1066 | 1066 | numericHour = numericHour + 12; |
1067 | 1067 | break; |
1068 | | - case amPmEnum.AM: |
1069 | | - case amPmEnum.None: |
| 1068 | + case amPm.AM: |
| 1069 | + case amPm.None: |
1070 | 1070 | break; |
1071 | 1071 | } |
1072 | 1072 |
|
1073 | | - return getDateTime1(numericYear, numericMonth, numericDay, numericHour, numericMinute, numericSecond, numericMiliSecond); |
| 1073 | + return getDateTime1(numericYear, numericMonth, numericDay, numericHour, numericMinute, numericSecond, numericMillisecond); |
1074 | 1074 | } |
1075 | 1075 |
|
1076 | 1076 | function parseGregorianDateTime(gregorianDateTimeString) { |
|
1368 | 1368 | selectMonth11ButtonCssClass: '', |
1369 | 1369 | selectMonth12ButtonCssClass: '', |
1370 | 1370 | }, |
1371 | | - holiDaysDateNumbers = [], |
| 1371 | + holidaysDateNumbers = [], |
1372 | 1372 | disabledDatesNumber = [], |
1373 | 1373 | specialDatesNumber = [], |
1374 | 1374 | disableBeforeDateTimeJson = {}, |
|
1402 | 1402 | selectedDateToShowTemp = getClonedDate(selectedDateToShow); |
1403 | 1403 | } |
1404 | 1404 | for (i = 0; i < setting.holiDays.length; i++) { |
1405 | | - holiDaysDateNumbers.push(convertToNumber1(getDateTimeJson1(setting.holiDays[i]))); |
| 1405 | + holidaysDateNumbers.push(convertToNumber1(getDateTimeJson1(setting.holiDays[i]))); |
1406 | 1406 | } |
1407 | 1407 | for (i = 0; i < setting.disabledDates.length; i++) { |
1408 | 1408 | disabledDatesNumber.push(convertToNumber1(getDateTimeJson1(setting.disabledDates[i]))); |
|
1433 | 1433 | selectedDateToShowTemp = getClonedDate(selectedDateToShow); |
1434 | 1434 | } |
1435 | 1435 | for (i = 0; i < setting.holiDays.length; i++) { |
1436 | | - holiDaysDateNumbers.push(convertToNumber1(getDateTimeJsonPersian1(setting.holiDays[i]))); |
| 1436 | + holidaysDateNumbers.push(convertToNumber1(getDateTimeJsonPersian1(setting.holiDays[i]))); |
1437 | 1437 | } |
1438 | 1438 | for (i = 0; i < setting.disabledDates.length; i++) { |
1439 | 1439 | disabledDatesNumber.push(convertToNumber1(getDateTimeJsonPersian1(setting.disabledDates[i]))); |
|
1540 | 1540 | } |
1541 | 1541 |
|
1542 | 1542 | // روزهای تعطیل |
1543 | | - for (j = 0; j < holiDaysDateNumbers.length; j++) { |
1544 | | - if (holiDaysDateNumbers[j] != currentDateNumber) continue; |
| 1543 | + for (j = 0; j < holidaysDateNumbers.length; j++) { |
| 1544 | + if (holidaysDateNumbers[j] != currentDateNumber) continue; |
1545 | 1545 | $td.addClass('text-danger'); |
1546 | 1546 | break; |
1547 | 1547 | } |
|
2032 | 2032 | else if (!setting.enableTimePicker && !setting.textFormat) setting.textFormat = 'yyyy/MM/dd'; |
2033 | 2033 | if (setting.enableTimePicker && !setting.dateFormat) setting.dateFormat = 'yyyy/MM/dd HH:mm:ss'; |
2034 | 2034 | else if (!setting.enableTimePicker && !setting.dateFormat) setting.dateFormat = 'yyyy/MM/dd'; |
2035 | | - var uniqeId = new Date().getTime(); |
| 2035 | + var uniqueId = new Date().getTime(); |
2036 | 2036 | $this.data(mdPluginName, setting); |
2037 | | - $this.attr('data-uniqueid', uniqeId); |
| 2037 | + $this.attr('data-uniqueid', uniqueId); |
2038 | 2038 | if (setting.rangeSelector && setting.selectedRangeDate != undefined) { |
2039 | 2039 | setSelectedRangeData(setting); |
2040 | 2040 | triggerChangeCalling = false; |
|
2053 | 2053 | placement: setting.placement, |
2054 | 2054 | title: ' ', |
2055 | 2055 | trigger: 'manual', |
2056 | | - template: popverHtmlTemplate, |
| 2056 | + template: popoverHtmlTemplate, |
2057 | 2057 | sanitize: false, |
2058 | 2058 | }).on(setting.trigger, function () { |
2059 | 2059 | triggerStart = true; |
|
2083 | 2083 | setting.selectedDateToShow = setting.selectedDate != undefined ? getClonedDate(setting.selectedDate) : new Date(); |
2084 | 2084 | var calendarHtml = getDateTimePickerHtml(setting); |
2085 | 2085 | $(mdDatePickerElementSelector).find('[data-name="mds-datetimepicker-body"]').html(calendarHtml); |
2086 | | - $(mdDatePickerElementSelector).find('[data-buttonselector]').attr('data-buttonselector', uniqeId); |
| 2086 | + $(mdDatePickerElementSelector).find('[data-buttonselector]').attr('data-buttonselector', uniqueId); |
2087 | 2087 | $(mdDatePickerElementSelector).modal('show'); |
2088 | 2088 | }); |
2089 | 2089 | } |
|
0 commit comments