{"id":7868,"date":"2015-11-02T20:02:50","date_gmt":"2015-11-02T20:02:50","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/02\/fullcalendar-and-timezones-help-im-doing-it-wrong-open-source-projects-arshaw-fullcalendar\/"},"modified":"2015-11-02T20:02:50","modified_gmt":"2015-11-02T20:02:50","slug":"fullcalendar-and-timezones-help-im-doing-it-wrong-open-source-projects-arshaw-fullcalendar","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/02\/fullcalendar-and-timezones-help-im-doing-it-wrong-open-source-projects-arshaw-fullcalendar\/","title":{"rendered":"Fullcalendar and timezones. Help, I&#39;m doing it wrong-open source projects arshaw\/fullcalendar"},"content":{"rendered":"<p>I&#8217;m doing it wrong somehow. I&#8217;m getting tripped up on timezones with <code>Fullcalendar<\/code>. I&#8217;ve tried setting <code>ignoreTimezone<\/code> to true and false, but it doesn&#8217;t seem to matter. It&#8217;s in the code below in two places because I wasn&#8217;t sure from the doc where it goes.<\/p>\n<p>My data source is a hidden form field. Data that goes <em>out<\/em> of <code>FullCalendar<\/code> is adjusted by adding 5 hours (CDT). Data that goes <em>in<\/em> to <code>FullCalendar<\/code> isn&#8217;t adjusted by removing 5 hours.<\/p>\n<p>On the back-end, I&#8217;m just saving and returning the JSON string without processing it (or even decoding it)<\/p>\n<pre><code>Page Load:\n  Data In: Empty, no data\n  Data Edit: drag from noon to 2pm (CDT), then submit form\n  Data Out: Use clientEvent to get data, and JSON.stringify to put into form field.\n    [{\"id\":6844,\"title\":\"Open\",\"start\":\"2011-04-19T17:00:00.000Z\",\"end\":\"2011-04-19T19:00:00.000Z\",\"allDay\":false}]\n\nPage Load (after submitting form):\n  Data In: Use JSON.parse to load data from hidden form field.  This is the incoming data, but the event is shifted to 5pm (CDT) in the control.  \n    [{\"id\":6844,\"title\":\"Open\",\"start\":\"2011-04-19T17:00:00.000Z\",\"end\":\"2011-04-19T19:00:00.000Z\",\"allDay\":false}]\n  Data Out:  Without changing the control, it's now:\n    [{\"id\":6844,\"title\":\"Open\",\"start\":\"2011-04-19T22:00:00.000Z\",\"end\":\"2011-04-20T00:00:00.000Z\",\"allDay\":false}]\n<\/code><\/pre>\n<p>I setup the <code>Fullcalendar<\/code> like this:<\/p>\n<pre><code>\/\/ Fullcalendar for business hours page\n\njQuery(document).ready(function() {\n\n  jQuery('#edit-submit').bind(\"click\", business_hours_set);\n  jQuery('#edit-preview').bind(\"click\", business_hours_set);\n\n  jQuery('#calendar').fullCalendar({\n\n    \/\/ configure display\n    header: {\n      left: '',\n      center: '',\n      right: ''\n    },\n    ignoreTimezone: false,\n    defaultView: 'agendaWeek',\n    allDaySlot: false,\n    firstHour: 8,\n\n    \/\/ configure selection for event creation\n    selectable: true,\n    selectHelper: true,\n    select: business_hours_add,\n\n    \/\/ configure data source\n    editable: true,\n    eventSources: [\n    {\n      events: jQuery.parseJSON(jQuery('#fullcalendar_data').val()),\n      color: '#992B0A',\n      textColor: 'white',\n      ignoreTimezone: false\n    }\n    ],\n\n    \/\/ configure editing\n    eventClick: function(calEvent) {\n      business_hours_delete(calEvent.id);\n    }\n  });\n  alert(jQuery('#fullcalendar_data').val());\n});\n\nfunction business_hours_add(startDate, endDate) {\n  var calendar = jQuery('#calendar');\n  var newid = Math.ceil(Math.random()*64000);\n  calendar.fullCalendar('renderEvent',\n  {\n    id: newid,\n    title: \"Open\",\n    start: startDate,\n    end: endDate,\n    allDay: false\n  },\n  true \/\/ make the event \"stick\"\n  );\n  calendar.fullCalendar('unselect');\n}\n\nvar business_hours_selectedId = -1;\nfunction business_hours_delete(id) {\n\n  business_hours_selectedId = id;\n\n  jQuery( \"#dialog-confirm\" ).dialog({\n    resizable: false,\n    height:160,\n    modal: true,\n    buttons: {\n      \"Yes, delete!\": function() {\n        calendar = jQuery('#calendar');\n        calendar.fullCalendar( 'removeEvents', business_hours_selectedId);\n        jQuery( this ).dialog( \"close\" );\n      },\n      Cancel: function() {\n        jQuery( this ).dialog( \"close\" );\n      }\n    }\n  }, id);\n}\n\nfunction business_hours_set() {\n  var data = jQuery('#calendar').fullCalendar( 'clientEvents' );\n\n  \/\/ data is cyclical.  Create a new data structure to stringify.\n  var ret = [];\n  for(var i=0; i<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m doing it wrong somehow. I&#8217;m getting tripped up on timezones with Fullcalendar. I&#8217;ve tried setting ignoreTimezone to true and false, but it doesn&#8217;t seem to matter. It&#8217;s in the code below in two places because I wasn&#8217;t sure from the doc where it goes. My data source is a hidden form field. Data that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7868","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7868"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7868\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}