Last active
December 28, 2015 10:39
-
-
Save chillu/7487287 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Behat\Behat\Context\BehatContext; | |
class MyFeatureContext extends BehatContext { | |
protected $dateFormat = 'Y-m-d'; | |
/** | |
* Transforms relative date statements compatible with strtotime(). | |
* Example: "date 2 days ago" might return "2013-10-10" if its currently | |
* the 12th of October 2013. Customize through {@link setDateFormat()}. | |
* | |
* @Transform /^(?:(the|a)) date of (?<val>.*)$/ | |
*/ | |
public function castRelativeToAbsoluteDate($prefix, $val) { | |
$timestamp = strtotime($val); | |
if(!$timestamp) { | |
throw new \InvalidArgumentException(sprintf( | |
"Can't resolve '%s' into a valid datetime value", | |
$val | |
)); | |
} | |
return date($this->dateFormat, $timestamp); | |
} | |
public function getDateFormat() { | |
return $this->dateFormat; | |
} | |
public function setDateFormat($format) { | |
$this->dateFormat = $format; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment