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

businessDaysIntoMonth has unexpected behavior #97

Closed eric-gonzalez-tfs closed 3 years ago

eric-gonzalez-tfs commented 3 years ago

Hello all,

I am trying to use this library specifically for businessDaysIntoMonth() but I cannot seem to get it to work.

I can confirm the date used in the tests/test.js works with my environment. However, when I change it to another date or the current moment the function does not return the appropriate value.

    import moment from 'moment-business-days';

    const businessDaysIntoMonth = moment('2015-09-23').businessDaysIntoMonth();
    console.log(businessDaysIntoMonth); // outputs 17 as expected

    const businessDaysIntoMonthCurrent = moment('2021-08-02').businessDaysIntoMonth();
    console.log(businessDaysIntoMonthCurrent); // outputs 1, 22 expected

    const today = moment().businessDaysIntoMonth();
    console.log(today); // outputs 1, 22 expected

I did notice however that the monthBusinessDays is working appropriately and can be used as a workaround.

    const today = moment().monthBusinessDays();
    console.log(today.length); // outputs 22 as expected
mcdado commented 3 years ago

Thanks for reporting. It's a function that I personally never used and that it was added long before I began looking at the project. I think function is poorly named and documented even worse! This function returns the amount of days since the beginning of the month. I'll correct the documentation and I'm glad that you found a workaround.

mcdado commented 3 years ago

Thanks again for bringing this up. Turns out that the function was incredibly buggy! If a month started on a non-business day, it would return the previous month! I corrected it and added more tests.