You are here

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

Format for widget.

Parameters

bool $show_seconds: (Optional) Whether to include the seconds in the output regardless of the current time value. Defaults to TRUE. This is to ensure the option to adjust seconds is not shown in the widget when we don't want it to.

Return value

string Formatted time eg `23:12:00`

File

src/Time.php, line 199

Class

Time
Time class represents time of day.

Namespace

Drupal\time_field

Code

public function formatForWidget($show_seconds = TRUE) {
  $time = self::baseDateTime();
  $time
    ->setTimestamp($time
    ->getTimestamp() + $this
    ->getTimestamp());

  // If we're showing seconds, include the seconds in the output.
  if ($show_seconds) {
    return $time
      ->format('H:i:s');
  }

  // Otherwise, exclude the seconds in the output.
  return $time
    ->format('H:i');
}