-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add a brief comparison with Moment.js? #275
Comments
This was my first thought when I found |
@rauschma Moment.js has a few problems that motivated me to start the project:
Also date-fns works with the native date type: no extra dependencies for date-fns cons is:
Functionality-wise date-fns equals to Moment.js. |
Some more to add from my reply to a recent r/javascript post
Edit: Updated to reflect bundle sizes. Minified bundles are a bad comparison though since ES6 imports and tree shaking, especially since this is a pure function approach. |
|
Good look trying to tree shake Moment.js |
@bfred-it in fact no one need s the full API. It is interesting to bundle functions I need. |
@bfred-it the dist version of date-fns (https://github.com/date-fns/date-fns/blob/master/dist/date_fns.min.js) coming as a single file while with webpack, Browserify (and other module bundler tools) you'll get the only code you use. It's possible to optimize the dist by splitting the functions into "packs", but our focus is |
Perfect! I didn't even realize. 😅 I was only responding to c-dante's comment |
It would be good to add this to the README.md |
Will convert the comments into FAQ. Please tell me if you have more questions. |
We got some perf tests working. Here is a sneak peak preview: https://gist.github.com/kossnocorp/6dccf64b3991622b53e6ebb6aaf20bfd |
A way to do chaining would be absolutely great. Personally I wouldn't mind even altering the built in |
@benjamingr chaining is not good -- mutation of objects defeats the purpose of this library being small, pure functions. Also, manipulating the built-in prototypes is also a bad practice. At that point, just use moment which embrasess that approach. If you want chaining in the sense of not having to do nested functions, check out the FP issue #253 which would let the library support pure function composition nicely. That all being said, a small function (chain) that would basically do what Lodash's wrapper does would support this in a possibly not awful way. |
@c-dante I didn't suggest mutation at all - you can chain functions without mutating the objects. Two example that come to mind are how functional languages like Haskell deal with this through infix notation or how languages like C# deal with it with the To be clear. Something like: imaginaryApi(date).addDays(3).addMinutes(30) Would return a new imaginaryApi(date).addDays(3).addMinutes(30).get() |
Yeah, I don't know if you saw what I added, but I'm not opposed to either the FP changes happening, and implementing the chain as just a "flow wrapper", or creating a light chain operator such as you pointed out. All this being said -- make a different issue with the request? This doesn't pertain to this issue. |
@c-dante you could just return a |
The bind operator :: would be great for chaining in a functional library like date-fns. Maybe look into it after ecma stage 1 approval. |
@benjamingr I've also thought a lot about chaining but IMHO OO is not the right approach for this library because we're talking about date-fns. I'm also worried about tree shaking issues with OO implementation. How about currying and re-ordering of function arguments to support partial application (like Ramda does)? That would enable quite elegant composition of date functions and also supports chaining. // fromMillis :: millis -> date
// format :: format -> date -> formatted-string
// add :: unit -> value -> date -> date
// sub :: unit -> value -> date -> date
// set :: unit -> value -> date -> date
// startOf :: unit -> date -> date
// functions can be used like any other function
fromMillis(0) // => 1.1.1970
startOf("day", new Date()) // today at 00:00
// see http://ramdajs.com/docs/#pipe
const doPipe = (x, ...fns) => R.pipe(...fns)(x)
// supports inline "chaining"
doPipe(fromMillis(0),
set("year", 2016),
add("days", 1),
add("minutes", 50),
sub("seconds", 10),
format("YYYY-MM-DDTHH:mm:ss"))
// => "2016-01-02T00:49:50"
// and point-free composition!
const addDays = add("days")
const startOfHour = startOf("hour")
const tomorrowAt15 = R.pipe(
addDays(1),
set("hour", 15),
startOfHour)
// reusability!
tomorrowAt15(new Date())
const apiObjects = ...
const apiObjsWithModifiedDate =
R.map(R.evolve({start_time: R.pipe(parse, tomorrowAt15)}), apiObjects) However, I see some at least the following caveat in this approach:
|
Hey, there! We're looking for testimonials for the new date-fns.org home page. If you want to share your thoughts with the world, see: date-fns/date-fns.org#93. 😇 |
I am seeing I'll switch to And I am surprised to see momentjs started as 3.7kb lib! WOW, this thing has exploded. |
A comparison with Luxon would be helpful, too. Why not add the "need help" status to this issue, since the comparison page still doesn't exist since this issue was created in 2016? |
And maybe add a comparison like: |
A comparison with dayjs would also be helpful (a 2kb bundle size and moment drop-in replacement). Although |
For those who'd like to transition from momentjs to date-fns, please check out https://github.com/you-dont-need/You-Dont-Need-Momentjs |
How did you extract your metring between your repo and Moment ? |
Also moment stops laravel-mix when you compile as production "npm run prod", if you are using dynamic import of components. 👎 |
Closing due to lack of activity (and the fact that moment.js is not actively maintained anymore) |
Given how much of a de-facto standard Moment.js has become, it may make sense to briefly explain how date-fns differs.
The text was updated successfully, but these errors were encountered: