summaryrefslogtreecommitdiff
path: root/ext/standard/tests/time
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/tests/time')
-rw-r--r--ext/standard/tests/time/001.phpt34
-rw-r--r--ext/standard/tests/time/bug38524.phpt31
-rw-r--r--ext/standard/tests/time/bug60222.phpt15
-rw-r--r--ext/standard/tests/time/idate.phpt31
-rw-r--r--ext/standard/tests/time/strptime_basic.phpt100
-rw-r--r--ext/standard/tests/time/strptime_error.phpt55
-rw-r--r--ext/standard/tests/time/strptime_parts.phpt76
7 files changed, 342 insertions, 0 deletions
diff --git a/ext/standard/tests/time/001.phpt b/ext/standard/tests/time/001.phpt
new file mode 100644
index 0000000..3b0ed8a
--- /dev/null
+++ b/ext/standard/tests/time/001.phpt
@@ -0,0 +1,34 @@
+--TEST--
+microtime() function
+--SKIPIF--
+<?php
+ if (!function_exists('microtime')) die('skip microtime() not available');
+ die('warn system dependent');
+?>
+--FILE--
+<?php
+$passed = 0;
+$failed = 0;
+$last_m = 0;
+$last_t = 0;
+$result = '';
+
+set_time_limit(0);
+
+for ($i=1;$i<=100000;$i++) {
+ list($micro,$time)=explode(" ",microtime());
+ if ($time > $last_t || ($time == $last_t && $micro >= $last_m)) {
+ $passed++;
+ } else if ($failed++ <=10) {
+ $result .= sprintf('%06d', $i).": $time $micro < $last_t $last_m\n";
+ }
+ $last_m = $micro;
+ $last_t = $time;
+}
+echo "Passed: $passed\n";
+echo "Failed: $failed\n";
+echo $result;
+?>
+--EXPECT--
+Passed: 100000
+Failed: 0
diff --git a/ext/standard/tests/time/bug38524.phpt b/ext/standard/tests/time/bug38524.phpt
new file mode 100644
index 0000000..77d0f4f
--- /dev/null
+++ b/ext/standard/tests/time/bug38524.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Bug #38524 (strptime() does not initialize the internal date storage structure)
+--SKIPIF--
+<?php if (!function_exists('strptime')) echo "SKIP"; ?>
+--FILE--
+<?php
+ var_dump(strptime('2006-08-20', '%Y-%m-%d'));
+?>
+===DONE===
+--EXPECTF--
+array(9) {
+ ["tm_sec"]=>
+ int(0)
+ ["tm_min"]=>
+ int(0)
+ ["tm_hour"]=>
+ int(0)
+ ["tm_mday"]=>
+ int(20)
+ ["tm_mon"]=>
+ int(7)
+ ["tm_year"]=>
+ int(106)
+ ["tm_wday"]=>
+ int(0)
+ ["tm_yday"]=>
+ int(%d)
+ ["unparsed"]=>
+ string(0) ""
+}
+===DONE===
diff --git a/ext/standard/tests/time/bug60222.phpt b/ext/standard/tests/time/bug60222.phpt
new file mode 100644
index 0000000..8053a81
--- /dev/null
+++ b/ext/standard/tests/time/bug60222.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #60222 (time_nanosleep() does validate input params)
+--FILE--
+<?php
+ var_dump(time_nanosleep(-1, 0));
+ var_dump(time_nanosleep(0, -1));
+?>
+===DONE===
+--EXPECTF--
+Warning: time_nanosleep(): The seconds value must be greater than 0 in %s on line %d
+bool(false)
+
+Warning: time_nanosleep(): The nanoseconds value must be greater than 0 in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/standard/tests/time/idate.phpt b/ext/standard/tests/time/idate.phpt
new file mode 100644
index 0000000..0b54405
--- /dev/null
+++ b/ext/standard/tests/time/idate.phpt
@@ -0,0 +1,31 @@
+--TEST--
+idate() function
+--FILE--
+<?php
+date_default_timezone_set('GMT0');
+$tmp = "UYzymndjHGhgistwLBIW";
+for($a = 0;$a < strlen($tmp); $a++){
+ echo $tmp[$a], ': ', idate($tmp[$a], 1043324459)."\n";
+}
+?>
+--EXPECT--
+U: 1043324459
+Y: 2003
+z: 22
+y: 3
+m: 1
+n: 1
+d: 23
+j: 23
+H: 12
+G: 12
+h: 12
+g: 12
+i: 20
+s: 59
+t: 31
+w: 4
+L: 0
+B: 556
+I: 0
+W: 4
diff --git a/ext/standard/tests/time/strptime_basic.phpt b/ext/standard/tests/time/strptime_basic.phpt
new file mode 100644
index 0000000..194a78f
--- /dev/null
+++ b/ext/standard/tests/time/strptime_basic.phpt
@@ -0,0 +1,100 @@
+--TEST--
+Test strptime() function : basic functionality
+--SKIPIF--
+<?php
+ if (!function_exists('strptime')) {
+ die("skip - strptime() function not available in this build");
+ }
+ if(PHP_OS == 'Darwin') die("skip - strptime() behaves differently on Darwin");
+?>
+
+--FILE--
+<?php
+/* Prototype : array strptime ( string $date , string $format )
+ * Description: Parse a time/date generated with strftime()
+ * Source code: ext/standard/datetime.c
+*/
+
+$orig = setlocale(LC_ALL, 'C');
+date_default_timezone_set("GMT");
+
+echo "*** Testing strptime() : basic functionality ***\n";
+
+$input = "10:00:00 AM July 2 1963";
+$tstamp = strtotime($input);
+
+$str = strftime("%r %B%e %Y %Z", $tstamp);
+var_dump(strptime($str, '%H:%M:%S %p %B %d %Y %Z'));
+
+$str = strftime("%T %D", $tstamp);
+var_dump(strptime($str, '%H:%M:%S %m/%d/%y'));
+
+$str = strftime("%A %B %e %R", $tstamp);
+var_dump(strptime($str, '%A %B %e %R'));
+
+setlocale(LC_ALL, $orig);
+?>
+===DONE===
+--EXPECTF--
+*** Testing strptime() : basic functionality ***
+array(9) {
+ ["tm_sec"]=>
+ int(0)
+ ["tm_min"]=>
+ int(0)
+ ["tm_hour"]=>
+ int(10)
+ ["tm_mday"]=>
+ int(2)
+ ["tm_mon"]=>
+ int(6)
+ ["tm_year"]=>
+ int(63)
+ ["tm_wday"]=>
+ int(2)
+ ["tm_yday"]=>
+ int(182)
+ ["unparsed"]=>
+ string(3) "GMT"
+}
+array(9) {
+ ["tm_sec"]=>
+ int(0)
+ ["tm_min"]=>
+ int(0)
+ ["tm_hour"]=>
+ int(10)
+ ["tm_mday"]=>
+ int(2)
+ ["tm_mon"]=>
+ int(6)
+ ["tm_year"]=>
+ int(163)
+ ["tm_wday"]=>
+ int(1)
+ ["tm_yday"]=>
+ int(182)
+ ["unparsed"]=>
+ string(0) ""
+}
+array(9) {
+ ["tm_sec"]=>
+ int(0)
+ ["tm_min"]=>
+ int(0)
+ ["tm_hour"]=>
+ int(10)
+ ["tm_mday"]=>
+ int(2)
+ ["tm_mon"]=>
+ int(6)
+ ["tm_year"]=>
+ int(0)
+ ["tm_wday"]=>
+ int(2)
+ ["tm_yday"]=>
+ int(182)
+ ["unparsed"]=>
+ string(0) ""
+}
+===DONE===
diff --git a/ext/standard/tests/time/strptime_error.phpt b/ext/standard/tests/time/strptime_error.phpt
new file mode 100644
index 0000000..92c7ca3
--- /dev/null
+++ b/ext/standard/tests/time/strptime_error.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Test localtime() function : error conditions
+--SKIPIF--
+<?php
+if (!function_exists('strptime')) {
+ echo "SKIP strptime function not available in build";
+}
+?>
+--FILE--
+<?php
+/* Prototype : array strptime ( string $date , string $format )
+ * Description: Parse a time/date generated with strftime()
+ * Source code: ext/standard/datetime.c
+ * Alias to functions:
+ */
+
+//Set the default time zone
+date_default_timezone_set("Europe/London");
+
+echo "*** Testing strptime() : error conditions ***\n";
+
+echo "\n-- Testing strptime() function with Zero arguments --\n";
+var_dump( strptime() );
+
+echo "\n-- Testing strptime() function with less than expected no. of arguments --\n";
+$format = '%b %d %Y %H:%M:%S';
+$timestamp = mktime(8, 8, 8, 8, 8, 2008);
+$date = strftime($format, $timestamp);
+var_dump( strptime($date) );
+
+echo "\n-- Testing strptime() function with more than expected no. of arguments --\n";
+$extra_arg = 10;
+var_dump( strptime($date, $format, $extra_arg) );
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing strptime() : error conditions ***
+
+-- Testing strptime() function with Zero arguments --
+
+Warning: strptime() expects exactly 2 parameters, 0 given in %s on line %d
+NULL
+
+-- Testing strptime() function with less than expected no. of arguments --
+
+Warning: strptime() expects exactly 2 parameters, 1 given in %s on line %d
+NULL
+
+-- Testing strptime() function with more than expected no. of arguments --
+
+Warning: strptime() expects exactly 2 parameters, 3 given in %s on line %d
+NULL
+===DONE===
+
diff --git a/ext/standard/tests/time/strptime_parts.phpt b/ext/standard/tests/time/strptime_parts.phpt
new file mode 100644
index 0000000..fbe684b
--- /dev/null
+++ b/ext/standard/tests/time/strptime_parts.phpt
@@ -0,0 +1,76 @@
+--TEST--
+Test strptime() function : basic functionality
+--SKIPIF--
+<?php
+ if (!function_exists('strptime')) {
+ die("skip - strptime() function not available in this build");
+ }
+?>
+
+--FILE--
+<?php
+/* Prototype : array strptime ( string $date , string $format )
+ * Description: Parse a time/date generated with strftime()
+ * Source code: ext/standard/datetime.c
+*/
+
+$orig = setlocale(LC_ALL, 'C');
+date_default_timezone_set("GMT");
+putenv("TZ=GMT");
+
+echo "*** Testing strptime() : basic functionality ***\n";
+
+$input = "10:01:20 AM July 2 1963";
+$tstamp = strtotime($input);
+
+$str = strftime("%r %B%e %Y %Z", $tstamp);
+$res = strptime($str, '%H:%M:%S %p %B %d %Y %Z');
+var_dump($res["tm_sec"]);
+var_dump($res["tm_min"]);
+var_dump($res["tm_hour"]);
+var_dump($res["tm_mday"]);
+var_dump($res["tm_mon"]);
+var_dump($res["tm_year"]);
+
+$str = strftime("%T %D", $tstamp);
+$res = strptime($str, '%H:%M:%S %m/%d/%y');
+var_dump($res["tm_sec"]);
+var_dump($res["tm_min"]);
+var_dump($res["tm_hour"]);
+var_dump($res["tm_mday"]);
+var_dump($res["tm_mon"]);
+var_dump($res["tm_year"]);
+
+$str = strftime("%A %B %e %R", $tstamp);
+$res = strptime($str, '%A %B %e %R');
+var_dump($res["tm_sec"]);
+var_dump($res["tm_min"]);
+var_dump($res["tm_hour"]);
+var_dump($res["tm_mday"]);
+var_dump($res["tm_mon"]);
+var_dump($res["tm_year"]);
+
+setlocale(LC_ALL, $orig);
+?>
+===DONE===
+--EXPECT--
+*** Testing strptime() : basic functionality ***
+int(20)
+int(1)
+int(10)
+int(2)
+int(6)
+int(63)
+int(20)
+int(1)
+int(10)
+int(2)
+int(6)
+int(163)
+int(0)
+int(1)
+int(10)
+int(2)
+int(6)
+int(0)
+===DONE===