Skip to content

Commit 1b757b3

Browse files
committed
Merge branch '0.8'
2 parents 7ce7a80 + 0e9044d commit 1b757b3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

library/Rules/Date.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public function validate($input)
3434
$dateFromFormat = DateTime::createFromFormat($this->format, $input);
3535

3636
return $dateFromFormat
37-
&& $input === date($this->format, $dateFromFormat->getTimestamp());
37+
&& $input === $dateFromFormat->format($this->format);
3838
}
3939
}

tests/Rules/DateTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,35 @@ public function testDateTimeExceptionalFormatsThatShouldBeValid()
7272
$this->dateValidator = new Date('r');
7373
$this->assertTrue($this->dateValidator->assert('Thu, 29 Dec 2005 01:02:03 +0000'));
7474
}
75+
76+
/**
77+
* Test that datetime strings with timezone information are valid independent on the system's timezone setting.
78+
*
79+
* @param string $systemTimezone
80+
* @param string $input
81+
* @dataProvider providerForDateTimeTimezoneStrings
82+
*/
83+
public function testDateTimeSystemTimezoneIndependent($systemTimezone, $format, $input)
84+
{
85+
date_default_timezone_set($systemTimezone);
86+
$this->dateValidator = new Date($format);
87+
$this->assertTrue($this->dateValidator->assert($input));
88+
}
89+
90+
/**
91+
*
92+
* @return array
93+
*/
94+
public function providerForDateTimeTimezoneStrings(){
95+
return array(
96+
array('UTC', 'c', '2005-12-30T01:02:03+01:00',),
97+
array('UTC', 'c', '2004-02-12T15:19:21+00:00',),
98+
array('UTC', 'r', 'Thu, 29 Dec 2005 01:02:03 +0000',),
99+
array('Europe/Amsterdam', 'c', '2005-12-30T01:02:03+01:00',),
100+
array('Europe/Amsterdam', 'c', '2004-02-12T15:19:21+00:00',),
101+
array('Europe/Amsterdam', 'r', 'Thu, 29 Dec 2005 01:02:03 +0000',),
102+
);
103+
}
104+
75105
}
76106

0 commit comments

Comments
 (0)