Skip to content
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

How to get business days #82

Open
AntonyDamico opened this issue Jan 24, 2020 · 6 comments
Open

How to get business days #82

AntonyDamico opened this issue Jan 24, 2020 · 6 comments

Comments

@AntonyDamico
Copy link

AntonyDamico commented Jan 24, 2020

I modified the locale to add holidays but now I need to know how many I added in another part that, is there a way to get them from the moment object? I know I could just use the holidays variable, but I want to use the moment object.

const holidays = [
                '01/01/2020',
                '06/01/2020',
                '10/04/2020',
                '01/05/2020',
                '15/08/2020',
                '12/10/2020',
                '08/12/2020',
                '25/12/2020',
            ];

moment.locale('es', {
            holidays,
            holidayFormat: 'DD/MM/YYYY'
        });
@ebui91
Copy link

ebui91 commented Jan 29, 2020

Hi @AntonyDamico, have you tried using moment.localeDate()._holidays? You might need to replace moment with whatever you're importing moment-business-days as.

On a sort of related note, I am needing to configure holidays as well and was wondering how you're accounting for holidays in which the date may change from year to year? For example, MLK was on the January 20th this year but January 21st last year.

@AntonyDamico
Copy link
Author

AntonyDamico commented Jan 30, 2020

@ebui91, I actually figured out and added it as a new method, but thanks anyway.

On your question, The backend devs used a holidays API and saved a buch of years in the db, I think This is the API.

@Nicolas-Menettrier
Copy link

Hello, I'm in the exactly same issue as @AntonyDamico, can you share your solution if you still have it please ?

@Nicolas-Menettrier
Copy link

It was just the format don't mind me!

@AntonyDamico
Copy link
Author

@Nicolas-Menettrier sure, as @ebui91 said I used localeData()._holidays. I just went to the source code ant the end and added these lines

moment.fn.getHolidays = function () {
 return this.localeData()._holidays
}

And then you can just use getHolidays () as a function.

@AntonyDamico
Copy link
Author

Oh ok, good then!

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

No branches or pull requests

3 participants