diff --git a/modules/openapi-generator/src/main/resources/Javascript/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Javascript/ApiClient.mustache index 7fd5f5e6cecd..d618e612b33c 100644 --- a/modules/openapi-generator/src/main/resources/Javascript/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Javascript/ApiClient.mustache @@ -541,12 +541,15 @@ {{/usePromises}} }; {{#emitJSDoc}} /** - * Parses an ISO-8601 string representation of a date value. + * Parses an ISO-8601 string representation or epoch representation of a date value. * @param {String} str The date value as a string. * @returns {Date} The parsed date object. */ {{/emitJSDoc}} exports.parseDate = function(str) { - return new Date(str.replace(/T/i, ' ')); + if (isNaN(str)) { + return new Date(str.replace(/T/i, ' ')); + } + return new Date(+str); }; {{#emitJSDoc}} /** diff --git a/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache index aa54b3d1bb87..c660001f1fdc 100644 --- a/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache @@ -519,12 +519,15 @@ class ApiClient { } {{#emitJSDoc}}/** - * Parses an ISO-8601 string representation of a date value. + * Parses an ISO-8601 string representation or epoch representation of a date value. * @param {String} str The date value as a string. * @returns {Date} The parsed date object. */{{/emitJSDoc}} static parseDate(str) { - return new Date(str); + if (isNaN(str)) { + return new Date(str); + } + return new Date(+str); } {{#emitJSDoc}}/** diff --git a/samples/client/petstore/javascript-es6/src/ApiClient.js b/samples/client/petstore/javascript-es6/src/ApiClient.js index 91fef65f79b8..3d081bf1877a 100644 --- a/samples/client/petstore/javascript-es6/src/ApiClient.js +++ b/samples/client/petstore/javascript-es6/src/ApiClient.js @@ -475,12 +475,15 @@ class ApiClient { } /** - * Parses an ISO-8601 string representation of a date value. + * Parses an ISO-8601 string representation or epoch representation of a date value. * @param {String} str The date value as a string. * @returns {Date} The parsed date object. */ static parseDate(str) { - return new Date(str); + if (isNaN(str)) { + return new Date(str); + } + return new Date(+str); } /** diff --git a/samples/client/petstore/javascript-promise-es6/src/ApiClient.js b/samples/client/petstore/javascript-promise-es6/src/ApiClient.js index 9a330d1d6832..d3eb5cb7184f 100644 --- a/samples/client/petstore/javascript-promise-es6/src/ApiClient.js +++ b/samples/client/petstore/javascript-promise-es6/src/ApiClient.js @@ -476,12 +476,15 @@ class ApiClient { } /** - * Parses an ISO-8601 string representation of a date value. + * Parses an ISO-8601 string representation or epoch representation of a date value. * @param {String} str The date value as a string. * @returns {Date} The parsed date object. */ static parseDate(str) { - return new Date(str); + if (isNaN(str)) { + return new Date(str); + } + return new Date(+str); } /**