You are here

public function Time::on 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::on()

DateTime with attached time to it.

Parameters

\DateTime $dateTime: Datetime to attach time to it.

Return value

\DateTime Datetime with attached time

File

src/Time.php, line 206

Class

Time
Time class represents time of day.

Namespace

Drupal\time_field

Code

public function on(\DateTime $dateTime) {
  $instance = new \DateTime();
  $instance
    ->setTimestamp($dateTime
    ->getTimestamp());
  $instance
    ->setTime(0, 0, 0);
  $instance
    ->setTimestamp($instance
    ->getTimestamp() + $this
    ->getTimestamp());
  return $instance;
}