{"id":1556211,"date":"2018-06-19T08:56:18","date_gmt":"2018-06-19T15:56:18","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/"},"modified":"2018-06-19T08:56:18","modified_gmt":"2018-06-19T15:56:18","slug":"function-to-automatically-change-any-greenwich-time-events-to-local-time","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/","title":{"rendered":"Function to automatically change any Greenwich time events to local time"},"content":{"rendered":"<p>Hi,<br \/>\nI would love a utility to automatically screen events for Greenwich time and convert them to the default local time of my WordPress site.  I am having chronic problems with imported events coming in with the wrong time.<\/p>\n<p>Here is a code snippet from a previous post.  Can this be modified for the purpose?  <\/p>\n<p>Thank you.<\/p>\n<p>&lt;?php<br \/>\n2 class Imported_Events_Timezone_Modifier {<br \/>\n3 \tprotected $source;<br \/>\n4 \tprotected $target_timezone;<br \/>\n5<br \/>\n6 \tpublic function __construct( $source, $target_timezone ) {<br \/>\n7 \t\t$this-&gt;source = $source;<br \/>\n8 \t\t$this-&gt;target_timezone = $target_timezone;<br \/>\n9 \t}<br \/>\n10<br \/>\n11 \tpublic function __invoke( $event, $record ) {<br \/>\n12 \t\t# Only run if the event is being imported from the specified source<br \/>\n13 \t\tif ( $this-&gt;source === null || $this-&gt;source === $record-&gt;meta[&#8216;source&#8217;] ) {<br \/>\n14 \t\t\tadd_action(<br \/>\n15 \t\t\t\t&#8216;tribe_events_update_meta&#8217;,<br \/>\n16 \t\t\t\t[ $this, &#8216;post_creation&#8217; ]<br \/>\n17 \t\t\t);<br \/>\n18 \t\t}<br \/>\n19<br \/>\n20 \t\treturn $event;<br \/>\n21 \t}<br \/>\n22<br \/>\n23 \tpublic function post_creation( $event_id ) {<br \/>\n24 \t\t# Run once only<br \/>\n25 \t\tremove_action(<br \/>\n26 \t\t\t&#8216;tribe_events_update_meta&#8217;,<br \/>\n27 \t\t\t[ $this, &#8216;post_creation&#8217; ]<br \/>\n28 \t\t);<br \/>\n29<br \/>\n30 \t\t$new_start_date = $this-&gt;convert( get_post_meta( $event_id, &#8216;_EventStartDateUTC&#8217;, true ) );<br \/>\n31 \t\t$new_end_date = $this-&gt;convert( get_post_meta( $event_id, &#8216;_EventEndDateUTC&#8217;, true ) );<br \/>\n32<br \/>\n33 \t\tif ( $new_start_date &amp;&amp; $new_end_date ) {<br \/>\n34 \t\t\tupdate_post_meta( $event_id, &#8216;_EventStartDate&#8217;, $new_start_date );<br \/>\n35 \t\t\tupdate_post_meta( $event_id, &#8216;_EventEndDate&#8217;, $new_end_date );<br \/>\n36 \t\t\tupdate_post_meta( $event_id, &#8216;_EventTimezone&#8217;, $this-&gt;target_timezone );<br \/>\n37 \t\t}<br \/>\n38 \t}<br \/>\n39<br \/>\n40 \tprotected function convert( $datetime ) {<br \/>\n41 \t\ttry {<br \/>\n42 \t\t\t$datetime = new DateTime( $datetime );<br \/>\n43 \t\t\t$datetime-&gt;setTimezone( new DateTimeZone( &#8216;UTC&#8217; ) );<br \/>\n44 \t\t\t$datetime-&gt;setTimezone( new DateTimeZone( $this-&gt;target_timezone ) );<br \/>\n45 \t\t\treturn $datetime-&gt;format( Tribe__Date_Utils::DBDATETIMEFORMAT );<br \/>\n46 \t\t}<br \/>\n47 \t\tcatch ( Exception $e ) {<br \/>\n48 \t\t\treturn false;<br \/>\n49 \t\t}<br \/>\n50 \t}<br \/>\n51 }<br \/>\n52<br \/>\n53 function modify_imported_event_timezones( $source_feed, $target_timezone ) {<br \/>\n54 \t$modifier = new Imported_Events_Timezone_Modifier( $source_feed, $target_timezone );<br \/>\n55 \tadd_filter( &#8216;tribe_aggregator_before_insert_event&#8217;, $modifier, 10, 2 );<br \/>\n56 }<br \/>\n57<br \/>\n58 # 1) Set the first param to null to operate on all import sources<br \/>\n59 # 2) Update the second param to the desired timezone (it must be<br \/>\n60 #    a valid timezone supported and understood by your PHP runtime)<br \/>\n61 modify_imported_event_timezones(<br \/>\n62 \t&#8216;https:\/\/some.source\/ical-feed.ics&#8217;,<br \/>\n63 \t&#8216;America\/Vancouver&#8217;<br \/>\n64 ); <\/p>\n","protected":false},"template":"","class_list":["post-1556211","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Function to automatically change any Greenwich time events to local time -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Function to automatically change any Greenwich time events to local time -\" \/>\n<meta property=\"og:description\" content=\"Hi, I would love a utility to automatically screen events for Greenwich time and convert them to the default local time of my WordPress site. I am having chronic problems with imported events coming in with the wrong time. Here is a code snippet from a previous post. Can this be modified for the purpose? [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/\",\"name\":\"Function to automatically change any Greenwich time events to local time -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2018-06-19T15:56:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Calendar Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Event Aggregator\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/event-aggregator\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Function to automatically change any Greenwich time events to local time\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Function to automatically change any Greenwich time events to local time -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/","og_locale":"en_US","og_type":"article","og_title":"Function to automatically change any Greenwich time events to local time -","og_description":"Hi, I would love a utility to automatically screen events for Greenwich time and convert them to the default local time of my WordPress site. I am having chronic problems with imported events coming in with the wrong time. Here is a code snippet from a previous post. Can this be modified for the purpose? [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/","name":"Function to automatically change any Greenwich time events to local time -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2018-06-19T15:56:18+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/function-to-automatically-change-any-greenwich-time-events-to-local-time\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Calendar Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/"},{"@type":"ListItem","position":4,"name":"Event Aggregator","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/event-aggregator\/"},{"@type":"ListItem","position":5,"name":"Function to automatically change any Greenwich time events to local time"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1556211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1556211\/revisions"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1556211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}