You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When operationSpec for an API response specifies an object property with format "Date" its value is not deserialized to Javascript Date object as expected.
For example when value "2021-03-31" is supplied by API in aforementioned property dateOfIssue the resulting Date object is actually deserialized as "2021-03-30" because the local timezone offset is applied.
This is due to a rather strange behaviour of Javascript Date object when local time is set to negative UTC offset and only a date value is passed to its contructor:
// Timezone set to -6newDate("2021-03-31")// is in fact interpreted as "Tue Mar 30 2021 18:00:00 GMT-0600 (Central Standard Time)"
The above issue does not apply to positive UTC offsets.
However, when time fraction is supplied (with midnight) it yields expected results:
// Timezone set to -6// when provided with time fraction (and without explicit time zone) it is constructed properlynewDate("2021-03-31T00:00:00")// is in fact interpreted as "Wed Mar 31 2021 00:00:00 GMT-0600 (Central Standard Time)"
I believe that Date only values should be interpreted strictly as local date regardless of currently used time zone offset. The following fix could be used to provide such a behaviour:
@skippone Thanks for the feedback! This is an interesting problem (as always for any Date related issues). We will investigate a bit deeper then get back to you.
Oh this is a fun one. I am not sure if there is going to be a bulletproof solution here, but as a default behavior this might be good enough.
The counter-example is a date-only string that is something like a validity period of a certificate, but I suppose most reasonable start boundaries might have time/timezone info rather than just a date?
The counter-example is a date-only string that is something like a validity period of a certificate, but I suppose most reasonable start boundaries might have time/timezone info rather than just a date?
yes for things that are important I'd expect time instead of just a date.
When operationSpec for an API response specifies an object property with format "Date" its value is not deserialized to Javascript Date object as expected.
Swagger / Open API example:
For example when value "2021-03-31" is supplied by API in aforementioned property
dateOfIssue
the resultingDate
object is actually deserialized as "2021-03-30" because the local timezone offset is applied.Code in question is:
ms-rest-js/lib/serializer.ts
Lines 214 to 215 in f6f0d92
This is due to a rather strange behaviour of Javascript Date object when local time is set to negative UTC offset and only a date value is passed to its contructor:
The above issue does not apply to positive UTC offsets.
However, when time fraction is supplied (with midnight) it yields expected results:
I believe that
Date
only values should be interpreted strictly as local date regardless of currently used time zone offset. The following fix could be used to provide such a behaviour:The very same behaviour is actually also present in the newer version of azure-sdk-for-js.
The text was updated successfully, but these errors were encountered: