diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 0a5a068af..2e743c0e9 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -9,6 +9,7 @@ class ApiController extends Zend_Controller_Action $context = $this->_helper->getHelper('contextSwitch'); $context->addActionContext('version', 'json') ->addActionContext('recorded-shows', 'json') + ->addActionContext('server-timestamp', 'json') ->addActionContext('upload-file', 'json') ->addActionContext('upload-recorded', 'json') ->addActionContext('media-monitor-setup', 'json') @@ -56,6 +57,12 @@ class ApiController extends Zend_Controller_Action $jsonStr = json_encode(array("version"=>AIRTIME_VERSION)); echo $jsonStr; } + + public function serverTimestampAction(){ + + $this->view->serverTimestamp = array("timestamp"=>time(), "timezoneOffset"=> date("Z")); + + } /** * Allows remote client to download requested media file. diff --git a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js index e0de9e0ac..eb8afcf0f 100644 --- a/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js +++ b/airtime_mvc/public/js/airtime/schedule/full-calendar-functions.js @@ -61,10 +61,23 @@ function makeTimeStamp(date){ return timestamp; } +function adjustDateToServerDate(date, serverTimezoneOffset){ + //date object stores time in the browser's localtime. We need to artificially shift + //it to + var timezoneOffset = date.getTimezoneOffset()*60*1000; + + date.setTime(date.getTime() + timezoneOffset + serverTimezoneOffset*1000); + + /* date object has been shifted to artificial UTC time. Now let's + * shift it to the server's timezone */ + + return date; +} + function dayClick(date, allDay, jsEvent, view) { var now, today, selected, chosenDate, chosenTime; - now = new Date(); + now = adjustDateToServerDate(new Date(), serverTimezoneOffset); if(view.name === "month") { today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); diff --git a/airtime_mvc/public/js/airtime/schedule/schedule.js b/airtime_mvc/public/js/airtime/schedule/schedule.js index a821412d9..14fc05bd6 100644 --- a/airtime_mvc/public/js/airtime/schedule/schedule.js +++ b/airtime_mvc/public/js/airtime/schedule/schedule.js @@ -4,6 +4,8 @@ * */ +var serverTimezoneOffset = 0; + function closeDialog(event, ui) { $("#schedule_calendar").fullCalendar( 'refetchEvents' ); $(this).remove(); @@ -292,18 +294,21 @@ function buildEditDialog(json){ } -$(window).load(function() { +function createFullCalendar(data){ + + serverTimezoneOffset = data.serverTimestamp.timezoneOffset; + var mainHeight = document.documentElement.clientHeight - 200 - 50; $('#schedule_calendar').fullCalendar({ header: { - left: 'prev, next, today', - center: 'title', - right: 'agendaDay, agendaWeek, month' - }, - defaultView: 'month', - editable: false, - allDaySlot: false, + left: 'prev, next, today', + center: 'title', + right: 'agendaDay, agendaWeek, month' + }, + defaultView: 'month', + editable: false, + allDaySlot: false, axisFormat: 'H:mm', timeFormat: { agenda: 'H:mm{ - H:mm}', @@ -312,17 +317,25 @@ $(window).load(function() { contentHeight: mainHeight, theme: true, lazyFetching: false, + serverTimestamp: parseInt(data.serverTimestamp.timestamp, 10), + serverTimezoneOffset: parseInt(data.serverTimestamp.timezoneOffset, 10), - events: getFullCalendarEvents, + events: getFullCalendarEvents, - //callbacks (in full-calendar-functions.js) + //callbacks (in full-calendar-functions.js) viewDisplay: viewDisplay, - dayClick: dayClick, - eventRender: eventRender, - eventAfterRender: eventAfterRender, - eventDrop: eventDrop, - eventResize: eventResize + dayClick: dayClick, + eventRender: eventRender, + eventAfterRender: eventAfterRender, + eventDrop: eventDrop, + eventResize: eventResize }); - + +} + +$(window).load(function() { + + $.ajax({ url: "/Api/server-timestamp/format/json", dataType:"json", success:createFullCalendar + , error:function(jqXHR, textStatus, errorThrown){}}); }); diff --git a/airtime_mvc/public/js/fullcalendar/fullcalendar.js b/airtime_mvc/public/js/fullcalendar/fullcalendar.js index bbcd2fb88..663802338 100644 --- a/airtime_mvc/public/js/fullcalendar/fullcalendar.js +++ b/airtime_mvc/public/js/fullcalendar/fullcalendar.js @@ -2275,7 +2275,7 @@ function BasicView(element, calendar, viewName) { function updateCells(firstTime) { var dowDirty = firstTime || rowCnt == 1; // could the cells' day-of-weeks need updating? var month = t.start.getMonth(); - var today = clearTime(new Date()); + var today = clearTime(adjustDateToServerDate(new Date(), opt("serverTimezoneOffset"))); var cell; var date; var row; diff --git a/install_minimal/include/AirtimeInstall.php b/install_minimal/include/AirtimeInstall.php index f0326ef85..55508143c 100644 --- a/install_minimal/include/AirtimeInstall.php +++ b/install_minimal/include/AirtimeInstall.php @@ -297,8 +297,10 @@ class AirtimeInstall public static function SetDefaultTimezone() { global $CC_DBC; + + $defaultTimezone = date_default_timezone_get(); - $sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('timezone', 'America/Toronto')"; + $sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('timezone', '$defaultTimezone')"; $result = $CC_DBC->query($sql); if (PEAR::isError($result)) { return false; diff --git a/install_minimal/upgrades/airtime-2.0.0/airtime-upgrade.php b/install_minimal/upgrades/airtime-2.0.0/airtime-upgrade.php index 6c9bdce85..9970f3078 100644 --- a/install_minimal/upgrades/airtime-2.0.0/airtime-upgrade.php +++ b/install_minimal/upgrades/airtime-2.0.0/airtime-upgrade.php @@ -20,8 +20,10 @@ class AirtimeInstall{ public static function SetDefaultTimezone() { global $CC_DBC; + + $defaultTimezone = date_default_timezone_get(); - $sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('timezone', 'America/Toronto')"; + $sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('timezone', '$defaultTimezone')"; $result = $CC_DBC->query($sql); if (PEAR::isError($result)) { return false;