File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,7 @@ protected function doClean($value)
117117 else
118118 {
119119 $ dateMax = new DateTime ($ max );
120+ $ dateMax ->setTimezone (new DateTimeZone (date_default_timezone_get ()));
120121 $ max = $ dateMax ->format ('YmdHis ' );
121122 $ maxError = $ dateMax ->format ($ this ->getOption ('date_format_range_error ' ));
122123 }
@@ -140,6 +141,7 @@ protected function doClean($value)
140141 else
141142 {
142143 $ dateMin = new DateTime ($ min );
144+ $ dateMin ->setTimezone (new DateTimeZone (date_default_timezone_get ()));
143145 $ min = $ dateMin ->format ('YmdHis ' );
144146 $ minError = $ dateMin ->format ($ this ->getOption ('date_format_range_error ' ));
145147 }
Original file line number Diff line number Diff line change 1010
1111require_once (__DIR__ .'/../../bootstrap/unit.php ' );
1212
13- $ t = new lime_test (52 );
13+ $ t = new lime_test (56 );
1414
1515$ v = new sfValidatorDate ();
1616
244244// did it convert from the other timezone to the default timezone?
245245$ date ->setTimezone ($ defaultTimezone );
246246$ t ->is ($ clean , $ date ->format ('Y-m-d H:i:s ' ), '->clean() respects incoming and default timezones ' );
247+
248+ // 'min' and 'max' options should be normalized to the default timezone
249+ $ v = new sfValidatorDateTime ([
250+ 'min ' => '2018-12-06T09:00:00Z '
251+ ], [
252+ 'min ' => 'min ' ,
253+ ]);
254+ try
255+ {
256+ $ v ->clean ('2018-12-06T09:59:59+01:00 ' );
257+ $ t ->fail ('->clean() throws an exception if the normalized date is before normalized min-option ' );
258+ }
259+ catch (sfValidatorError $ e )
260+ {
261+ $ t ->pass ('->clean() throws an exception if the normalized date is before normalized min-option ' );
262+ $ t ->is ($ e ->getMessage (), 'min ' , '->clean() adds correct min-message ' );
263+ }
264+ $ v = new sfValidatorDateTime ([
265+ 'max ' => '2018-12-06T09:00:00Z '
266+ ], [
267+ 'max ' => 'max ' ,
268+ ]);
269+ try
270+ {
271+ $ v ->clean ('2018-12-06T10:00:01+01:00 ' );
272+ $ t ->fail ('->clean() throws an exception if the normalized date is after normalized max-option ' );
273+ }
274+ catch (sfValidatorError $ e )
275+ {
276+ $ t ->pass ('->clean() throws an exception if the normalized date is after normalized max-option ' );
277+ $ t ->is ($ e ->getMessage (), 'max ' , '->clean() adds correct max-message ' );
278+ }
You can’t perform that action at this time.
0 commit comments