Skip to content

Commit

Permalink
Merge pull request #198 from cakephp/test-now-times
Browse files Browse the repository at this point in the history
Test now times
  • Loading branch information
markstory authored May 30, 2019
2 parents ba0de05 + 98e2ee7 commit 5af4766
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Traits/RelativeKeywordTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ trait RelativeKeywordTrait
*/
public static function hasRelativeKeywords($time)
{
// Just a time
if (preg_match('/^[0-2][0-9]:[0-5][0-9](?::[0-5][0-9])?$/', $time)) {
return true;
}

// skip common format with a '-' in it
if (preg_match('/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/', $time) !== 1) {
return preg_match(static::$relativePattern, $time) > 0;
Expand Down
2 changes: 2 additions & 0 deletions tests/DateTime/TestingAidsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public function testParseRelativeWithTestValueSet($class)
$notNow = $class::parse('2013-09-01 05:15:05');
$class::setTestNow($notNow);

$this->assertSame('2013-09-01 06:30:00', $class::parse('06:30:00')->toDateTimeString());

$this->assertSame('2013-09-01 05:10:05', $class::parse('5 minutes ago')->toDateTimeString());

$this->assertSame('2013-08-25 05:15:05', $class::parse('1 week ago')->toDateTimeString());
Expand Down

7 comments on commit 5af4766

@joshbmarshall
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change introduced a breaking change. Try the following you'll see that you get different time strings for timezone based parsing if a leading 0 is left off:

	var_dump(\Cake\Chronos\Chronos::parse('8:00:00')->toTimeString());
	var_dump(\Cake\Chronos\Chronos::parse('8:00:00', 'Etc/UTC')->toTimeString());
	var_dump(\Cake\Chronos\Chronos::parse('08:00:00')->toTimeString());
	var_dump(\Cake\Chronos\Chronos::parse('08:00:00', 'Etc/UTC')->toTimeString());

@dereuromark
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it should probably be less strict on the leading zeros.

@joshbmarshall
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to create an Issue report on this?

@lorenzo
Copy link
Member

@lorenzo lorenzo commented on 5af4766 Jun 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to create an Issue report on this?

yes, please

@dereuromark
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did for you now: #201

@dereuromark
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshbmarshall Are you able to create a PR that fixes it?

@joshbmarshall
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just went to do this, have been beaten to it :) 755cca8

Please sign in to comment.