Skip to content
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

UTC Plugin Milliseconds parsing #544

Closed
ilueckel opened this issue Mar 25, 2019 · 12 comments · Fixed by #1010
Closed

UTC Plugin Milliseconds parsing #544

ilueckel opened this issue Mar 25, 2019 · 12 comments · Fixed by #1010
Labels

Comments

@ilueckel
Copy link

Describe the bug
When I use the UTC-Plugin and try to parse a string with milliseconds, it changes the time (I'm CET). If I append a "Z" to my string, this does not happen (see example)

Expected behavior
Parsing a string without milliseconds creates a correct representation of the date (with or without "Z" at the end). Adding milliseconds to the script should not change this behavior.

Example

dayjs.utc('2019-03-25T06:41:00');
/** { [Number: 1553496060000]
      '$L': 'en',
      '$u': true,
      '$d': 2019-03-25T06:41:00.000Z,
      '$y': 2019,
      '$M': 2,
      '$D': 25,
      '$W': 1,
      '$H': 6,
      '$m': 41,
      '$s': 0,
      '$ms': 0 }
*/

dayjs.utc('2019-03-25T06:41:00Z');
/** { [Number: 1553496060000]
      '$L': 'en',
      '$u': true,
      '$d': 2019-03-25T06:41:00.000Z,
      '$y': 2019,
      '$M': 2,
      '$D': 25,
      '$W': 1,
      '$H': 6,
      '$m': 41,
      '$s': 0,
      '$ms': 0 }
*/
// They are the same

dayjs.utc('2019-03-25T06:41:00.654321');
// This one is one hour of (the first example isn't)
/** { [Number: 1553492460654]
      '$L': 'en',
      '$u': true,
      '$d': 2019-03-25T05:41:00.654Z,
      '$y': 2019,
      '$M': 2,
      '$D': 25,
      '$W': 1,
      '$H': 5,
      '$m': 41,
      '$s': 0,
      '$ms': 654 }
*/

dayjs.utc('2019-03-25T06:41:00.654321Z')
// This one isn't one hour off (as I would expect it for the previous one too)
/** { [Number: 1553496060654]
      '$L': 'en',
      '$u': true,
      '$d': 2019-03-25T06:41:00.654Z,
      '$y': 2019,
      '$M': 2,
      '$D': 25,
      '$W': 1,
      '$H': 6,
      '$m': 41,
      '$s': 0,
      '$ms': 654 }
*/

Information

  • Day.js Version: v1.8.11
  • OS: Windows 10
  • Browser: Chrome, Jest
@iamkun
Copy link
Owner

iamkun commented Mar 25, 2019

@ilueckel
I think we currently support 2019-03-25T06:41:00.654 (3 digits ms), you could try this first to see if it works as expected.

Plus, just wondering what's this date format that contains 6 digits millisecond?

@ilueckel
Copy link
Author

ilueckel commented Mar 25, 2019

Restricting it to three digits would fix it. I'll guess I do this instead.

The date strings are generated in a Spring Boot Web App from LocalDateTime Objects with Jackson Json. I will change the default format there.

@iamkun

This comment has been minimized.

@ilueckel
Copy link
Author

I tried to use

dayjs.utc('2019-03-25T06:41:00.654321', 'YYYY-MM-DDTHH:mm:ss.SSSSSS')

but result was still

  { [Number: 1553492460654]
      '$L': 'en',
      '$u': true,
      '$d': 2019-03-25T05:41:00.654Z,
      '$y': 2019,
      '$M': 2,
      '$D': 25,
      '$W': 1,
      '$H': 5,
      '$m': 41,
      '$s': 0,
      '$ms': 654 }

@iamkun
Copy link
Owner

iamkun commented Mar 25, 2019

Yes, currently we only support parsing 3 digits millisecond both parse and customParseForamt plugin

@igaloly
Copy link

igaloly commented May 18, 2020

@iamkun
Why there's a difference between 3 / 6 digits?

@stefanv
Copy link

stefanv commented Aug 2, 2020

What is the motivation for not supporting more digits?

@iamkun
Copy link
Owner

iamkun commented Aug 3, 2020

Of course, we could support it if needed.

@cyberfly
Copy link

I am scratching my head and the work around actually fix this

https://stackoverflow.com/questions/61368563/day-js-is-not-converting-utc-to-local-time

@iamkun
Copy link
Owner

iamkun commented Aug 18, 2020

sorry for the inconvenience, and it is fixed in #1010

iamkun pushed a commit that referenced this issue Aug 20, 2020
## [1.8.34](v1.8.33...v1.8.34) (2020-08-20)

### Bug Fixes

* Fix Timezone plugin to preserve milliseconds while changing timezone ([#1003](#1003)) ([5f446ed](5f446ed)), closes [#1002](#1002)
* support parsing unlimited decimals of millisecond ([#1010](#1010)) ([d1bdd36](d1bdd36)), closes [#544](#544)
* update Duration plugin to support global locale ([#1008](#1008)) ([1c49c83](1c49c83)), closes [#1007](#1007)
@iamkun
Copy link
Owner

iamkun commented Aug 20, 2020

🎉 This issue has been resolved in version 1.8.34 🎉

The release is available on:

Your semantic-release bot 📦🚀

@josefsmrz
Copy link

josefsmrz commented Apr 22, 2021

Hi, there seems to be another problem that manifests very similarly and might be connected.

Conversion from UTC to local time doesn't work when parsing it as 'DD/MM/YYYY H:mm'.

//returns '06/09/2019 9:09' - correct CEST
dayjs.utc('2019/09/06 7:09', 'YYYY/MM/DD H:mm').local().format('DD/MM/YYYY H:mm')
 
//returns '06/09/2019 7:09' - incorrect
dayjs.utc('06/09/2019 7:09', 'DD/MM/YYYY H:mm').local().format('DD/MM/YYYY H:mm')

//returns 'invalid date'
dayjs.utc('31/12/2019 7:09', 'DD/MM/YYYY H:mm').local().format('DD/MM/YYYY H:mm')

andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this issue May 10, 2022
## [1.8.34](iamkun/dayjs@v1.8.33...v1.8.34) (2020-08-20)

### Bug Fixes

* Fix Timezone plugin to preserve milliseconds while changing timezone ([#1003](iamkun/dayjs#1003)) ([5f446ed](iamkun/dayjs@5f446ed)), closes [#1002](iamkun/dayjs#1002)
* support parsing unlimited decimals of millisecond ([#1010](iamkun/dayjs#1010)) ([d1bdd36](iamkun/dayjs@d1bdd36)), closes [#544](iamkun/dayjs#544)
* update Duration plugin to support global locale ([#1008](iamkun/dayjs#1008)) ([1c49c83](iamkun/dayjs@1c49c83)), closes [#1007](iamkun/dayjs#1007)
andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this issue May 10, 2022
## [1.8.34](iamkun/dayjs@v1.8.33...v1.8.34) (2020-08-20)

### Bug Fixes

* Fix Timezone plugin to preserve milliseconds while changing timezone ([#1003](iamkun/dayjs#1003)) ([5f446ed](iamkun/dayjs@5f446ed)), closes [#1002](iamkun/dayjs#1002)
* support parsing unlimited decimals of millisecond ([#1010](iamkun/dayjs#1010)) ([d1bdd36](iamkun/dayjs@d1bdd36)), closes [#544](iamkun/dayjs#544)
* update Duration plugin to support global locale ([#1008](iamkun/dayjs#1008)) ([1c49c83](iamkun/dayjs@1c49c83)), closes [#1007](iamkun/dayjs#1007)
splashwizard pushed a commit to splashwizard/tracking-time that referenced this issue Oct 21, 2024
## [1.8.34](iamkun/dayjs@v1.8.33...v1.8.34) (2020-08-20)

### Bug Fixes

* Fix Timezone plugin to preserve milliseconds while changing timezone ([#1003](iamkun/dayjs#1003)) ([5f446ed](iamkun/dayjs@5f446ed)), closes [#1002](iamkun/dayjs#1002)
* support parsing unlimited decimals of millisecond ([#1010](iamkun/dayjs#1010)) ([d1bdd36](iamkun/dayjs@d1bdd36)), closes [#544](iamkun/dayjs#544)
* update Duration plugin to support global locale ([#1008](iamkun/dayjs#1008)) ([1c49c83](iamkun/dayjs@1c49c83)), closes [#1007](iamkun/dayjs#1007)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants