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
[BUG] dayjs.tz do nothing #1965
Comments
@lilonghe Hello have you initialized dayjs like the exemple below before using it ?
|
@kravorkid Yes, of course, and u can try run this code, it is useful:
|
@lilonghe it's look like the
|
@kravorkid
|
IMO this is a documentation topic:
I already created a pr for making the documentation for this feature more clearly. |
I do not believe this is an issue with documentation. |
@nimrodyanai can you give me some exemple, and what do you want to achieve, maybe i could help on something, for now i've tried something very simple and it seems that it gave me the good UTC-0500 look at the code below :
|
Here you go:
I also tried to use the default timezone. As you can see, the result is a day earlier than expected, and no matter how I test it, I always get this result. What I expected to get was "2002-02-22T22:00:00.000Z". |
@nimrodyanai Try this instead
|
Some confusion here. The format is the input format, which is DD-MMM-YY. I need the output in standard ISO.
|
This time your problem comes from the fact that you just throw a date string to dayjs, hoping that the result wil be what you expect 😄 . According to the documentation, dayjs expects an ISO8601 string as input and So just use customParseFormat plugin if you want to parse a non ISO8601 date. |
That same documentation also says that if I am using anything other than ISO8601, I should use the string+format option, which is what I was trying to do. I have tried the customParseFormat plugin as well as numerous other solutions with the timezone options, none of them work correctly.
And for testing: |
The problem is using 'MMM' in customParseFormat with locale 'en' as there is no definition for 'monthShort' in this locale and the documentation says |
I tried converting the dates so that the format is DD-MM-YY as you suggested, but the result is always the same:
It's as if the zone parameter is just ignored and there is no way to convert it. |
In your code you use the internal variable A better variant of your code sample could look like this:
For me this looks like what you expected; am I right? |
The reason I am using $d is that the object I get back from dayjs is not a date or even a string with the date. The date is inside the object under the $d variable. |
Oh no that is not the idea of internal variables 😄 dayjs(...) returns a dayjs object with many nice fields and functions. So if you want to get a string representation of a dayjs object, you just use the |
That works! |
I suppose by
you mean 'using To use |
I tried using that plugin, and MMM is one of the available formats in the documentation. It even shows the short names in the example exactly as I input them in the string. In the solution you suggested, the plugin actually exists and is called upon. I both cases I am parsing a string to a date. The only difference is that one time the string for example is 24-02-05 and in the other its 24-FEB-05 (and the expected format changes accordingly, of course). |
Here my updated test code:
Is this what you need? |
Yes, thank you! That works great! |
Describe the bug
Expected behavior
dayjs.tz look like do nothing
Information
The text was updated successfully, but these errors were encountered: