-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JS] adding handling for epoch dates #6504
Conversation
8b11630
to
40a7e53
Compare
4fc1977
to
cd7910c
Compare
Pushed the recent upstream changes to this PR... |
* @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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Number.isNaN() method determines whether a value is NaN (Not-A-Number).
Ref: https://www.w3schools.com/jsref/jsref_isnan_number.asp
Did you mean to check if str is a number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I meant to check if str is not a number. If it's not a number then we'll default to the existing logic otherwise it's a number that we can just pass into Date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. After reading https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN, I think we can go with your fix.
* master: (129 commits) [typescript-axios] add promise to bearer and oauth tokens (#7132) update doc [REQ] Added enumClassPrefix option to Go server generation (#7008) [Java][jersey2] Add helper methods for oneOf Java classes (#7115) [Kotlin][Retrofit2] fix missing import for file (#7121) adding handling for epoch dates in javascript ApiClient mustache file (#6497) (#6504) update doc comment out cpanm in travis [Kotlin] Rxjava3 support (#6998) [BUG][JAVA] Fix error handling in okhttp-gson async api client (#7089) Update to reset httpRepsonse.Body (#6948) [php-lumen] Set required PHP version to ^7.2.5 (#6949) [contrib][docs] Assert importance of title/description/repro steps (#7103) ISSUE-4222: Prevent conflicts with accept(s) local variables in generated Java RestTemplate ApiClient (#7101) [bug][core] Copy all attributes (not properties) on composed schemas when flattening models (#7106) [core] Add type and format properties to model of inline response (#6153) [PowerShell] better publishing workflow (#7114) [aspnetcore] Typo issues in docs and generated code (#7094) fix http signaure auth in build.sbt (#7110) fix for the issue facing spec invlolving arrayschema structure with ref (#6310) ...
… (#6497)
Added simple branching logic where a number is sent directly to the Date constructor or execute the previous logic.
PR checklist
./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc).master
,4.3.x
,5.0.x
. Default:master
.cc @CodeNinjai @frol @cliffano