Skip to content

Instantly share code, notes, and snippets.

@chillu
Last active December 28, 2015 10:39
Show Gist options
  • Save chillu/7487287 to your computer and use it in GitHub Desktop.
Save chillu/7487287 to your computer and use it in GitHub Desktop.
<?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