ms-rest-js icon indicating copy to clipboard operation
ms-rest-js copied to clipboard

Local date is deserialized as UTC timezone in Safari on macOS

Open nattster opened this issue 5 years ago • 7 comments

Package Version: 1.7.0

  • [ ] nodejs
    • nodejs version: ______
    • os name/version: _____
  • [x] browser
    • name/version: Safari 12.1.2 Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Deserialize the local date (without timezone data) with AutoRest ( --model-date-time-as-string=false, the default value) 2019-01-10T10:00:00
  2. Date is assumed UTC, and deserialized incorrectly 2019-01-10T17:00:00 GMT+0700

Expected behavior 2019-01-10T10:00:00 GMT+0700 Datetime without timezone, should be treated as user's local time, not UTC.

Screenshots

  1. User timezone is GMT+7 and browser is Google Chrome 79 on Windows 10 Deserialized as local time correctly. image

  2. User timezone is GMT+7 and browser is Safari 12.1.2 on mac OS image (44)

Additional context Suspect the problem coming from here: https://github.com/Azure/ms-rest-js/blob/master/lib/serializer.ts#L205

nattster avatar Feb 04 '20 11:02 nattster

What service is returning this date without timezone data? It feels like the service should always specify the timezone or Z for UTC.

xirzec avatar Sep 22 '20 21:09 xirzec

Facing a similar issue. Is there a solution for this yet? Thanks.

ArjunSureshKumar92 avatar Mar 25 '21 17:03 ArjunSureshKumar92

It's unfortunate that new Date(dateString) behavior is different and inconsistent across browsers.

jeremymeng avatar Mar 26 '21 16:03 jeremymeng

Since Temporal is still a ways off, what do we think about using something like https://www.npmjs.com/package/dayjs to handle parsing and converting to Date?

xirzec avatar Mar 26 '21 18:03 xirzec

Tried on both browser and found out the conversion seems to work fine now both Chrome and safari.

Chrome

image

Safari: Version 15.5 (17613.2.7.1.8)

image

teepobharu avatar Jun 16 '22 11:06 teepobharu

@mpodwysocki can you confirm that Safari fixed this for you as well?

xirzec avatar Jun 16 '22 18:06 xirzec

@xirzec confirmed on Safari:

  • Version 15.5 (17613.2.7.1.8)
  • Release 146 (Safari 15.4, WebKit 17614.1.14.10.6)

mpodwysocki avatar Jun 16 '22 19:06 mpodwysocki