Skip to content

Commit

Permalink
adding handling for epoch dates in javascript ApiClient mustache file (
Browse files Browse the repository at this point in the history
  • Loading branch information
tray2100 authored Aug 4, 2020
1 parent c1b53df commit 9f1d012
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}} /**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}/**
Expand Down
7 changes: 5 additions & 2 deletions samples/client/petstore/javascript-es6/src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 9f1d012

Please sign in to comment.