RelativeKeywordTrait
Provides methods for testing if strings contain relative keywords.
Table of Contents
Properties
- $relativePattern : string
- Regex for relative period.
Methods
- hasRelativeKeywords() : bool
- Determine if there is a relative keyword in the time string, this is to create dates relative to now for test instances. e.g.: next tuesday
- isRelativeOnly() : bool
- Determines if there is no fixed date in the time string.
- isTimeExpression() : bool
- Determine if there is just a time in the time string
Properties
$relativePattern
Regex for relative period.
protected
static string
$relativePattern
= '/this|next|last|tomorrow|yesterday|midnight|today|[+-]|first|last|ago/i'
Methods
hasRelativeKeywords()
Determine if there is a relative keyword in the time string, this is to create dates relative to now for test instances. e.g.: next tuesday
public
static hasRelativeKeywords(string|null $time) : bool
Parameters
- $time : string|null
-
The time string to check.
Return values
bool —true if there is a keyword, otherwise false
isRelativeOnly()
Determines if there is no fixed date in the time string.
private
static isRelativeOnly(DateTimeInterface|string|null $time) : bool
Parameters
- $time : DateTimeInterface|string|null
-
The time string to check
Return values
bool —true if doesn't contain a fixed date
isTimeExpression()
Determine if there is just a time in the time string
private
static isTimeExpression(string $time) : bool
Parameters
- $time : string
-
The time string to check.
Return values
bool —true if there is a keyword, otherwise false