Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Working with Friday and Saturday weekends #44

Open
fardeem opened this issue May 26, 2016 · 10 comments
Open

Working with Friday and Saturday weekends #44

fardeem opened this issue May 26, 2016 · 10 comments

Comments

@fardeem
Copy link

fardeem commented May 26, 2016

Is this possible without forking?

Thanks 😄

@jamesplease
Copy link
Owner

Thanks for the issue @fardeemmunir !

Unfortunately, this only works for western weeks since that's what I was building it to support. If you wanted to PR an update I would gladly merge it in. And if you need any help I could provide some guidance, too. I just don't have the time to dedicate to doing the whole feature atm.

One idea is that week/weekend methods could accept a third arg, options, with a single attr (for now), weekend: [], which would accept a list of days to consider weekends. So, for instance,

weekend: [0, 6] would be the default, but [5, 6] would be what you're looking for. i.e.;

business.weekDays(momentOne, momentTwo, {
  weekend: [5, 6]
});

This should be easier to do on the weekDays method, since it uses a generalized algorithm for computation, but might be less easy to do addWeekDays, since it's more ad hoc. I have on my backlog to update addWeekDays (#36), but I'm not sure when I'll get around to it :)

Anyway, hope this helps!

@jamesplease
Copy link
Owner

jamesplease commented Mar 1, 2017

This would likely require a big update to the add algorithm, and a little update to the day diff algorithm.

But here's what I'm thinking for adding/subtracting:

  • you define an abstract notion of an interval of 7 items. these are the weekdays (this will come in handy shortly)
  • the numbers that the user inputs into the array represent holes in the interval
  • the start date can occur on a partial interview, so you compute that first week in a special manner
  • once they reach the end of that interval (if they do), then you can do a single calculation for the remaining weeks by dividing out the remaining days to add by the number of days each interval subtracts

For weekdays between two dates:

the same algo we currently have should work fine. you'd just find the contained-periodic values for the values that the user input, rather than 0 and 6.

@sseidametov
Copy link

image
Can you please explain me what the hell is going on?

@jamesplease
Copy link
Owner

jamesplease commented Jun 23, 2017

@sseidametov , sure, I can take a look. Would you mind opening a new issue? This seems unrelated to making weekends Fri/Sat rather than Sat/Sun. When you open the issue, can you share the code you used to create the moments? That will help me look into this.

Initial thoughts: read this section of the README. You should not have times in there. Then, make sure you understand how the intervals of this lib work.

My guess is that you're getting weird results because Moment is miscomputing the number of days in your interval because of the times, which can be unpredictable. That, on top of the interval behavior, can make people ask questions like, "what the hell is going on!" Most of the time, issues with this lib have largely been due to bad inputs rather than the algo itself.

Thanks!

@SaharZehavi
Copy link

I added this ability on the vanilla js version.
i hope to find some time to add this to the moment version as well, assuming the changes aren't that big.
jamesplease/bizniz.js#14

@jamesplease
Copy link
Owner

@SaharZehavi , thank you! That's awesome. I'll review your code soon. I think a lot of people will appreciate this :)

@SaharZehavi
Copy link

Don't thank me yet, after farther testing I found that it doesn't work exactly as I want it.
I'll continue to work on it tomorrow, you're more than welcome to review it and see if there's anything you see that needs improving...

@SaharZehavi
Copy link

Fixed what was bothering me. hope you'll add it to the main and the moment version :)

@kapowaz
Copy link

kapowaz commented Jun 20, 2018

Did this PR get merged or abandoned? I’m working on something that uses moment.js and I need to account for the Friday/Saturday weekend in UAE. Would love to make use of something to account for this, but I’m happy to create a PR to add this functionality if necessary!

@jamesplease
Copy link
Owner

Hi @kapowaz ! It has not been merged, but there’s more work to do on the vanilla JS PR to land the changes. There’s a link a few comments up.

I’d be happy to review a PR if you get around to it!

Also, if anyone wants to become a maintainer of this library, let me know.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants