Skip to content

Commit

Permalink
Merge branch '0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemoody committed Apr 24, 2015
2 parents 7ce7a80 + 0e9044d commit 1b757b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/Rules/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public function validate($input)
$dateFromFormat = DateTime::createFromFormat($this->format, $input);

return $dateFromFormat
&& $input === date($this->format, $dateFromFormat->getTimestamp());
&& $input === $dateFromFormat->format($this->format);
}
}
30 changes: 30 additions & 0 deletions tests/Rules/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,35 @@ public function testDateTimeExceptionalFormatsThatShouldBeValid()
$this->dateValidator = new Date('r');
$this->assertTrue($this->dateValidator->assert('Thu, 29 Dec 2005 01:02:03 +0000'));
}

/**
* Test that datetime strings with timezone information are valid independent on the system's timezone setting.
*
* @param string $systemTimezone
* @param string $input
* @dataProvider providerForDateTimeTimezoneStrings
*/
public function testDateTimeSystemTimezoneIndependent($systemTimezone, $format, $input)
{
date_default_timezone_set($systemTimezone);
$this->dateValidator = new Date($format);
$this->assertTrue($this->dateValidator->assert($input));
}

/**
*
* @return array
*/
public function providerForDateTimeTimezoneStrings(){
return array(
array('UTC', 'c', '2005-12-30T01:02:03+01:00',),
array('UTC', 'c', '2004-02-12T15:19:21+00:00',),
array('UTC', 'r', 'Thu, 29 Dec 2005 01:02:03 +0000',),
array('Europe/Amsterdam', 'c', '2005-12-30T01:02:03+01:00',),
array('Europe/Amsterdam', 'c', '2004-02-12T15:19:21+00:00',),
array('Europe/Amsterdam', 'r', 'Thu, 29 Dec 2005 01:02:03 +0000',),
);
}

}

0 comments on commit 1b757b3

Please sign in to comment.