-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
locales/tz #608
locales/tz #608
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #608 +/- ##
========================================
- Coverage 100% 90.26% -9.74%
========================================
Files 154 157 +3
Lines 986 1438 +452
Branches 141 236 +95
========================================
+ Hits 986 1298 +312
- Misses 0 109 +109
- Partials 0 31 +31
Continue to review full report at Codecov.
|
This node doesn't have complete ICU bundled, so it can't translate texts. (reason why test fails) |
I've also applied for bounty on #46, even if at large they expect API that of moment, which I wouldn't mind getting into. There's already another pull request for adding timezone support though, without the intl usage. |
Removed dependency on date-fns-tz in production and the build somehow got bigger from 3.35 to 3.4, from original 2.52. The api is more moment like. I didn't mess with utc plugin or how it's used, nor changed api to basically assume by default that new instances are in utc if not specified otherwise. |
Even if this doesn't get dayjs all the way there, it looks like a really good start. I'm glad you removed the date-fns dep. It's weird the build got bigger. If you just copy/paste the module from date-fns it should be the same. Even if it gets bigger I think I'd prefer it without the dep. @iamkun This looks like a good start to timezone support. 👏 |
I write trash tests, and then I write mindbending code, that isn't following desired api anyhow. Spectacular. |
It's done except for skipped tests, and above notes. One of the bigger issues is that time modifications-additions/subtractions- won't take into account dst, and dst calculation and detection aren't non-trivial. Calling tz with the same timezone would do it (this.timeZone), or calling the constructor method, or modifying offsetModifier if the above doesn't work- which is in minutes with the example in constructor method, for using offset as way to modify time. |
Btw in terms of backwards DST it will straight up skip an hour, so adding 2 hours just before backwards DST will add 3 instead. |
I believe caching/calculating DST in methods that output date like toDate()/format- which already does- would be ideal, instead of always running DST checks. (by way of modifying offsetModifier, with that in mind $utc method already takes that into account). |
Another thing to mention is that the plugin itself uses add/subtract with the assumption that it's not dst aware |
Thanks for this huge PR. Seems this PR changed core bundle too much to implement this tz feature? |
It adds moment tz data for tests. I don't think it's tree shaking the stuff used in tests. |
Or it might be adding the polyfill that shouldn't load by default unless you specify locale for which you haven't loaded dayjs data. |
Before I added moment data it was 3.4, and it's still 3.4 Removing polyfill call brings it to 3.28. Removing test packages and data doesn't help. Removing intl locales functionality brings it down to 2.78 without the polyfill, so I suppose it's just massive. |
All right. Thanks. Need some time reviewing this large PR. |
The original size being 2.52. |
I just remembered that I haven't updated d.ts. I don't know how to make the distinction the there's tz method on prototype and instance. |
I'd like to see this PR implemented, I love dayjs but the requirements of my company have changed and we need to support different timezones so I'd have to go back to momentjs. |
I believe npm lets you install packages from specific commits/branches. Be warned that this pr doesn't include interoperability with some of other dayjs methods (they won't recognize dst). |
I wouldn't mind implementing the ineroperability with rest of library so long as I know what iamkun would be happy with-implementation wise, or splitting this pr down into two. |
The localization of text could probably be its own plugin. I don't know how to stop the polyfill from being bundled even if telling rollup.js about it. |
@janat08 Finally got time review this PR. Thanks. The reason why I haven't merge this PR is it changed our main code a lot and the plugin itself is a little bit complicated( but timezone is complicated). I'm looking for a way to implement tz support in a simple way, or just split this plugin into a separate repo. |
After careful reviewing this pr, we decided to pending it because,
|
Yes, I said that I havent gone about running dst checks when the methods like add are run. I also suggested extracting the code into separate packages. |
Should I get to it as I have nothing better to do currently. Or more accurately I could use the money. |
@janat08 Thanks anyway. I'm currently digging all the source codes of other libs to look for a better way for us. |
The only lib that uses intl: https://date-fns.org/v2.4.1/docs/Time-Zones At first I was just going to use that, not sure why I didn't. |
also luxon |
Any chance my code is actually better? |
Could use the bounty. |
1 similar comment
Its been half a year |
At this rate they'll probably improve the intl api, and this would be fixing a problem that doesn't exist. If you really want to be conservative about performance why not have users manually trigger DST checks? |
Day.js Time Zone Plugin https://day.js.org/docs/en/timezone/timezone |
Update: Day.js Time Zone Plugin https://day.js.org/docs/en/timezone/timezone
#498