You are here

protected function DateRecurOccurrences::massageDateValueForStorage in Recurring Dates Field 3.0.x

Same name and namespace in other branches
  1. 8.2 src/DateRecurOccurrences.php \Drupal\date_recur\DateRecurOccurrences::massageDateValueForStorage()
  2. 3.x src/DateRecurOccurrences.php \Drupal\date_recur\DateRecurOccurrences::massageDateValueForStorage()
  3. 3.1.x src/DateRecurOccurrences.php \Drupal\date_recur\DateRecurOccurrences::massageDateValueForStorage()

Convert date ready to be inserted into database column.

Parameters

\DateTimeInterface $date: A date time object.

\Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem $item: The date recur field item.

Return value

string The date value for storage.

1 call to DateRecurOccurrences::massageDateValueForStorage()
DateRecurOccurrences::saveItem in src/DateRecurOccurrences.php
Create table rows from occurrences for a single field value.

File

src/DateRecurOccurrences.php, line 385

Class

DateRecurOccurrences
Manages occurrences tables and the data that populates them.

Namespace

Drupal\date_recur

Code

protected function massageDateValueForStorage(\DateTimeInterface $date, DateRecurItem $item) : string {

  // Convert native timezone to UTC.
  $date
    ->setTimezone(new \DateTimeZone(DateRecurItem::STORAGE_TIMEZONE));

  // If storage does not allow time, then reset to midday.
  $storageFormat = $item
    ->getDateStorageFormat();
  if ($storageFormat == DateRecurItem::DATE_STORAGE_FORMAT) {
    $date
      ->setTime(12, 0, 0);
  }
  return $date
    ->format($storageFormat);
}