You are here

public function DurationService::getDateIntervalFromDurationString in Duration Field 8.2

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

Convert an ISO 8601 string into a PHP DateInterval object.

Parameters

string $durationString: Ann ISO 8601 duration string.

Return value

\DateInterval A PHP DateInterval object for the given ISO 8601 duration string.

Throws

Drupal\duration_field\Exception\InvalidDurationException Thrown if $value is not a valid ISO 8601 Duration string.

Overrides DurationServiceInterface::getDateIntervalFromDurationString

2 calls to DurationService::getDateIntervalFromDurationString()
DurationService::convertDateArrayToDateInterval in src/Service/DurationService.php
Convert a PHP DateInterval object to an ISO 8601 duration string.
DurationService::getSecondsFromDurationString in src/Service/DurationService.php
Get the number of seconds an ISO 8601 duration string represents.

File

src/Service/DurationService.php, line 73

Class

DurationService
Provides services for the Duration Field module.

Namespace

Drupal\duration_field\Service

Code

public function getDateIntervalFromDurationString($durationString) {

  // Note: this will throw
  // \Drupal\duration_field\Exception\InvalidDurationException if $value is
  // an invalid ISO 8601 Duration string.
  $this
    ->checkDurationInvalid($durationString);
  if (!empty($durationString)) {
    return new DateInterval($durationString);
  }
  else {
    return $this
      ->createEmptyDateInterval();
  }
}