Skip to content

Commit

Permalink
Merge pull request #29 from Hywan/util_date
Browse files Browse the repository at this point in the history
Strict hours and days format
  • Loading branch information
evert committed Nov 6, 2014
2 parents f9b05b4 + e893b01 commit c0316d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ static function parseHTTPDate($dateHeader) {
$month = '(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)';
$weekday = '(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)';
$wkday = '(Mon|Tue|Wed|Thu|Fri|Sat|Sun)';
$time = '[0-2]\d(\:[0-5]\d){2}';
$date3 = $month . ' ([1-3]\d| \d)';
$date2 = '[0-3]\d\-' . $month . '\-\d\d';
$time = '([0-1]\d|2[0-3])(\:[0-5]\d){2}';
$date3 = $month . ' ([12]\d|3[01]| [1-9])';
$date2 = '(0[1-9]|[12]\d|3[01])\-' . $month . '\-\d{2}';
//4-digit year cannot begin with 0 - unix timestamp begins in 1970
$date1 = '[0-3]\d ' . $month . ' [1-9]\d{3}';
$date1 = '(0[1-9]|[12]\d|3[01]) ' . $month . ' [1-9]\d{3}';

//ANSI C's asctime() format
//4-digit year cannot begin with 0 - unix timestamp begins in 1970
Expand Down
10 changes: 10 additions & 0 deletions tests/HTTP/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ function testParseHTTPDateFail() {
'Wednesday, 13-Oct-10 10:26:00 UTC',
// No space before the 6
'Wed Oct 6 10:26:00 2010',
// Invalid day
'Wed Oct 0 10:26:00 2010',
'Wed Oct 32 10:26:00 2010',
'Wed, 0 Oct 2010 10:26:00 GMT',
'Wed, 32 Oct 2010 10:26:00 GMT',
'Wednesday, 32-Oct-10 10:26:00 GMT',
// Invalid hour
'Wed, 13 Oct 2010 24:26:00 GMT',
'Wednesday, 13-Oct-10 24:26:00 GMT',
'Wed Oct 13 24:26:00 2010',
);

foreach($times as $time) {
Expand Down

0 comments on commit c0316d1

Please sign in to comment.