eduolalo / moment-business-days

This is a momentJS plugin that allows you to use only business days (Monday to Friday)
MIT License
240 stars 67 forks source link

How to get business days #82

Open AntonyDamico opened 4 years ago

AntonyDamico commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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

Nicolas-Menettrier commented 4 years ago

It was just the format don't mind me!

AntonyDamico commented 4 years ago

@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 commented 4 years ago

Oh ok, good then!