TheAlgorithms / JavaScript

Algorithms and Data Structures implemented in JavaScript for beginners, following best practices.
https://the-algorithms.com/language/javascript
GNU General Public License v3.0
31.77k stars 5.44k forks source link

fix: properly floor the partial results in `DateDayDifference` #1629

Closed vil02 closed 4 months ago

vil02 commented 4 months ago

Open in Gitpod know more

Describe your change:

Currently DateDayDifference('29/02/2024', '04/03/2024') gives 5. This PR fixes that. Further more:

Checklist:

codecov-commenter commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 83.91%. Comparing base (83b4dd8) to head (3368c0d).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1629 +/- ## ========================================== + Coverage 83.89% 83.91% +0.01% ========================================== Files 377 377 Lines 19736 19733 -3 Branches 2916 2919 +3 ========================================== + Hits 16558 16559 +1 + Misses 3178 3174 -4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

vil02 commented 4 months ago

CheckDayAndMonth should ideally compute how many days a month has (based on the year) and check against that (you don't need to do this though).

A function like ParseSimpleDate could be used both in DateToDay and DateDayDifference (i.e. the input would be a string "24/03/2024" and the output would be some kind of tuple with day, month and year). It should also check if the resulting date is correct (including correct number of days for given month). I was planning to spend some time on it after this and #1628 are merged.