1

I am encountering a design problem on a new project. I have chosen the library Luxon (https://moment.github.io/luxon/) because I think it suits this project perfectly. Date-fns (https://date-fns.org/) is also great but suffers from very bad timezone support.

Now, I am also using a datepicker library called react-datepicker (https://reactdatepicker.com/). This is used by my company. The problem is react-datepicker uses date-fns under the hood. Of course both libraries will perfectly work fine in the project, but since I am not the only one working on this project, it will lead to confusion. For examples:

  • date and time formatting tokens might be different in both libraries
  • Luxon rap dates in a DateTime object which might lead to confusion on what values are really returned.

I have no idea how to manage this potentially disastrous design. What should I do? If I removed date-fns, react-datepicker will fail to work. If I removed luxon, I can no longer handle timezones. Please help.

  • 2
    stackoverflow.com/a/58684120/6397798 in this answer there are a couple of available npm packages that add timezone support to date-fns. It might be an option. – bracco23 Aug 5 at 8:12
  • @bracco23 Yes I tried it before, it is not usable in my use case. – morbidCode Aug 5 at 15:08
3

You already listed two solutions - removing luxon, and removing date-fns - which are unacceptable to you. The simplest remaining option, as ugly as it is, would be to use both libraries side by side and accept the ugliness.

Another (expensive) option would be to implement an API wrapper above luxon which provides date-fns compatibility, and let react-datepicker use that. I have no idea whether that's even possible here. Good luck finding a sponsor for significant development work with no obvious end-user value :-)

| improve this answer | |
  • As mentioned also in the comments on the question, a third option is to add timezone support to date-fns – Bart van Ingen Schenau Aug 5 at 10:28
  • @BartvanIngenSchenau yes, I've upvoted that comment. Might well be the best solution. – Hans-Martin Mosner Aug 5 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.