You are here

function views_timelinejs_convert_to_timestamp in Views TimelineJS integration 7

Converts a given time and date into timestamp with Drupals timezone.

Parameters

string $value: The date to be converted.

string $date_format: The format of the date.

string $timezone: The timezone of the date.

string $db_timezone: The Drupal timezone.

Return value

string Timestamp.

4 calls to views_timelinejs_convert_to_timestamp()
views_timelinejs_date_iso_source_date_field_conversion in plugins/date_sources/date_iso_field.inc
Converts ISO date field formats, forces TimelineJS to ignore browser TZ.
views_timelinejs_date_source_date_field_conversion in plugins/date_sources/date_field.inc
Converts date field formats, forces TimelineJS to ignore browser timezone.
views_timelinejs_date_source_post_date_conversion in plugins/date_sources/post_date.inc
Converts post date formats, forces TimelineJS to ignore browser TZ.
views_timelinejs_date_stamp_source_date_field_conversion in plugins/date_sources/date_stamp_field.inc
Converts date stamp field formats, forces TimelineJS to ignore browser TZ.

File

./views_timelinejs.module, line 195
Views TimelineJS API, theming, libraries, etc.

Code

function views_timelinejs_convert_to_timestamp($value, $date_format, $timezone, $db_timezone) {

  // To avoid errors, if value is empty set it to unix epoch.
  if (empty($value)) {
    return "FALSE";
  }
  $timezone = new DateTimezone($timezone);
  $db_timezone = new DateTimezone($db_timezone);
  switch ($date_format) {
    case 'datestamp':
    case 'timestamp':
      $date = new DateTime();
      $date
        ->setTimezone($db_timezone);
      $date
        ->setTimestamp($value);
      break;
    default:
      $date = new DateTime($value, $db_timezone);
      break;
  }
  $date
    ->setTimezone($timezone);
  return $date
    ->format('U');
}