AIRAVATA-2152 Enable reservation start/end time Also factored out UTC<->local time conversion to functions in CommonUtilities.php. Fixed a bug in the logic with timezones with negative offset; the minus sign wasn't being handled in strtotime so I'm using the absolute value instead.
Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/18a98fd2 Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/18a98fd2 Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/18a98fd2 Branch: refs/heads/develop Commit: 18a98fd27475dd7b3e918e3b20d6c7de26dd894c Parents: 17425c0 Author: Marcus Christie <[email protected]> Authored: Wed Oct 19 16:44:48 2016 -0400 Committer: Marcus Christie <[email protected]> Committed: Fri Oct 28 15:04:30 2016 -0400 ---------------------------------------------------------------------- app/libraries/CRUtilities.php | 8 ++---- app/libraries/CommonUtilities.php | 26 ++++++++++++++++++ app/libraries/URPUtilities.php | 8 ++---- .../account/user-compute-resources.blade.php | 29 ++++++++++++++++++++ .../compute-resource-preferences.blade.php | 9 ++---- .../user-compute-resource-preferences.blade.php | 9 ++---- 6 files changed, 63 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/18a98fd2/app/libraries/CRUtilities.php ---------------------------------------------------------------------- diff --git a/app/libraries/CRUtilities.php b/app/libraries/CRUtilities.php index fad1ad2..34066c1 100755 --- a/app/libraries/CRUtilities.php +++ b/app/libraries/CRUtilities.php @@ -524,15 +524,11 @@ class CRUtilities public static function add_or_update_CRP($inputs) { - $timeDifference = Session::get("user_timezone"); - $addOrSubtract = "-"; - if( $timeDifference > 0) - $addOrSubtract = "+"; $inputs = Input::all(); if( $inputs["reservationStartTime"] != "") - $inputs["reservationStartTime"] = strtotime( $addOrSubtract . " " . Session::get("user_timezone") . " hours", strtotime( $inputs["reservationStartTime"]) ) * 1000; + $inputs["reservationStartTime"] = CommonUtilities::convertLocalToUTC($inputs["reservationStartTime"]) * 1000; if( $inputs["reservationEndTime"] != "") - $inputs["reservationEndTime"] = strtotime( $addOrSubtract . " " . Session::get("user_timezone") . " hours", strtotime($inputs["reservationEndTime"]) ) * 1000; + $inputs["reservationEndTime"] = CommonUtilities::convertLocalToUTC($inputs["reservationEndTime"]) * 1000; $computeResourcePreferences = new computeResourcePreference($inputs); http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/18a98fd2/app/libraries/CommonUtilities.php ---------------------------------------------------------------------- diff --git a/app/libraries/CommonUtilities.php b/app/libraries/CommonUtilities.php index 9ec209b..94e8626 100644 --- a/app/libraries/CommonUtilities.php +++ b/app/libraries/CommonUtilities.php @@ -373,5 +373,31 @@ class CommonUtilities } }; } + + /** + * Convert from UTC time to local time. Units are seconds since Unix Epoch. + */ + public static function convertUTCToLocal($utcTime) { + + $timeDifference = Session::get("user_timezone"); + $addOrSubtract = "-"; + if( $timeDifference < 0) + $addOrSubtract = "+"; + + return strtotime( $addOrSubtract . " " . abs($timeDifference) . " hours", $utcTime); + } + + /** + * Convert from local time to UTC time. Units are seconds since Unix Epoch. + */ + public static function convertLocalToUTC($localTime) { + + $timeDifference = Session::get("user_timezone"); + $addOrSubtract = "-"; + if( $timeDifference > 0) + $addOrSubtract = "+"; + + return strtotime( $addOrSubtract . " " . abs($timeDifference) . " hours", $localTime); + } } http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/18a98fd2/app/libraries/URPUtilities.php ---------------------------------------------------------------------- diff --git a/app/libraries/URPUtilities.php b/app/libraries/URPUtilities.php index 3da8f21..ad4529b 100644 --- a/app/libraries/URPUtilities.php +++ b/app/libraries/URPUtilities.php @@ -72,15 +72,11 @@ class URPUtilities public static function add_or_update_user_CRP($inputs, $update = false) { - $timeDifference = Session::get("user_timezone"); - $addOrSubtract = "-"; - if( $timeDifference > 0) - $addOrSubtract = "+"; $inputs = Input::all(); if( $inputs["reservationStartTime"] != "") - $inputs["reservationStartTime"] = strtotime( $addOrSubtract . " " . Session::get("user_timezone") . " hours", strtotime( $inputs["reservationStartTime"]) ) * 1000; + $inputs["reservationStartTime"] = CommonUtilities::convertLocalToUTC($inputs["reservationStartTime"]) * 1000; if( $inputs["reservationEndTime"] != "") - $inputs["reservationEndTime"] = strtotime( $addOrSubtract . " " . Session::get("user_timezone") . " hours", strtotime($inputs["reservationEndTime"]) ) * 1000; + $inputs["reservationEndTime"] = CommonUtilities::convertLocalToUTC($inputs["reservationEndTime"]) * 1000; $userComputeResourcePreference = new UserComputeResourcePreference($inputs); $userId = Session::get('username'); http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/18a98fd2/app/views/account/user-compute-resources.blade.php ---------------------------------------------------------------------- diff --git a/app/views/account/user-compute-resources.blade.php b/app/views/account/user-compute-resources.blade.php index a1a1f99..e46f37e 100644 --- a/app/views/account/user-compute-resources.blade.php +++ b/app/views/account/user-compute-resources.blade.php @@ -2,6 +2,7 @@ @section('page-header') @parent +{{ HTML::style('css/datetimepicker.css')}} <style> button.add-user-cr { margin-top: 10px; @@ -120,6 +121,8 @@ button.add-user-cr { @section('scripts') @parent +{{ HTML::script('js/moment.js')}} +{{ HTML::script('js/datetimepicker.js')}} <script> $('.add-user-cr').on('click', function(){ @@ -136,5 +139,31 @@ $("body").on("change", "#user-cr-select", function(){ crId = crId.replace(/\./g,"_"); $(".user-cr-pref-space").html($("#cr-" + crId).html()); }); + +/* making datetimepicker work for reservation start and end date kept in user-compute-resource-preferences blade*/ +$('.datetimepicker1').datetimepicker({ + pick12HourFormat: false + //pickTime: false +}); +$('.datetimepicker2').datetimepicker({ + pick12HourFormat: false + //pickTime: false +}); + +$(".datetimepicker1 input").focus( function(){ + $(this).parent().find(".glyphicon-calendar").click(); +}); +$(".datetimepicker2 input").focus( function(){ + $(this).parent().find(".glyphicon-calendar").click(); +}); + +$(".datetimepicker1").on("dp.change", function (e) { + $('.datetimepicker2').data("DateTimePicker").setMinDate(e.date); + $(this).find(".glyphicon-calendar").click(); +}); +$(".datetimepicker2").on("dp.change", function (e) { + $('.datetimepicker1').data("DateTimePicker").setMaxDate(e.date); + $(this).find(".glyphicon-calendar").click(); +}); </script> @stop \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/18a98fd2/app/views/partials/compute-resource-preferences.blade.php ---------------------------------------------------------------------- diff --git a/app/views/partials/compute-resource-preferences.blade.php b/app/views/partials/compute-resource-preferences.blade.php index 99fc469..82bdd62 100644 --- a/app/views/partials/compute-resource-preferences.blade.php +++ b/app/views/partials/compute-resource-preferences.blade.php @@ -132,18 +132,13 @@ </div> <?php //to add or remove time according to local hours. -$timeDifference = Session::get("user_timezone"); -$addOrSubtract = "-"; -if( $timeDifference < 0) - $addOrSubtract = "+"; - $reservationStartTime = ""; if( isset( $preferences) && $preferences->reservationStartTime != '') - $reservationStartTime = strtotime( $addOrSubtract . " " . Session::get("user_timezone") . " hours", $preferences->reservationStartTime/1000); + $reservationStartTime = CommonUtilities::convertUTCToLocal($preferences->reservationStartTime/1000) $reservationEndTime = ""; if( isset( $preferences) && $preferences->reservationEndTime != '') - $reservationEndTime = strtotime( $addOrSubtract . " " . Session::get("user_timezone") . " hours", $preferences->reservationEndTime/1000); + $reservationEndTime = CommonUtilities::convertUTCToLocal($preferences->reservationEndTime/1000) ?> <div class="form-group col-md-6"> http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/18a98fd2/app/views/partials/user-compute-resource-preferences.blade.php ---------------------------------------------------------------------- diff --git a/app/views/partials/user-compute-resource-preferences.blade.php b/app/views/partials/user-compute-resource-preferences.blade.php index 0e2036c..af0872e 100644 --- a/app/views/partials/user-compute-resource-preferences.blade.php +++ b/app/views/partials/user-compute-resource-preferences.blade.php @@ -83,18 +83,13 @@ </div> <?php //to add or remove time according to local hours. -$timeDifference = Session::get("user_timezone"); -$addOrSubtract = "-"; -if( $timeDifference < 0) - $addOrSubtract = "+"; - $reservationStartTime = ""; if( isset( $preferences) && $preferences->reservationStartTime != '') - $reservationStartTime = strtotime( $addOrSubtract . " " . Session::get("user_timezone") . " hours", $preferences->reservationStartTime/1000); + $reservationStartTime = CommonUtilities::convertUTCToLocal($preferences->reservationStartTime/1000) $reservationEndTime = ""; if( isset( $preferences) && $preferences->reservationEndTime != '') - $reservationEndTime = strtotime( $addOrSubtract . " " . Session::get("user_timezone") . " hours", $preferences->reservationEndTime/1000); + $reservationEndTime = CommonUtilities::convertUTCToLocal($preferences->reservationEndTime/1000) ?>
