Skip to content

Commit 4324f6e

Browse files
committed
Merge branch 'master' of github.com:kvz/phpjs
Conflicts: functions/datetime/strtotime.js
2 parents 00fd55b + 3a9f259 commit 4324f6e

34 files changed

+110
-80
lines changed

functions/array/shuffle.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function shuffle(inputArr) {
1313
// % note 1: property deletion is supported. Note that we intend to implement the PHP
1414
// % note 1: behavior by default if IE ever does allow it; only gives shallow copy since
1515
// % note 1: is by reference in PHP anyways
16+
// * test: skip
1617
// * example 1: ini_set('phpjs.strictForIn', true);
1718
// * example 2: var data = {5:'a', 2:'3', 3:'c', 4:5, 'q':5};
1819
// * example 1: shuffle(data);

functions/ctype/ctype_cntrl.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ function ctype_cntrl(text) {
33
// + original by: Brett Zamir (http://brett-zamir.me)
44
// - depends on: setlocale
55
// * example 1: ctype_cntrl('\u0020');
6-
// * returns 1: true
6+
// * returns 1: false
7+
// * example 2: ctype_cntrl('\u001F');
8+
// * returns 2: true
79
if (typeof text !== 'string') {
810
return false;
911
}

functions/datetime/date_parse.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ function date_parse(date) {
99
this.php_js = this.php_js || {};
1010
// END REDUNDANT
1111

12-
var warningsOffset = this.php_js.warnings ? this.php_js.warnings.length : null;
13-
var errorsOffset = this.php_js.errors ? this.php_js.errors.length : null;
12+
var ts,
13+
warningsOffset = this.php_js.warnings ? this.php_js.warnings.length : null,
14+
errorsOffset = this.php_js.errors ? this.php_js.errors.length : null;
1415

1516
try {
16-
var ts = this.strtotime(date);
17+
this.php_js.date_parse_state = true; // Allow strtotime to return a decimal (which it normally does not)
18+
ts = this.strtotime(date);
19+
this.php_js.date_parse_state = false;
1720
} finally {
1821
if (!ts) {
1922
return false;
@@ -35,7 +38,7 @@ function date_parse(date) {
3538
retObj.minute = dt.getMinutes();
3639
retObj.second = dt.getSeconds();
3740
retObj.fraction = parseFloat('0.' + dt.getMilliseconds());
38-
retObj.is_localtime = dt.getTimezoneOffset !== 0;
41+
retObj.is_localtime = dt.getTimezoneOffset() !== 0;
3942

4043
return retObj;
4144
}

functions/datetime/gettimeofday.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ function gettimeofday(return_float) {
66
// + revised by: Theriault
77
// * example 1: gettimeofday();
88
// * returns 1: {sec: 12, usec: 153000, minuteswest: -480, dsttime: 0}
9-
// * example 1: gettimeofday(true);
10-
// * returns 1: 1238748978.49
9+
// * example 2: gettimeofday(true);
10+
// * returns 2: 1238748978.49
1111
var t = new Date(),
1212
y = 0;
1313

functions/datetime/idate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function idate(format, timestamp) {
66
// + improved by: Theriault
77
// + derived from: date
88
// + derived from: gettimeofday
9-
// * example 1: idate('y');
9+
// * example 1: idate('y', 1255633200);
1010
// * returns 1: 9
1111
if (format === undefined) {
1212
throw 'idate() expects at least 1 parameter, 0 given';

functions/datetime/strptime.js

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function strptime(dateStr, format) {
44
// + based on: strftime
55
// - depends on: setlocale
66
// - depends on: array_map
7-
// * test: skip
7+
// * test: skip
88
// * example 1: strptime('20091112222135', '%Y%m%d%H%M%S'); // Return value will depend on date and locale
99
// * returns 1: {tm_sec: 35, tm_min: 21, tm_hour: 22, tm_mday: 12, tm_mon: 10, tm_year: 109, tm_wday: 4, tm_yday: 315, unparsed: ''}
1010
// * example 1: strptime('2009extra', '%Y');
@@ -15,39 +15,41 @@ function strptime(dateStr, format) {
1515
// Needs more thorough testing and examples
1616

1717
var retObj = {
18-
tm_sec: 0,
19-
tm_min: 0,
20-
tm_hour: 0,
21-
tm_mday: 0,
22-
tm_mon: 0,
23-
tm_year: 0,
24-
tm_wday: 0,
25-
tm_yday: 0,
26-
unparsed: ''
27-
},
28-
that = this,
29-
amPmOffset = 0,
30-
prevHour = false,
31-
_date = function() {
32-
var o = retObj;
33-
// We set date to at least 1 to ensure year or month doesn't go backwards
34-
return _reset(new Date(Date.UTC(o.tm_year + 1900, o.tm_mon, o.tm_mday || 1, o.tm_hour, o.tm_min, o.tm_sec)), o.tm_mday);
35-
};
36-
_reset = function(dateObj, realMday) {
37-
// realMday is to allow for a value of 0 in return results (but without
38-
// messing up the Date() object)
39-
var o = retObj;
40-
var d = dateObj;
41-
o.tm_sec = d.getUTCSeconds();
42-
o.tm_min = d.getUTCMinutes();
43-
o.tm_hour = d.getUTCHours();
44-
o.tm_mday = realMday === 0 ? realMday : d.getUTCDate();
45-
o.tm_mon = d.getUTCMonth();
46-
o.tm_year = d.getUTCFullYear() - 1900;
47-
o.tm_wday = realMday === 0 ? (d.getUTCDay() > 0 ? d.getUTCDay() - 1 : 6) : d.getUTCDay();
48-
var jan1 = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
49-
o.tm_yday = Math.ceil((d - jan1) / (1000 * 60 * 60 * 24));
50-
};
18+
tm_sec: 0,
19+
tm_min: 0,
20+
tm_hour: 0,
21+
tm_mday: 0,
22+
tm_mon: 0,
23+
tm_year: 0,
24+
tm_wday: 0,
25+
tm_yday: 0,
26+
unparsed: ''
27+
},
28+
i = 0,
29+
that = this,
30+
amPmOffset = 0,
31+
prevHour = false,
32+
_reset = function(dateObj, realMday) {
33+
// realMday is to allow for a value of 0 in return results (but without
34+
// messing up the Date() object)
35+
var jan1,
36+
o = retObj,
37+
d = dateObj;
38+
o.tm_sec = d.getUTCSeconds();
39+
o.tm_min = d.getUTCMinutes();
40+
o.tm_hour = d.getUTCHours();
41+
o.tm_mday = realMday === 0 ? realMday : d.getUTCDate();
42+
o.tm_mon = d.getUTCMonth();
43+
o.tm_year = d.getUTCFullYear() - 1900;
44+
o.tm_wday = realMday === 0 ? (d.getUTCDay() > 0 ? d.getUTCDay() - 1 : 6) : d.getUTCDay();
45+
jan1 = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
46+
o.tm_yday = Math.ceil((d - jan1) / (1000 * 60 * 60 * 24));
47+
},
48+
_date = function() {
49+
var o = retObj;
50+
// We set date to at least 1 to ensure year or month doesn't go backwards
51+
return _reset(new Date(Date.UTC(o.tm_year + 1900, o.tm_mon, o.tm_mday || 1, o.tm_hour, o.tm_min, o.tm_sec)), o.tm_mday);
52+
};
5153

5254
// BEGIN STATIC
5355
var _NWS = /\S/,
@@ -132,12 +134,13 @@ Oy
132134
};
133135

134136
// BEGIN PROCESSING CHARACTERS
135-
for (var i = 0, j = 0; i < format.length; i++) {
137+
for (i = 0, j = 0; i < format.length; i++) {
136138
if (format.charAt(i) === '%') {
137139
var literalPos = ['%', 'n', 't'].indexOf(format.charAt(i + 1));
138140
if (literalPos !== -1) {
139141
if (['%', '\n', '\t'].indexOf(dateStr.charAt(j)) === literalPos) { // a matched literal
140-
++i, ++j; // skip beyond
142+
++i;
143+
++j; // skip beyond
141144
continue;
142145
}
143146
// Format indicated a percent literal, but not actually present
@@ -323,7 +326,6 @@ Oy
323326
break;
324327
default:
325328
throw 'Unrecognized formatting character in strptime()';
326-
break;
327329
}
328330
} catch (e) {
329331
if (e === 'No match in string') { // Allow us to exit
@@ -341,10 +343,10 @@ Oy
341343
} else if (format.charAt(i).search(_NWS) !== -1) { // Any extra formatting characters besides white-space causes
342344
// problems (do check after WS though, as may just be WS in string before next character)
343345
return false;
344-
} else { // Extra WS in format
345-
// Adjust strings when encounter non-matching whitespace, so they align in future checks above
346-
// Will check on next iteration (against same (non-WS) string character)
347346
}
347+
// Extra WS in format
348+
// Adjust strings when encounter non-matching whitespace, so they align in future checks above
349+
// Will check on next iteration (against same (non-WS) string character)
348350
} else {
349351
j++;
350352
}

functions/exec/escapeshellarg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function escapeshellarg(arg) {
33
// + original by: Felix Geisendoerfer (http://www.debuggable.com/felix)
44
// + improved by: Brett Zamir (http://brett-zamir.me)
55
// * example 1: escapeshellarg("kevin's birthday");
6-
// * returns 1: "'kevin\'s birthday'"
6+
// * returns 1: "'kevin\\'s birthday'"
77
var ret = '';
88

99
ret = arg.replace(/[^\\]'/g, function(m, i, s) {

functions/filesystem/basename.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ function basename(path, suffix) {
44
// + improved by: Ash Searle (http://hexmen.com/blog/)
55
// + improved by: Lincoln Ramsay
66
// + improved by: djmix
7+
// + improved by: Dmitry Gorelenkov
78
// * example 1: basename('/www/site/home.htm', '.htm');
89
// * returns 1: 'home'
910
// * example 2: basename('ecra.php?p=1');
1011
// * returns 2: 'ecra.php?p=1'
11-
var b = path.replace(/^.*[\/\\]/g, '');
12+
// * example 3: basename('/some/path/');
13+
// * returns 3: 'path'
14+
// * example 4: basename('/some/path_ext.ext/','.ext');
15+
// * returns 4: 'path_ext'
16+
var b = path;
17+
var lastChar = b.charAt(b.length-1);
18+
19+
if(lastChar === "/" || lastChar === "\\") {
20+
b = b.slice(0, -1);
21+
}
22+
23+
b = b.replace(/^.*[\/\\]/g, '');
1224

1325
if (typeof suffix === 'string' && b.substr(b.length - suffix.length) == suffix) {
1426
b = b.substr(0, b.length - suffix.length);

functions/filesystem/pathinfo.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ function pathinfo(path, options) {
1313
// % note 2: But by way we implemented this function, if you want you can still declare the PATHINFO_*
1414
// % note 2: yourself, and then you can use: pathinfo('/www/index.html', PATHINFO_BASENAME | PATHINFO_EXTENSION);
1515
// % note 2: which makes it fully compliant with PHP syntax.
16-
// - depends on: dirname
1716
// - depends on: basename
18-
// * test: skip
1917
// * example 1: pathinfo('/www/htdocs/index.html', 1);
2018
// * returns 1: '/www/htdocs'
2119
// * example 2: pathinfo('/www/htdocs/index.html', 'PATHINFO_BASENAME');
@@ -83,8 +81,8 @@ function pathinfo(path, options) {
8381

8482
// Gather path infos
8583
if (options & OPTS.PATHINFO_DIRNAME) {
86-
var dirname = this.dirname(path);
87-
tmp_arr.dirname = dirname === path ? '.' : dirname;
84+
var dirName = path.replace(/\\/g, '/').replace(/\/[^\/]*\/?$/, ''); // dirname
85+
tmp_arr.dirname = dirName === path ? '.' : dirName;
8886
}
8987

9088
if (options & OPTS.PATHINFO_BASENAME) {

functions/i18n/i18n_loc_get_default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ function i18n_loc_get_default() {
55
// % note 2: List of locales at http://demo.icu-project.org/icu-bin/locexp
66
// % note 3: To be usable with sort() if it is passed the SORT_LOCALE_STRING sorting flag: http://php.net/manual/en/function.sort.php
77
// - depends on: i18n_loc_set_default
8+
// * example 1: i18n_loc_set_default('pt_PT');
89
// * example 1: i18n_loc_get_default();
9-
// * returns 1: 'en_US_POSIX'
10+
// * returns 1: 'pt_PT'
1011

1112
// BEGIN REDUNDANT
1213
this.php_js = this.php_js || {};

0 commit comments

Comments
 (0)