You are here

public static function DurationService::checkDurationInvalid in Duration Field 8

Same name and namespace in other branches
  1. 8.2 src/Service/DurationService.php \Drupal\duration_field\Service\DurationService::checkDurationInvalid()
  2. 3.0.x src/Service/DurationService.php \Drupal\duration_field\Service\DurationService::checkDurationInvalid()

Checks if a given duration is a valid Iso8601 duration format.

@input string $duration The string whose format should be checked

Return value

bool

  • TRUE if the string is a valid format
  • FALSE if it's an invalid format

Overrides DurationServiceInterface::checkDurationInvalid

See also

http://en.wikipedia.org/wiki/Iso8601#Durations

1 call to DurationService::checkDurationInvalid()
DurationData::setValue in src/Plugin/DataType/DurationData.php
Sets the data value.

File

src/Service/DurationService.php, line 20

Class

DurationService
Provides services for the Duration Field module.

Namespace

Drupal\duration_field\Service

Code

public static function checkDurationInvalid($duration) {
  if (!empty($duration) && !preg_match(self::DURATION_FIELD_PATTERN, $duration)) {
    throw new InvalidDurationException($duration . ' is not a valid duration');
  }
  return FALSE;
}