Skip to content

Commit 514a536

Browse files
committed
Fix #22: Correct parseInt for older browsers
1 parent 82b61cd commit 514a536

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

CHANGE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Change Log: `php-date-formatter`
66
**Date:** 14-Apr-2020
77

88
- (enh #24): Correct date format error for characters containing `T`.
9+
- (enh #22): Correct `parseInt` for older browsers.
910

1011
## Version 1.3.5
1112

js/php-date-formatter.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
tzParts: /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
5555
tzClip: /[^-+\dA-Z]/g
5656
},
57+
getInt: function (str, radix) {
58+
return parseInt(str, (radix ? radix : 10));
59+
},
5760
compare: function (str1, str2) {
5861
return typeof (str1) === 'string' && typeof (str2) === 'string' && str1.toLowerCase() === str2.toLowerCase();
5962
},
@@ -131,7 +134,7 @@
131134
return vDate;
132135
}
133136
if (vFormat === 'U') {
134-
i = parseInt(vDate);
137+
i = $h.getInt(vDate);
135138
return i ? new Date(i * 1000) : vDate;
136139
}
137140
switch (typeof vDate) {
@@ -154,13 +157,13 @@
154157
vDateParts = vDate.replace(self.separators, '\0').split('\0');
155158
for (i = 0; i < vDateParts.length; i++) {
156159
vDatePart = vDateParts[i];
157-
iDatePart = parseInt(vDatePart);
160+
iDatePart = $h.getInt(vDatePart);
158161
switch (vFormatParts[i]) {
159162
case 'y':
160163
case 'Y':
161164
if (iDatePart) {
162165
len = vDatePart.length;
163-
out.year = len === 2 ? parseInt((iDatePart < 70 ? '20' : '19') + vDatePart) : iDatePart;
166+
out.year = len === 2 ? $h.getInt((iDatePart < 70 ? '20' : '19') + vDatePart) : iDatePart;
164167
} else {
165168
return null;
166169
}
@@ -271,7 +274,7 @@
271274
for (i = 0; i < vParts.length; i++) {
272275
vDigit = 2;
273276
iPart = vParts[i];
274-
iSec = parseInt(iPart.substr(0, 2));
277+
iSec = $h.getInt(iPart.substr(0, 2));
275278
if (isNaN(iSec)) {
276279
return null;
277280
}
@@ -294,7 +297,7 @@
294297
vYear = vDate.getFullYear();
295298
len = iPart.length;
296299
vDigit = len < 4 ? len : 4;
297-
vYear = parseInt(len < 4 ? vYear.toString().substr(0, 4 - len) + iPart : iPart.substr(0, 4));
300+
vYear = $h.getInt(len < 4 ? vYear.toString().substr(0, 4 - len) + iPart : iPart.substr(0, 4));
298301
if (!vYear) {
299302
return null;
300303
}
@@ -637,7 +640,7 @@
637640
}
638641
str = self.parseFormat(vChar, vDate);
639642
if (i !== (len - 1) && self.intParts.test(vChar) && vFormat.charAt(i + 1) === 'S') {
640-
n = parseInt(str) || 0;
643+
n = $h.getInt(str) || 0;
641644
str += self.dateSettings.ordinal(n);
642645
}
643646
vDateStr += str;

js/php-date-formatter.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)