adding handling for epoch dates in javascript ApiClient mustache file (#6497) (#6504)

This commit is contained in:
Troy P 2020-08-04 08:55:38 -07:00 committed by GitHub
parent c1b53df345
commit 9f1d012d14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 8 deletions

View File

@ -541,12 +541,15 @@
{{/usePromises}} }; {{/usePromises}} };
{{#emitJSDoc}} /** {{#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. * @param {String} str The date value as a string.
* @returns {Date} The parsed date object. * @returns {Date} The parsed date object.
*/ */
{{/emitJSDoc}} exports.parseDate = function(str) { {{/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}} /** {{#emitJSDoc}} /**

View File

@ -519,12 +519,15 @@ class ApiClient {
} }
{{#emitJSDoc}}/** {{#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. * @param {String} str The date value as a string.
* @returns {Date} The parsed date object. * @returns {Date} The parsed date object.
*/{{/emitJSDoc}} */{{/emitJSDoc}}
static parseDate(str) { static parseDate(str) {
return new Date(str); if (isNaN(str)) {
return new Date(str);
}
return new Date(+str);
} }
{{#emitJSDoc}}/** {{#emitJSDoc}}/**

View File

@ -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. * @param {String} str The date value as a string.
* @returns {Date} The parsed date object. * @returns {Date} The parsed date object.
*/ */
static parseDate(str) { static parseDate(str) {
return new Date(str); if (isNaN(str)) {
return new Date(str);
}
return new Date(+str);
} }
/** /**

View File

@ -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. * @param {String} str The date value as a string.
* @returns {Date} The parsed date object. * @returns {Date} The parsed date object.
*/ */
static parseDate(str) { static parseDate(str) {
return new Date(str); if (isNaN(str)) {
return new Date(str);
}
return new Date(+str);
} }
/** /**