moment-business-days icon indicating copy to clipboard operation
moment-business-days copied to clipboard

How to get business days

Open AntonyDamico opened this issue 5 years ago • 6 comments

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'
        });

AntonyDamico avatar Jan 24 '20 08:01 AntonyDamico

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.

ebui91 avatar Jan 29 '20 21:01 ebui91

@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.

AntonyDamico avatar Jan 30 '20 09:01 AntonyDamico

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

Nicolas-Menettrier avatar May 05 '20 13:05 Nicolas-Menettrier

It was just the format don't mind me!

Nicolas-Menettrier avatar May 05 '20 14:05 Nicolas-Menettrier

@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 avatar May 05 '20 14:05 AntonyDamico

Oh ok, good then!

AntonyDamico avatar May 05 '20 14:05 AntonyDamico