3 ms·
When I see things like dayjs().diff(dayjs(), 'years'); I get an uncomfortable feeling. That's an awkward question to answer (except in some informal approxi
by smhg 8y ago
When I see things like
dayjs().diff(dayjs(), 'years');
I get an uncomfortable feeling. That's an awkward question to answer (except in some informal approximation contexts maybe).
I see a part of the milliseconds to X (years in this case) conversion code was copied from moment.
At some point (still?) moment defined that for some calculations/conversions a month lasts 30 days. Needless to say this gives you all kinds of weird outcomes.
- underwater 8y agoI ended up writing a simple date library that used objects with year, month and day keys to represent dates. It made it much easier to define operations like “the same day next month” in a way that didn’t break down on edge cases, and using plain objects worked much more nicely with Redux, et al. https://github.com/joshduck/simple-day/blob/master/src/SimpleDay.js https://github.com/joshduck/simple-day/blob/master/src/Simpl...