diff --git a/guacamole/src/main/webapp/app/form/controllers/dateFieldController.js b/guacamole/src/main/webapp/app/form/controllers/dateFieldController.js index 34acabe62..26b663f30 100644 --- a/guacamole/src/main/webapp/app/form/controllers/dateFieldController.js +++ b/guacamole/src/main/webapp/app/form/controllers/dateFieldController.js @@ -69,7 +69,14 @@ angular.module('form').controller('dateFieldController', ['$scope', '$injector', * set. */ var parseDate = function parseDate(str) { - return new Date(str + 'T00:00Z'); + + // Parse date, return blank if invalid + var parsedDate = new Date(str + 'T00:00Z'); + if (isNaN(parsedDate.getTime())) + return null; + + return parsedDate; + }; // Update typed value when model is changed diff --git a/guacamole/src/main/webapp/app/form/controllers/timeFieldController.js b/guacamole/src/main/webapp/app/form/controllers/timeFieldController.js index 5cb831c76..58f077524 100644 --- a/guacamole/src/main/webapp/app/form/controllers/timeFieldController.js +++ b/guacamole/src/main/webapp/app/form/controllers/timeFieldController.js @@ -69,7 +69,14 @@ angular.module('form').controller('timeFieldController', ['$scope', '$injector', * set. */ var parseTime = function parseTime(str) { - return new Date('1970-01-01T' + str + 'Z'); + + // Parse time, return blank if invalid + var parsedDate = new Date('1970-01-01T' + str + 'Z'); + if (isNaN(parsedDate.getTime())) + return null; + + return parsedDate; + }; // Update typed value when model is changed diff --git a/guacamole/src/main/webapp/app/form/directives/guacLenientDate.js b/guacamole/src/main/webapp/app/form/directives/guacLenientDate.js index fe21c8efc..4bd282f79 100644 --- a/guacamole/src/main/webapp/app/form/directives/guacLenientDate.js +++ b/guacamole/src/main/webapp/app/form/directives/guacLenientDate.js @@ -63,7 +63,11 @@ angular.module('form').directive('guacLenientDate', ['$injector', var day = parseInt(match[3] || '0') || 1; // Convert to Date object - return new Date(Date.UTC(year, month - 1, day)); + var parsedDate = new Date(Date.UTC(year, month - 1, day)); + if (isNaN(parsedDate.getTime())) + return null; + + return parsedDate; }]; diff --git a/guacamole/src/main/webapp/app/form/directives/guacLenientTime.js b/guacamole/src/main/webapp/app/form/directives/guacLenientTime.js index c5a03b917..98ecd590a 100644 --- a/guacamole/src/main/webapp/app/form/directives/guacLenientTime.js +++ b/guacamole/src/main/webapp/app/form/directives/guacLenientTime.js @@ -83,7 +83,11 @@ angular.module('form').directive('guacLenientTime', ['$injector', hour %= 24; // Convert to Date object - return new Date(Date.UTC(1970, 0, 1, hour, minute, second)); + var parsedDate = new Date(Date.UTC(1970, 0, 1, hour, minute, second)); + if (isNaN(parsedDate.getTime())) + return null; + + return parsedDate; }];