Skip to content

Instantly share code, notes, and snippets.

@ahebrank
Last active May 24, 2018 13:27
Show Gist options
  • Select an option

  • Save ahebrank/6be7a28dfcf4257fe0c665c53f14ec3a to your computer and use it in GitHub Desktop.

Select an option

Save ahebrank/6be7a28dfcf4257fe0c665c53f14ec3a to your computer and use it in GitHub Desktop.
diff --git a/src/Plugin/views/style/FullCalendar.php b/src/Plugin/views/style/FullCalendar.php
index afd1bc4..fcc45e5 100644
--- a/src/Plugin/views/style/FullCalendar.php
+++ b/src/Plugin/views/style/FullCalendar.php
@@ -279,6 +279,19 @@ class FullCalendar extends StylePluginBase {
return $settings;
}
+ /**
+ * Reset a date to UTC
+ *
+ * @param [type] $date
+ * @param \DateTimeZone $tz
+ * @return string date
+ */
+ private function tzConvert($date, \DateTimeZone $tz) {
+ $dt = new \DateTime($date, new \DateTimeZone('UTC'));
+ $dt->setTimezone($tz);
+ return $dt->format('Y-m-d') . 'T' . $dt->format('H:i:s');
+ }
+
/**
* @todo.
*/
@@ -325,6 +338,8 @@ class FullCalendar extends StylePluginBase {
], $classes);
$class = (count($classes)) ? implode(' ', array_unique($classes)) : '';
+ $tz = new \DateTimeZone(drupal_get_user_timezone());
+
$event = [];
foreach ($date_fields as $field) {
// Filter fields without value.
@@ -333,8 +348,8 @@ class FullCalendar extends StylePluginBase {
}
foreach ($field['value'] as $index => $item) {
- $start = $item['raw']->value;
- $end = $item['raw']->end_value;
+ $start = $this->tzConvert($item['raw']->value, $tz);
+ $end = $this->tzConvert($item['raw']->end_value, $tz);
$all_day = FALSE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment