Skip to content

Conversation

@leduyquang753
Copy link
Contributor

@leduyquang753 leduyquang753 commented Dec 31, 2024

(This is part of a set of multiple pull requests looking to overhaul the calculation functions.)

The current implementation of elapsedTime just assumes there are 30 days in a month, which causes overshoots when roundToSingleUnit takes its result and, in a rather roundabout way, tries to compute the original date back.

This pull request reimplements the function so that it is consistent with applyDuration: applying the duration to the reference date always gives the original input date.

In math form:

If diff = date2 - date1 (elapsedTime) then date2 = date1 + diff (applyDuration) 

In code:

applyDuration(date1, elapsedTime(date2, 'second', date1)) === date2
The new implementation is consistent with `applyDuration` so that: if with `elapsedTime`: diff = d2 - d1 then with `applyDuration`: d1 + diff == d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants