summaryrefslogtreecommitdiff
path: root/ext/date
diff options
context:
space:
mode:
Diffstat (limited to 'ext/date')
-rwxr-xr-xext/date/config.w325
-rw-r--r--ext/date/config0.m45
-rw-r--r--ext/date/lib/parse_tz.c6
-rw-r--r--ext/date/lib/timelib_structs.h66
-rw-r--r--ext/date/php_date.c129
-rw-r--r--ext/date/php_date.h4
-rw-r--r--ext/date/tests/002.phpt2
-rw-r--r--ext/date/tests/DatePeriod_getter.phpt25
-rw-r--r--ext/date/tests/DateTimeImmutable_createFromMutable.phpt26
-rw-r--r--ext/date/tests/bug13142.phpt2
-rw-r--r--ext/date/tests/bug26317.phpt2
-rw-r--r--ext/date/tests/bug26320.phpt2
-rw-r--r--ext/date/tests/bug41523.phpt2
13 files changed, 247 insertions, 29 deletions
diff --git a/ext/date/config.w32 b/ext/date/config.w32
index c97df7246c..26d583bfbf 100755
--- a/ext/date/config.w32
+++ b/ext/date/config.w32
@@ -1,7 +1,7 @@
// $Id$
// vim:ft=javascript
-EXTENSION("date", "php_date.c", false, "-Iext/date/lib");
+EXTENSION("date", "php_date.c", false, "/Iext/date/lib /DHAVE_TIMELIB_CONFIG_H=1");
ADD_SOURCES("ext/date/lib", "astro.c timelib.c dow.c parse_date.c parse_tz.c tm2unixtime.c unixtime2tm.c parse_iso_intervals.c interval.c", "date");
AC_DEFINE('HAVE_DATE', 1, 'Have date/time support');
@@ -9,6 +9,9 @@ ADD_FLAG('CFLAGS_DATE', "/wd4244");
var tl_config = FSO.CreateTextFile("ext/date/lib/timelib_config.h", true);
tl_config.WriteLine("#include \"config.w32.h\"");
+tl_config.WriteLine("#include <php_stdint.h>");
+tl_config.WriteLine("#define TIMELIB_OMIT_STDINT 1");
tl_config.Close();
PHP_INSTALL_HEADERS("ext/date/", "php_date.h lib/timelib.h lib/timelib_structs.h lib/timelib_config.h");
+AC_DEFINE('HAVE_TIMELIB_CONFIG_H', 1, 'Have timelib_config.h')
diff --git a/ext/date/config0.m4 b/ext/date/config0.m4
index f403104a8a..b83f9bc0d4 100644
--- a/ext/date/config0.m4
+++ b/ext/date/config0.m4
@@ -4,7 +4,7 @@ dnl config.m4 for date extension
sinclude(ext/date/lib/timelib.m4)
sinclude(lib/timelib.m4)
-PHP_DATE_CFLAGS="-I@ext_builddir@/lib"
+PHP_DATE_CFLAGS="-I@ext_builddir@/lib -D HAVE_TIMELIB_CONFIG_H=1"
timelib_sources="lib/astro.c lib/dow.c lib/parse_date.c lib/parse_tz.c
lib/timelib.c lib/tm2unixtime.c lib/unixtime2tm.c lib/parse_iso_intervals.c lib/interval.c"
@@ -15,6 +15,7 @@ PHP_ADD_INCLUDE([$ext_builddir/lib])
PHP_ADD_INCLUDE([$ext_srcdir/lib])
PHP_INSTALL_HEADERS([ext/date], [php_date.h lib/timelib.h lib/timelib_structs.h lib/timelib_config.h])
+AC_DEFINE([HAVE_TIMELIB_CONFIG_H], [1], [Have timelib_config.h])
cat > $ext_builddir/lib/timelib_config.h <<EOF
#ifdef PHP_WIN32
@@ -22,4 +23,6 @@ cat > $ext_builddir/lib/timelib_config.h <<EOF
#else
# include <php_config.h>
#endif
+#include <php_stdint.h>
+#define TIMELIB_OMIT_STDINT 1
EOF
diff --git a/ext/date/lib/parse_tz.c b/ext/date/lib/parse_tz.c
index ec7c6d380a..fc301453c7 100644
--- a/ext/date/lib/parse_tz.c
+++ b/ext/date/lib/parse_tz.c
@@ -336,7 +336,7 @@ static ttinfo* fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib
{
uint32_t i;
- /* If there is no transistion time, we pick the first one, if that doesn't
+ /* If there is no transition time, we pick the first one, if that doesn't
* exist we return NULL */
if (!tz->timecnt || !tz->trans) {
*transition_time = 0;
@@ -346,8 +346,8 @@ static ttinfo* fetch_timezone_offset(timelib_tzinfo *tz, timelib_sll ts, timelib
return NULL;
}
- /* If the TS is lower than the first transistion time, then we scan over
- * all the transistion times to find the first non-DST one, or the first
+ /* If the TS is lower than the first transition time, then we scan over
+ * all the transition times to find the first non-DST one, or the first
* one in case there are only DST entries. Not sure which smartass came up
* with this idea in the first though :) */
if (ts < tz->trans[0]) {
diff --git a/ext/date/lib/timelib_structs.h b/ext/date/lib/timelib_structs.h
index 8f36fe1ba7..6bede34985 100644
--- a/ext/date/lib/timelib_structs.h
+++ b/ext/date/lib/timelib_structs.h
@@ -21,7 +21,11 @@
#ifndef __TIMELIB_STRUCTS_H__
#define __TIMELIB_STRUCTS_H__
-#include "timelib_config.h"
+#ifdef HAVE_TIMELIB_CONFIG_H
+# include "timelib_config.h"
+#endif
+
+#ifndef TIMELIB_OMIT_STDINT
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
@@ -33,11 +37,6 @@
#include <stdint.h>
#endif
-#ifdef PHP_WIN32
-/* TODO: Remove these hacks/defs once we have the int definitions in main/
- rathen than in each 2nd extension and win32/ */
-# include "win32/php_stdint.h"
-#else
# ifndef HAVE_INT32_T
# if SIZEOF_INT == 4
typedef int int32_t;
@@ -53,8 +52,63 @@ typedef unsigned int uint32_t;
typedef unsigned long int uint32_t;
# endif
# endif
+
+#ifdef _WIN32
+# if _MSC_VER >= 1600
+# include <stdint.h>
+# endif
+# ifndef SIZEOF_INT
+# define SIZEOF_INT 4
+# endif
+# ifndef SIZEOF_LONG
+# define SIZEOF_LONG 4
+# endif
+# ifndef int32_t
+typedef __int32 int32_t;
+# endif
+# ifndef uint32_t
+typedef unsigned __int32 uint32_t;
+# endif
+# ifndef int64_t
+typedef __int64 int64_t;
+# endif
+# ifndef uint64_t
+typedef unsigned __int64 uint64_t;
+# endif
+# ifndef PRId32
+# define PRId32 "I32d"
+# endif
+# ifndef PRIu32
+# define PRIu32 "I32u"
+# endif
+# ifndef PRId64
+# define PRId64 "I64d"
+# endif
+# ifndef PRIu64
+# define PRIu64 "I64u"
+# endif
+# ifndef INT32_MAX
+#define INT32_MAX _I32_MAX
+# endif
+# ifndef INT32_MIN
+#define INT32_MIN ((int32_t)_I32_MIN)
+# endif
+# ifndef UINT32_MAX
+#define UINT32_MAX _UI32_MAX
+# endif
+# ifndef INT64_MIN
+#define INT64_MIN ((int64_t)_I64_MIN)
+# endif
+# ifndef INT64_MAX
+#define INT64_MAX _I64_MAX
+# endif
+# ifndef UINT64_MAX
+#define UINT64_MAX _UI64_MAX
+# endif
#endif
+#endif /* TIMELIB_OMIT_STDINT */
+
#include <stdio.h>
#ifdef HAVE_STDLIB_H
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 909377ba1f..15ca08d3a9 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -303,6 +303,10 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_date_method_timestamp_get, 0)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_date_method_create_from_mutable, 0, 0, 1)
+ ZEND_ARG_INFO(0, DateTime)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_timezone_open, 0, 0, 1)
ZEND_ARG_INFO(0, timezone)
ZEND_END_ARG_INFO()
@@ -499,6 +503,7 @@ const zend_function_entry date_funcs_immutable[] = {
PHP_ME(DateTimeImmutable, setDate, arginfo_date_method_date_set, 0)
PHP_ME(DateTimeImmutable, setISODate, arginfo_date_method_isodate_set, 0)
PHP_ME(DateTimeImmutable, setTimestamp, arginfo_date_method_timestamp_set, 0)
+ PHP_ME(DateTimeImmutable, createFromMutable, arginfo_date_method_create_from_mutable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};
@@ -528,6 +533,9 @@ const zend_function_entry date_funcs_period[] = {
PHP_ME(DatePeriod, __construct, arginfo_date_period_construct, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
PHP_ME(DatePeriod, __wakeup, NULL, ZEND_ACC_PUBLIC)
PHP_ME(DatePeriod, __set_state, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(DatePeriod, getStartDate, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(DatePeriod, getEndDate, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(DatePeriod, getDateInterval, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
@@ -2652,10 +2660,8 @@ PHP_FUNCTION(date_create)
if (!php_date_initialize(zend_object_store_get_object(&datetime_object TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 0 TSRMLS_CC)) {
zval_dtor(&datetime_object);
RETURN_FALSE;
- } else {
- zval *datetime_object_ptr = &datetime_object;
- RETVAL_ZVAL(datetime_object_ptr, 0, 0);
}
+ RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */
@@ -2677,10 +2683,8 @@ PHP_FUNCTION(date_create_immutable)
if (!php_date_initialize(zend_object_store_get_object(&datetime_object TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 0 TSRMLS_CC)) {
zval_dtor(&datetime_object);
RETURN_FALSE;
- } else {
- zval *datetime_object_ptr = &datetime_object;
- RETVAL_ZVAL(datetime_object_ptr, 0, 0);
}
+ RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */
@@ -2702,10 +2706,8 @@ PHP_FUNCTION(date_create_from_format)
if (!php_date_initialize(zend_object_store_get_object(&datetime_object TSRMLS_CC), time_str, time_str_len, format_str, timezone_object, 0 TSRMLS_CC)) {
zval_dtor(&datetime_object);
RETURN_FALSE;
- } else {
- zval *datetime_object_ptr = &datetime_object;
- RETVAL_ZVAL(datetime_object_ptr, 0, 0);
}
+ RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */
@@ -2727,10 +2729,8 @@ PHP_FUNCTION(date_create_immutable_from_format)
if (!php_date_initialize(zend_object_store_get_object(&datetime_object TSRMLS_CC), time_str, time_str_len, format_str, timezone_object, 0 TSRMLS_CC)) {
zval_dtor(&datetime_object);
RETURN_FALSE;
- } else {
- zval *datetime_object_ptr = &datetime_object;
- RETVAL_ZVAL(datetime_object_ptr, 0, 0);
}
+ RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */
@@ -2770,6 +2770,34 @@ PHP_METHOD(DateTimeImmutable, __construct)
}
/* }}} */
+/* {{{ proto DateTimeImmutable::createFromMutable(DateTimeZone object)
+ Creates new DateTimeImmutable object from an existing mutable DateTime object.
+*/
+PHP_METHOD(DateTimeImmutable, createFromMutable)
+{
+ zval *datetime_object = NULL;
+ php_date_obj *new_obj = NULL;
+ php_date_obj *old_obj = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O!", &datetime_object, date_ce_date) == FAILURE) {
+ return;
+ }
+
+ php_date_instantiate(date_ce_immutable, return_value TSRMLS_CC);
+ old_obj = (php_date_obj *) zend_object_store_get_object(datetime_object TSRMLS_CC);
+ new_obj = (php_date_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
+
+ new_obj->time = timelib_time_ctor();
+ *new_obj->time = *old_obj->time;
+ if (old_obj->time->tz_abbr) {
+ new_obj->time->tz_abbr = strdup(old_obj->time->tz_abbr);
+ }
+ if (old_obj->time->tz_info) {
+ new_obj->time->tz_info = old_obj->time->tz_info;
+ }
+}
+/* }}} */
+
static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht TSRMLS_DC)
{
zval **z_date = NULL;
@@ -4449,7 +4477,82 @@ PHP_METHOD(DatePeriod, __construct)
}
/* }}} */
-static int check_id_allowed(char *id, long what)
+/* {{{ proto DatePeriod::getStartDate()
+ Get start date.
+*/
+PHP_METHOD(DatePeriod, getStartDate)
+{
+ php_period_obj *dpobj;
+ php_date_obj *dateobj;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ dpobj = (php_period_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_date_instantiate(dpobj->start_ce, return_value TSRMLS_CC);
+ dateobj = (php_date_obj *)zend_object_store_get_object(return_value TSRMLS_CC);
+ dateobj->time = timelib_time_ctor();
+ *dateobj->time = *dpobj->start;
+ if (dpobj->start->tz_abbr) {
+ dateobj->time->tz_abbr = strdup(dpobj->start->tz_abbr);
+ }
+ if (dpobj->start->tz_info) {
+ dateobj->time->tz_info = dpobj->start->tz_info;
+ }
+}
+/* }}} */
+
+/* {{{ proto DatePeriod::getEndDate()
+ Get end date.
+*/
+PHP_METHOD(DatePeriod, getEndDate)
+{
+ php_period_obj *dpobj;
+ php_date_obj *dateobj;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ dpobj = (php_period_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_date_instantiate(dpobj->start_ce, return_value TSRMLS_CC);
+ dateobj = (php_date_obj *)zend_object_store_get_object(return_value TSRMLS_CC);
+ dateobj->time = timelib_time_ctor();
+ *dateobj->time = *dpobj->end;
+ if (dpobj->end->tz_abbr) {
+ dateobj->time->tz_abbr = strdup(dpobj->end->tz_abbr);
+ }
+ if (dpobj->end->tz_info) {
+ dateobj->time->tz_info = dpobj->end->tz_info;
+ }
+}
+/* }}} */
+
+/* {{{ proto DatePeriod::getDateInterval()
+ Get date interval.
+*/
+PHP_METHOD(DatePeriod, getDateInterval)
+{
+ php_period_obj *dpobj;
+ php_interval_obj *diobj;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ dpobj = (php_period_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_date_instantiate(date_ce_interval, return_value TSRMLS_CC);
+ diobj = (php_interval_obj *)zend_object_store_get_object(return_value TSRMLS_CC);
+ diobj->diff = timelib_rel_time_clone(dpobj->interval);
+ diobj->initialized = 1;
+}
+/* }}} */
+
+static int check_id_allowed(char *id, long what) /* {{{ */
{
if (what & PHP_DATE_TIMEZONE_GROUP_AFRICA && strncasecmp(id, "Africa/", 7) == 0) return 1;
if (what & PHP_DATE_TIMEZONE_GROUP_AMERICA && strncasecmp(id, "America/", 8) == 0) return 1;
diff --git a/ext/date/php_date.h b/ext/date/php_date.h
index 10498d0d01..a3deeb2a41 100644
--- a/ext/date/php_date.h
+++ b/ext/date/php_date.h
@@ -82,6 +82,7 @@ PHP_METHOD(DateTimeImmutable, setTime);
PHP_METHOD(DateTimeImmutable, setDate);
PHP_METHOD(DateTimeImmutable, setISODate);
PHP_METHOD(DateTimeImmutable, setTimestamp);
+PHP_METHOD(DateTimeImmutable, createFromMutable);
PHP_METHOD(DateTimeZone, __construct);
PHP_METHOD(DateTimeZone, __wakeup);
@@ -105,6 +106,9 @@ PHP_FUNCTION(date_interval_create_from_date_string);
PHP_METHOD(DatePeriod, __construct);
PHP_METHOD(DatePeriod, __wakeup);
PHP_METHOD(DatePeriod, __set_state);
+PHP_METHOD(DatePeriod, getStartDate);
+PHP_METHOD(DatePeriod, getEndDate);
+PHP_METHOD(DatePeriod, getDateInterval);
/* Options and Configuration */
PHP_FUNCTION(date_default_timezone_set);
diff --git a/ext/date/tests/002.phpt b/ext/date/tests/002.phpt
index 92d0d5f105..adbea5e231 100644
--- a/ext/date/tests/002.phpt
+++ b/ext/date/tests/002.phpt
@@ -3,7 +3,7 @@ strtotime() function
--SKIPIF--
<?php
if (!@putenv("TZ=EST5") || getenv("TZ") != 'EST5') {
- die("skip unable to change TZ enviroment variable\n");
+ die("skip unable to change TZ environment variable\n");
}
?>
--FILE--
diff --git a/ext/date/tests/DatePeriod_getter.phpt b/ext/date/tests/DatePeriod_getter.phpt
new file mode 100644
index 0000000000..22006d1ae8
--- /dev/null
+++ b/ext/date/tests/DatePeriod_getter.phpt
@@ -0,0 +1,25 @@
+--TEST--
+DatePeriod: Test getter
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+$start = new DateTime('2000-01-01 00:00:00', new DateTimeZone('Europe/Berlin'));
+$end = new DateTime('2000-01-31 00:00:00', new DateTimeZone('UTC'));
+$interval = new DateInterval('P1D');
+$period = new DatePeriod($start, $interval, $end);
+
+var_dump($period->getStartDate()->format('Y-m-d H:i:s'));
+var_dump($period->getStartDate()->getTimeZone()->getName());
+
+var_dump($period->getEndDate()->format('Y-m-d H:i:s'));
+var_dump($period->getEndDate()->getTimeZone()->getName());
+
+var_dump($period->getDateInterval()->format('%R%y-%m-%d-%h-%i-%s'));
+?>
+--EXPECTF--
+string(19) "2000-01-01 00:00:00"
+string(13) "Europe/Berlin"
+string(19) "2000-01-31 00:00:00"
+string(3) "UTC"
+string(12) "+0-0-1-0-0-0"
diff --git a/ext/date/tests/DateTimeImmutable_createFromMutable.phpt b/ext/date/tests/DateTimeImmutable_createFromMutable.phpt
new file mode 100644
index 0000000000..ac92fb4bb4
--- /dev/null
+++ b/ext/date/tests/DateTimeImmutable_createFromMutable.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Tests for DateTimeImmutable::createFromMutable.
+--INI--
+date.timezone=Europe/London
+--FILE--
+<?php
+$current = "2014-03-02 16:24:08";
+
+$i = DateTimeImmutable::createFromMutable( date_create( $current ) );
+var_dump( $i );
+
+$i = DateTimeImmutable::createFromMutable( date_create_immutable( $current ) );
+var_dump( $i );
+?>
+--EXPECTF--
+object(DateTimeImmutable)#%d (3) {
+ ["date"]=>
+ string(26) "2014-03-02 16:24:08.000000"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(13) "Europe/London"
+}
+
+Warning: DateTimeImmutable::createFromMutable() expects parameter 1 to be DateTime, object given in %stests%eDateTimeImmutable_createFromMutable.php on line %d
+NULL
diff --git a/ext/date/tests/bug13142.phpt b/ext/date/tests/bug13142.phpt
index 5254142baa..5849a94427 100644
--- a/ext/date/tests/bug13142.phpt
+++ b/ext/date/tests/bug13142.phpt
@@ -8,7 +8,7 @@ if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
die("skip. set TZ env is not supported at runtime.");
}
if (!@putenv("TZ=US/Eastern") || getenv("TZ") != 'US/Eastern') {
- die("skip unable to change TZ enviroment variable\n");
+ die("skip unable to change TZ environment variable\n");
}
?>
--FILE--
diff --git a/ext/date/tests/bug26317.phpt b/ext/date/tests/bug26317.phpt
index 5b79bec525..27d6ff1250 100644
--- a/ext/date/tests/bug26317.phpt
+++ b/ext/date/tests/bug26317.phpt
@@ -4,7 +4,7 @@ Bug #26317 (military timezone offset signedness)
date.timezone=GMT0
--SKIPIF--
if (!@putenv("TZ=GMT0") || getenv("TZ") != 'GMT0') {
- die("skip unable to change TZ enviroment variable\n");
+ die("skip unable to change TZ environment variable\n");
}
--FILE--
<?php
diff --git a/ext/date/tests/bug26320.phpt b/ext/date/tests/bug26320.phpt
index c8aeb00c9f..e742c39da5 100644
--- a/ext/date/tests/bug26320.phpt
+++ b/ext/date/tests/bug26320.phpt
@@ -4,7 +4,7 @@ Bug #26320 (strtotime handling of XML Schema/ISO 8601 format)
date.timezone=GMT0
--SKIPIF--
if (!@putenv("TZ=GMT0") || getenv("TZ") != 'GMT0') {
- die("skip unable to change TZ enviroment variable\n");
+ die("skip unable to change TZ environment variable\n");
}
--FILE--
<?php
diff --git a/ext/date/tests/bug41523.phpt b/ext/date/tests/bug41523.phpt
index 05c591f063..68fe1bd6a3 100644
--- a/ext/date/tests/bug41523.phpt
+++ b/ext/date/tests/bug41523.phpt
@@ -46,7 +46,7 @@ array(12) {
bool(false)
object(DateTime)#1 (3) {
["date"]=>
- string(20) "-0001-11-30 00:00:00.000000"
+ string(27) "-0001-11-30 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>