You are here

public static function Time::createFromHtml5Format in Time Field For Drupal 8.x / 9.x 2.x

Same name and namespace in other branches
  1. 8 src/Time.php \Drupal\time_field\Time::createFromHtml5Format()

Create Time object based on html5 formatted string.

Parameters

string $string: Time string eg `12:30:20` or `12:30`.

Return value

\Drupal\time_field\Time Time object created html5 formatted string

2 calls to Time::createFromHtml5Format()
TimeElement::valueCallback in src/Element/TimeElement.php
Determines how user input is mapped to an element's #value property.
TimeTest::testItCanBeCreatedByHtml5String in tests/src/Unit/TimeTest.php
Test it can be created by html5 string.

File

src/Time.php, line 160

Class

Time
Time class represents time of day.

Namespace

Drupal\time_field

Code

public static function createFromHtml5Format($string) {
  if (!$string) {
    return new self();
  }
  $inputs = explode(':', $string);
  if (count($inputs) === 2) {
    $inputs[] = 0;
  }
  list($hour, $minute, $seconds) = $inputs;
  return new self($hour, $minute, $seconds);
}