Skip to content

Commit

Permalink
[2.0][http-foundation] Fix Response::getDate method
Browse files Browse the repository at this point in the history
  • Loading branch information
benja-M-1 authored and fabpot committed Sep 30, 2012
1 parent 5984dee commit 1a53b12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Symfony/Component/HttpFoundation/HeaderBag.php
Expand Up @@ -226,7 +226,9 @@ public function remove($key)
* @param string $key The parameter key
* @param \DateTime $default The default value
*
* @return \DateTime The filtered value
* @return null|\DateTime The filtered value
*
* @throws \RuntimeException When the HTTP header is not parseable
*
* @api
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Response.php
Expand Up @@ -430,7 +430,7 @@ public function mustRevalidate()
*/
public function getDate()
{
return $this->headers->getDate('Date');
return $this->headers->getDate('Date', new \DateTime());
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php
Expand Up @@ -40,6 +40,10 @@ public function testGetDate()
$now = $this->createDateTimeNow();
$response->headers->set('Date', $now->format(DATE_RFC2822));
$this->assertEquals(0, $now->diff($response->getDate())->format('%s'), '->getDate() returns the date when the header has been modified');

$response = new Response('', 200);
$response->headers->remove('Date');
$this->assertInstanceOf('\DateTime', $response->getDate());
}

public function testGetMaxAge()
Expand Down

0 comments on commit 1a53b12

Please sign in to comment.