-
Notifications
You must be signed in to change notification settings - Fork 13
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 businessDiff method #45
base: master
Are you sure you want to change the base?
Conversation
between DateTimes.
In practice this would be handled based on developer needs.
Codecov Report
@@ Coverage Diff @@
## master #45 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 116 133 +17
Branches 23 33 +10
=========================================
+ Hits 116 133 +17
Continue to review full report at Codecov.
|
@amaidah oddly, the tests were passing when this was submitted but when I opened vscode today they were failing. I've refactored to clear out some of the spider webs left over from a day of working :) |
Hey, thanks for opening a PR -- I will take a look (can't promise this weekend). I remember thinking about this method originally and had thought about changing the interface a bit. |
Sounds good, and you're welcome 😄 |
added includeEndDate
Swapped out the relative param for a config object. |
@amaidah sorry to bother, but have you had a chance to take a peek? |
Thanks for being super patient, not yet. Will try for this week |
/** | ||
* @typedef BusinessDiffConfig | ||
* @property {boolean} [includeEndDate=false] - include the end date in the calculation | ||
* @property {boolean} [relative=false] - signs the return value as negative if end date is in the past |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I think about how I use a calendar, I say things like 2 days ago (-2) so it doesn't make total sense to me that a difference would be absolute by default. Is there a reason for this? I remember being confused with the moment version of this plugin when I first saw that too.
Both diff and diffNow are relative and I'd like to to keep this plugin similar to Luxon core concepts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the rationale is that you already have methods for determining whether a date is in the past and it is probably a less common scenario to need a negative value for a business day calculation.
That being said, consistency is a really strong argument so if you think it would be better defaulting relative to true I will support that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok cool, let's go with relative as default
src/index.test.js
Outdated
|
||
it('knows there are 3 business days between two dates that are 3 business days apart', () => { | ||
const myCompanyTakesNoHolidays = []; | ||
const startDate = DateTime.local().startOf('day'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is .startOf
necessary for the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In all honestly, it's been a while and it's possible that startOf only seemed necessary as a symptom of another resolved problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing them on local seems to not affect the tests, perhaps we can refactor them out.
Co-authored-by: Andrew Maidah <[email protected]>
Co-authored-by: Andrew Maidah <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #45 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 116 136 +20
Branches 23 34 +11
=========================================
+ Hits 116 136 +20
Continue to review full report at Codecov.
|
Put startOf call back in. Co-authored-by: Andrew Maidah <[email protected]>
Hmm...running into some failing tests when the current date is not a valid business day. Going to investigate. How should calculations work if performed on a non-business day? |
Ok upon further investigation, it was already working correctly, it was just a matter of a bad test. I am interested in your input on this, but maybe we should have a separate test for starting on a non-business day. |
Should just return the number of days that are business days between the two compared dates right? So if starting on Sat, and the next day is Sun and both are nonbusiness running a
Yes, now that you bring it up, sounds smart to test for a few more things:
I also include error handling conditional for the other methods: if (!dt.isValid) {
return dt;
} Maybe we should think about returning an error if trying to call |
That's actually a good point that isn't currently accounted for. I just added the following: let daysDiff = Number(
includeEndDate && end.isBusinessDay() && !end.isHoliday()
); Testing for starting on a non-business day should be next on the list. I will work on that over the weekend. In the meantime, I've updated the branch to use a static start date of Monday May 3 2021. |
FYI, I merged in a bunch of dependabot PRs so you may need to pull from master |
Thanks for letting me know! |
I'm interested in using this method. Can you merge the PR? |
Added businessDiff method to get number of business days between DateTimes.
After completing the switch from Moment to Luxon, I realized this functionality was missing in this library. The solution was to borrow from https://github.com/kalmecak/moment-business-days/blob/master/index.js.
Usage: