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

Optional moment.js Part 2 #1052

Merged

Conversation

prayerslayer
Copy link
Contributor

@prayerslayer prayerslayer commented Oct 3, 2017

Basically it's #1046 minus moment in tests.

The idea is that after this PR I can:

  1. create a new date_utils without moment
  2. copy tests, give components a flag which utils to use and switch the utility module in test code
  3. refactor react-datepicker to work with whatever while having a good idea if I broke something

@codecov
Copy link

codecov bot commented Oct 3, 2017

Codecov Report

Merging #1052 into master will increase coverage by 0.4%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1052     +/-   ##
=========================================
+ Coverage    83.1%   83.51%   +0.4%     
=========================================
  Files          13       13             
  Lines         817      837     +20     
  Branches      141      141             
=========================================
+ Hits          679      699     +20     
  Misses         33       33             
  Partials      105      105
Impacted Files Coverage Δ
src/date_utils.js 92.44% <100%> (+0.99%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3c9d89...7b82f65. Read the comment docs.

Copy link
Contributor

@aij aij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. @martijnrusschen Care to take a look?

@@ -24,105 +27,105 @@ describe('Calendar', function () {
}

it('should start with the current date in view if no date range', function () {
const now = moment()
const now = utils.newDate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a bit cleaner to use separate functions to parse a date and to get the current date. We can leave that for later though, since moment() did serve both purposes too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, had exactly the same thought :)

@martijnrusschen
Copy link
Member

Seems solid. Lots of changes, so lets hope we don't break anything. How should we move forward with this. First merge part 1?

@prayerslayer
Copy link
Contributor Author

How should we move forward with this. First merge part 1?

Since this part contains also part 1, we can close the other and merge only part 2.

@aij
Copy link
Contributor

aij commented Oct 3, 2017

@martijnrusschen Sounds good, that way it's clear the changes to the code are independent from the changes to the unit tests.

@martijnrusschen
Copy link
Member

@prayerslayer Part 1 got merged. Can you rebase your PR so that we can merge part 2 as well?

@prayerslayer prayerslayer force-pushed the feature/optional-moment-part2 branch from 9e86cd0 to f046042 Compare October 3, 2017 15:29
@prayerslayer
Copy link
Contributor Author

Done.

@martijnrusschen martijnrusschen merged commit 7829235 into Hacker0x01:master Oct 3, 2017
@prayerslayer
Copy link
Contributor Author

WIP of Part 3 is here: https://github.com/prayerslayer/react-datepicker/tree/feature/optional-moment-part3

  • I'll probably need to refactor how locales are handled. A major advantage of date-fns is that it doesn't include a bazillion locales right away, so we'd probably need to give up string locales (locale="fr") in favour of locale data that is useful for the formatting function (locale={require("date-fns/locale/fr")} / locale={moment.localeData('fr')}).
  • What gives me a bit of headache is the UTC offset. As far as I see there is no way to get a JS Date with a timezone other than what you're currently in. Ofc you can do something like new Date(Date.UTC(year, month, day)), with year, month, day being values in UTC, but the Date object will still show GMT+2 or whatever. Not sure yet how to work around this, advice is welcome.

@martijnrusschen
Copy link
Member

I'll probably need to refactor how locales are handled. A major advantage of date-fns is that it doesn't include a bazillion locales right away, so we'd probably need to give up string locales (locale="fr") in favour of locale data that is useful for the formatting function (locale={require("date-fns/locale/fr")} / locale={moment.localeData('fr')}).

Sounds fine. As long as we discuss this as a breaking change

What gives me a bit of headache is the UTC offset. As far as I see there is no way to get a JS Date with a timezone other than what you're currently in. Ofc you can do something like new Date(Date.UTC(year, month, day)), with year, month, day being values in UTC, but the Date object will still show GMT+2 or whatever. Not sure yet how to work around this, advice is welcome.

Not sure how what's desired here. Any suggestions?

@prayerslayer
Copy link
Contributor Author

prayerslayer commented Oct 18, 2017

Hi, thanks for taking the time. I already opened a PR to discuss details about this. #1059 It has a proof of concept too.

Not sure how what's desired here. Any suggestions?

Yeah. My proposal is that all timezone related functions would be no-ops when using date-fns, until the library can work with TZs (if ever). That way

  • we don't build a subset of moment with less tests
  • we don't extend the underlying library in a non-obvious way
  • users still get to choose based on their needs: Want a really small bundle and TZs are not an issue? Go with date-fns-backed datepicker. Definitely need TZs? Well, then you're stuck with moment anyways.

At first I tried to extract the TZ logic from moment into something separate, but quickly realized I'm building moment on top of date-fns, as you have to consider TZ information for all regular operations like adding hours etc. That's an option too, but it can be done later imo.

@aij aij mentioned this pull request Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants