@@ -40,15 +40,6 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
40
40
*/
41
41
private $ parseFormat ;
42
42
43
- /**
44
- * Whether to parse by appending a pipe "|" to the parse format.
45
- *
46
- * This only works as of PHP 5.3.7.
47
- *
48
- * @var bool
49
- */
50
- private $ parseUsingPipe ;
51
-
52
43
/**
53
44
* Transforms a \DateTime instance to a string.
54
45
*
@@ -57,18 +48,15 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
57
48
* @param string $inputTimezone The name of the input timezone
58
49
* @param string $outputTimezone The name of the output timezone
59
50
* @param string $format The date format
60
- * @param bool $parseUsingPipe Whether to parse by appending a pipe "|" to the parse format
61
51
*
62
52
* @throws UnexpectedTypeException if a timezone is not a string
63
53
*/
64
- public function __construct ($ inputTimezone = null , $ outputTimezone = null , $ format = 'Y-m-d H:i:s ' , $ parseUsingPipe = true )
54
+ public function __construct ($ inputTimezone = null , $ outputTimezone = null , $ format = 'Y-m-d H:i:s ' )
65
55
{
66
56
parent ::__construct ($ inputTimezone , $ outputTimezone );
67
57
68
58
$ this ->generateFormat = $ this ->parseFormat = $ format ;
69
59
70
- $ this ->parseUsingPipe = $ parseUsingPipe || null === $ parseUsingPipe ;
71
-
72
60
// See http://php.net/manual/en/datetime.createfromformat.php
73
61
// The character "|" in the format makes sure that the parts of a date
74
62
// that are *not* specified in the format are reset to the corresponding
@@ -77,7 +65,7 @@ public function __construct($inputTimezone = null, $outputTimezone = null, $form
77
65
// where the time corresponds to the current server time.
78
66
// With "|" and "Y-m-d", "2010-02-03" becomes "2010-02-03 00:00:00",
79
67
// which is at least deterministic and thus used here.
80
- if ($ this -> parseUsingPipe && false === strpos ($ this ->parseFormat , '| ' )) {
68
+ if (false === strpos ($ this ->parseFormat , '| ' )) {
81
69
$ this ->parseFormat .= '| ' ;
82
70
}
83
71
}
@@ -147,70 +135,6 @@ public function reverseTransform($value)
147
135
}
148
136
149
137
try {
150
- // On PHP versions < 5.3.7 we need to emulate the pipe operator
151
- // and reset parts not given in the format to their equivalent
152
- // of the UNIX base timestamp.
153
- if (!$ this ->parseUsingPipe ) {
154
- list ($ year , $ month , $ day , $ hour , $ minute , $ second ) = explode ('- ' , $ dateTime ->format ('Y-m-d-H-i-s ' ));
155
-
156
- // Check which of the date parts are present in the pattern
157
- preg_match (
158
- '/( ' .
159
- '(?P<day>[djDl])| ' .
160
- '(?P<month>[FMmn])| ' .
161
- '(?P<year>[Yy])| ' .
162
- '(?P<hour>[ghGH])| ' .
163
- '(?P<minute>i)| ' .
164
- '(?P<second>s)| ' .
165
- '(?P<dayofyear>z)| ' .
166
- '(?P<timestamp>U)| ' .
167
- '[^djDlFMmnYyghGHiszU] ' .
168
- ')*/ ' ,
169
- $ this ->parseFormat ,
170
- $ matches
171
- );
172
-
173
- // preg_match() does not guarantee to set all indices, so
174
- // set them unless given
175
- $ matches = array_merge (array (
176
- 'day ' => false ,
177
- 'month ' => false ,
178
- 'year ' => false ,
179
- 'hour ' => false ,
180
- 'minute ' => false ,
181
- 'second ' => false ,
182
- 'dayofyear ' => false ,
183
- 'timestamp ' => false ,
184
- ), $ matches );
185
-
186
- // Reset all parts that don't exist in the format to the
187
- // corresponding part of the UNIX base timestamp
188
- if (!$ matches ['timestamp ' ]) {
189
- if (!$ matches ['dayofyear ' ]) {
190
- if (!$ matches ['day ' ]) {
191
- $ day = 1 ;
192
- }
193
- if (!$ matches ['month ' ]) {
194
- $ month = 1 ;
195
- }
196
- }
197
- if (!$ matches ['year ' ]) {
198
- $ year = 1970 ;
199
- }
200
- if (!$ matches ['hour ' ]) {
201
- $ hour = 0 ;
202
- }
203
- if (!$ matches ['minute ' ]) {
204
- $ minute = 0 ;
205
- }
206
- if (!$ matches ['second ' ]) {
207
- $ second = 0 ;
208
- }
209
- $ dateTime ->setDate ($ year , $ month , $ day );
210
- $ dateTime ->setTime ($ hour , $ minute , $ second );
211
- }
212
- }
213
-
214
138
if ($ this ->inputTimezone !== $ this ->outputTimezone ) {
215
139
$ dateTime ->setTimezone (new \DateTimeZone ($ this ->inputTimezone ));
216
140
}
0 commit comments