public function DurationService::checkDurationInvalid in Duration Field 3.0.x
Same name and namespace in other branches
- 8.2 src/Service/DurationService.php \Drupal\duration_field\Service\DurationService::checkDurationInvalid()
- 8 src/Service/DurationService.php \Drupal\duration_field\Service\DurationService::checkDurationInvalid()
Checks if a given string is a valid ISO 8601 duration string.
Parameters
string $duration: The string whose format should be checked.
Return value
bool
- TRUE if the string is a valid ISO 8601 duration string
- FALSE if it's an invalid format
Overrides DurationServiceInterface::checkDurationInvalid
See also
http://en.wikipedia.org/wiki/Iso8601#Durations
1 call to DurationService::checkDurationInvalid()
- DurationService::getDateIntervalFromDurationString in src/
Service/ DurationService.php - Convert an ISO 8601 string into a PHP DateInterval object.
File
- src/
Service/ DurationService.php, line 20
Class
- DurationService
- Provides services for the Duration Field module.
Namespace
Drupal\duration_field\ServiceCode
public function checkDurationInvalid($duration) {
if (!empty($duration) && !preg_match(Iso8601StringInterface::DURATION_STRING_PATTERN, $duration)) {
throw new InvalidDurationException('The submitted duration is not a valid duration string.');
}
return FALSE;
}