You are here

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

Same name and namespace in other branches
  1. 2.x src/Time.php \Drupal\time_field\Time::createFromTimestamp()

Creates Time object from timestamp.

Parameters

int $timestamp: Number of seconds passed through midnight must be between 0 and 86400.

Return value

\Drupal\time_field\Time Time object created based on timestamp

5 calls to Time::createFromTimestamp()
TimeConstraintValidator::validate in src/Plugin/Validation/Constraint/TimeConstraintValidator.php
Checks if the passed value is valid.
TimeFormatter::viewValue in src/Plugin/Field/FieldFormatter/TimeFormatter.php
Generate the output appropriate for one field item.
TimeRangeFormatter::viewValue in src/Plugin/Field/FieldFormatter/TimeRangeFormatter.php
Generate the output appropriate for one field item.
TimeTest::testItCanBeCreatedFromDayTimestamp in tests/src/Unit/TimeTest.php
Test it can be created from day timestamp.
time_field_tokens in ./time_field.tokens.inc
Implements hook_tokens().

File

src/Time.php, line 131

Class

Time
Time class represents time of day.

Namespace

Drupal\time_field

Code

public static function createFromTimestamp($timestamp) {
  self::assertInRange($timestamp, 0, 86400);
  $time = self::baseDateTime();
  $time
    ->setTimestamp($time
    ->getTimestamp() + $timestamp);
  return new self($time
    ->format('H'), $time
    ->format('i'), $time
    ->format('s'));
}