dmtrKovalenko / date-io

Abstraction over common javascript date management libraries
MIT License
726 stars 90 forks source link

feat: New methods `startOfYear` and `endOfYear` #614

Closed flaviendelangle closed 2 years ago

flaviendelangle commented 2 years ago

Goal

Add two new methods startOfYear and endOfYear following the model of the other startOfXXX / endOfXXX.

They will be used on @mui/x-date-pickers to improve the behavior when we select a year but the current date is disabled.

For instance if we are on 2018-01-01 and all days are enabled except 2019-01-01 to 2019-01-04. If we change the year from 2018 to 2019, we expect the new date to be 2019-01-04. But right now, it will be 2018-12-31 because we don't limit to the current year when looking for the closest enabled date.

This new method will allow to easily create the minDate / maxDate when looking for the closest valid date.

Side note

With @alexfauquette we now maintain the date pickers from MUI. I will probably have other methods to add (getDate to get the date number in the month would be nice for instance). If you want to organize our work differently between the adapters and the packages we are available to discuss it.

dmtrKovalenko commented 2 years ago

@flaviendelangle would you like to become a collaborator on this project?

flaviendelangle commented 2 years ago

@flaviendelangle would you like to become a collaborator on this project?

Sure !

dmtrKovalenko commented 2 years ago

@flaviendelangle invited you to the project and I see some tests failed. I think once you become a collaborator you can debug everything on CI. Can you please fix them?

The changes are ok, happy to make a release when CI passes

flaviendelangle commented 2 years ago

Thanks for the invitation I will have a look at the tests

codecov-commenter commented 2 years ago

Codecov Report

Merging #614 (df0d5a0) into master (c83bcc8) will decrease coverage by 0.26%. The diff coverage is 87.50%.

@@             Coverage Diff             @@
##            master     #614      +/-   ##
===========================================
- Coverage   100.00%   99.73%   -0.27%     
===========================================
  Files           16       16              
  Lines         1450     1482      +32     
  Branches       186      186              
===========================================
+ Hits          1450     1478      +28     
- Misses           0        4       +4     
Impacted Files Coverage Δ
...kages/date-fns-jalali/src/date-fns-jalali-utils.ts 99.18% <50.00%> (-0.82%) :arrow_down:
packages/hijri/src/hijri-utils.ts 97.61% <50.00%> (-2.39%) :arrow_down:
packages/date-fns/src/date-fns-utils.ts 100.00% <100.00%> (ø)
packages/dayjs/src/dayjs-utils.ts 100.00% <100.00%> (ø)
packages/jalaali/src/jalaali-utils.ts 100.00% <100.00%> (ø)
packages/js-joda/src/js-joda-utils.ts 100.00% <100.00%> (ø)
packages/luxon/src/luxon-utils.ts 100.00% <100.00%> (ø)
packages/moment/src/moment-utils.ts 100.00% <100.00%> (ø)

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 c83bcc8...df0d5a0. Read the comment docs.

dmtrKovalenko commented 2 years ago

Please also add a testcase or ignore to maintain 100% coverage

dmtrKovalenko commented 2 years ago

@flaviendelangle let me know if you need to add something else or I should I release today?

flaviendelangle commented 2 years ago

I won't be able to use it on MUI right away (we have behaviors to clarify before)

So I can do the clonage cleaning I mentioned in a comment before releasing