summaryrefslogtreecommitdiffstats
path: root/61748491a773a7f47694e2fd97dc2c3c61ce9f18.patch
blob: d9710e84dbe166f8435ca87544495225571d2efe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
From 61748491a773a7f47694e2fd97dc2c3c61ce9f18 Mon Sep 17 00:00:00 2001
From: Yoshio HANAWA <y@hnw.jp>
Date: Wed, 2 Oct 2019 23:53:44 +0900
Subject: [PATCH] Refactoring

---
 .travis.yml                       |  3 +--
 tests/date_007.phpt               |  2 +-
 tests/date_008.phpt               |  2 +-
 tests/date_override_007.phpt      |  2 +-
 tests/date_override_008.phpt      |  2 +-
 tests/immutable_007.phpt          |  2 +-
 tests/immutable_008.phpt          |  2 +-
 tests/immutable_override_007.phpt |  2 +-
 tests/immutable_override_008.phpt |  2 +-
 timecop_php7.c                    | 17 ++++++++---------
 10 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/tests/date_007.phpt b/tests/date_007.phpt
index db490d8..759c09c 100644
--- a/tests/date_007.phpt
+++ b/tests/date_007.phpt
@@ -58,7 +58,7 @@ string\(32\) "2010-09-02 03:04:05\.000000-07:00"
 string\(32\) "2010-12-24 03:04:05\.000000-08:00"
 string\(32\) "2010-01-02 05:00:00\.000000\+09:00"
 string\(32\) "2010-01-02 00:00:59\.000000-08:00"
-string\(32\) "2010-01-02 (00|03):(00|04):(00|05)\.654321-08:00"
+string\(32\) "2010-01-02 (00:00:00|03:04:05)\.654321-08:00"
 string\(32\) "2012-03-31 12:34:56\.000000-07:00"
 string\(32\) "1970-01-01 12:34:56\.000000-08:00"
 string\(32\) "1970-01-01 19:00:00\.000000-05:00"
diff --git a/tests/date_008.phpt b/tests/date_008.phpt
index 851c953..b91c833 100644
--- a/tests/date_008.phpt
+++ b/tests/date_008.phpt
@@ -59,7 +59,7 @@ string\(32\) "2010-09-02 03:04:05\.000000-07:00"
 string\(32\) "2010-12-24 03:04:05\.000000-08:00"
 string\(32\) "2010-01-02 05:00:00\.000000\+09:00"
 string\(32\) "2010-01-02 00:00:59\.000000-08:00"
-string\(32\) "2010-01-02 (00|03):(00|04):(00|05)\.654321-08:00"
+string\(32\) "2010-01-02 (00:00:00|03:04:05)\.654321-08:00"
 string\(32\) "2012-03-31 12:34:56\.000000-07:00"
 string\(32\) "1970-01-01 12:34:56\.000000-08:00"
 string\(32\) "1970-01-01 19:00:00\.000000-05:00"
diff --git a/tests/date_override_007.phpt b/tests/date_override_007.phpt
index 6dd8311..c34708f 100644
--- a/tests/date_override_007.phpt
+++ b/tests/date_override_007.phpt
@@ -60,7 +60,7 @@ string\(32\) "2010-09-02 03:04:05\.000000-07:00"
 string\(32\) "2010-12-24 03:04:05\.000000-08:00"
 string\(32\) "2010-01-02 05:00:00\.000000\+09:00"
 string\(32\) "2010-01-02 00:00:59\.000000-08:00"
-string\(32\) "2010-01-02 (00|03):(00|04):(00|05)\.654321-08:00"
+string\(32\) "2010-01-02 (00:00:00|03:04:05)\.654321-08:00"
 string\(32\) "2012-03-31 12:34:56\.000000-07:00"
 string\(32\) "1970-01-01 12:34:56\.000000-08:00"
 string\(32\) "1970-01-01 19:00:00\.000000-05:00"
diff --git a/tests/date_override_008.phpt b/tests/date_override_008.phpt
index 8d38c04..1764c0a 100644
--- a/tests/date_override_008.phpt
+++ b/tests/date_override_008.phpt
@@ -61,7 +61,7 @@ string\(32\) "2010-09-02 03:04:05\.000000-07:00"
 string\(32\) "2010-12-24 03:04:05\.000000-08:00"
 string\(32\) "2010-01-02 05:00:00\.000000\+09:00"
 string\(32\) "2010-01-02 00:00:59\.000000-08:00"
-string\(32\) "2010-01-02 (00|03):(00|04):(00|05)\.654321-08:00"
+string\(32\) "2010-01-02 (00:00:00|03:04:05)\.654321-08:00"
 string\(32\) "2012-03-31 12:34:56\.000000-07:00"
 string\(32\) "1970-01-01 12:34:56\.000000-08:00"
 string\(32\) "1970-01-01 19:00:00\.000000-05:00"
diff --git a/tests/immutable_007.phpt b/tests/immutable_007.phpt
index 3bcf5c0..36249d2 100644
--- a/tests/immutable_007.phpt
+++ b/tests/immutable_007.phpt
@@ -58,7 +58,7 @@ string\(32\) "2010-09-02 03:04:05\.000000-07:00"
 string\(32\) "2010-12-24 03:04:05\.000000-08:00"
 string\(32\) "2010-01-02 05:00:00\.000000\+09:00"
 string\(32\) "2010-01-02 00:00:59\.000000-08:00"
-string\(32\) "2010-01-02 (00|03):(00|04):(00|05)\.654321-08:00"
+string\(32\) "2010-01-02 (00:00:00|03:04:05)\.654321-08:00"
 string\(32\) "2012-03-31 12:34:56\.000000-07:00"
 string\(32\) "1970-01-01 12:34:56\.000000-08:00"
 string\(32\) "1970-01-01 19:00:00\.000000-05:00"
diff --git a/tests/immutable_008.phpt b/tests/immutable_008.phpt
index 8fd738f..06f1539 100644
--- a/tests/immutable_008.phpt
+++ b/tests/immutable_008.phpt
@@ -59,7 +59,7 @@ string\(32\) "2010-09-02 03:04:05\.000000-07:00"
 string\(32\) "2010-12-24 03:04:05\.000000-08:00"
 string\(32\) "2010-01-02 05:00:00\.000000\+09:00"
 string\(32\) "2010-01-02 00:00:59\.000000-08:00"
-string\(32\) "2010-01-02 (00|03):(00|04):(00|05)\.654321-08:00"
+string\(32\) "2010-01-02 (00:00:00|03:04:05)\.654321-08:00"
 string\(32\) "2012-03-31 12:34:56\.000000-07:00"
 string\(32\) "1970-01-01 12:34:56\.000000-08:00"
 string\(32\) "1970-01-01 19:00:00\.000000-05:00"
diff --git a/tests/immutable_override_007.phpt b/tests/immutable_override_007.phpt
index 7d26767..38390ab 100644
--- a/tests/immutable_override_007.phpt
+++ b/tests/immutable_override_007.phpt
@@ -60,7 +60,7 @@ string\(32\) "2010-09-02 03:04:05\.000000-07:00"
 string\(32\) "2010-12-24 03:04:05\.000000-08:00"
 string\(32\) "2010-01-02 05:00:00\.000000\+09:00"
 string\(32\) "2010-01-02 00:00:59\.000000-08:00"
-string\(32\) "2010-01-02 (00|03):(00|04):(00|05)\.654321-08:00"
+string\(32\) "2010-01-02 (00:00:00|03:04:05)\.654321-08:00"
 string\(32\) "2012-03-31 12:34:56\.000000-07:00"
 string\(32\) "1970-01-01 12:34:56\.000000-08:00"
 string\(32\) "1970-01-01 19:00:00\.000000-05:00"
diff --git a/tests/immutable_override_008.phpt b/tests/immutable_override_008.phpt
index 567ae25..b7dfa4a 100644
--- a/tests/immutable_override_008.phpt
+++ b/tests/immutable_override_008.phpt
@@ -66,7 +66,7 @@ string\(32\) "2010-09-02 03:04:05\.000000-07:00"
 string\(32\) "2010-12-24 03:04:05\.000000-08:00"
 string\(32\) "2010-01-02 05:00:00\.000000\+09:00"
 string\(32\) "2010-01-02 00:00:59\.000000-08:00"
-string\(32\) "2010-01-02 (00|03):(00|04):(00|05)\.654321-08:00"
+string\(32\) "2010-01-02 (00:00:00|03:04:05)\.654321-08:00"
 string\(32\) "2012-03-31 12:34:56\.000000-07:00"
 string\(32\) "1970-01-01 12:34:56\.000000-08:00"
 string\(32\) "1970-01-01 19:00:00\.000000-05:00"
diff --git a/timecop_php7.c b/timecop_php7.c
index df430cd..0e95945 100644
--- a/timecop_php7.c
+++ b/timecop_php7.c
@@ -1433,6 +1433,8 @@ static void _timecop_date_create_from_format(INTERNAL_FUNCTION_PARAMETERS, int i
 
 	call_php_function_with_3_params(ORIG_FUNC_NAME("date_create_from_format"), &dt, &orig_format, &orig_time, orig_timezone);
 	if (Z_TYPE(dt) == IS_FALSE) {
+		zval_ptr_dtor(&orig_format);
+		zval_ptr_dtor(&orig_time);
 		RETURN_FALSE;
 	}
 
@@ -1443,6 +1445,7 @@ static void _timecop_date_create_from_format(INTERNAL_FUNCTION_PARAMETERS, int i
 
 		if (immutable) {
 			call_php_method_with_1_params(NULL, TIMECOP_G(ce_DateTimeImmutable), "createfrommutable", &dti, &dt);
+			zval_ptr_dtor(&dt);
 			RETURN_ZVAL(&dti, 1, 1);
 		}
 
@@ -1458,7 +1461,11 @@ static void _timecop_date_create_from_format(INTERNAL_FUNCTION_PARAMETERS, int i
 	call_php_method_with_1_params(&dt, TIMECOP_G(ce_DateTime), "format", &fixed_time, &tmp);
 	zval_ptr_dtor(&tmp);
 
-	if (memchr(orig_format_str, 'g', orig_format_len) ||
+	if (
+#if PHP_VERSION_ID >= 70300
+		memchr(orig_format_str, 'u', orig_format_len) ||
+#endif
+		memchr(orig_format_str, 'g', orig_format_len) ||
 		memchr(orig_format_str, 'h', orig_format_len) ||
 		memchr(orig_format_str, 'G', orig_format_len) ||
 		memchr(orig_format_str, 'H', orig_format_len) ||
@@ -1478,14 +1485,6 @@ static void _timecop_date_create_from_format(INTERNAL_FUNCTION_PARAMETERS, int i
 			   memchr(orig_format_str, 'l', orig_format_len) ||
 			   memchr(orig_format_str, 'U', orig_format_len)) {
 		ZVAL_STRING(&fixed_format, "Y-m-d H:i:s.??????");
-	} else if (memchr(orig_format_str, 'u', orig_format_len)) {
-		#if PHP_VERSION_ID >= 70300
-				ZVAL_STRING(&fixed_format, "Y-m-d ??:??:??.??????");
-		#elif PHP_VERSION_ID >= 70100
-				ZVAL_STRING(&fixed_format, "Y-m-d H:i:s.u");
-		#else
-				ZVAL_STRING(&fixed_format, "Y-m-d H:i:s.??????");
-		#endif
 	} else {
 		#if PHP_VERSION_ID >= 70100
 				ZVAL_STRING(&fixed_format, "Y-m-d H:i:s.u");