commenthol / date-holidays

worldwide holidays
https://commenthol.github.io/date-holidays/
Other
911 stars 236 forks source link

holidays.isHoliday() returning Array instead of true false #374

Closed sid028 closed 1 year ago

sid028 commented 1 year ago

Hi, I am trying to fetch the next working day of the bank. To find that I am trying the bellow code but the isHoliday() function is not returning me boolean value. but if I use something like holidays.isHoliday(new Date()) in this case it returns true and false.

Here is my method :

import * as DateHolidays from "date-holidays";

const holidays = new DateHolidays.default();
   holidays.init("se");

const getNextWorkingDate = () => {
    let year = new Date().getFullYear();
    let month = new Date().getMonth();
    const date = new Date(year, month, 1);
    console.log("date >>>>> ", date);
    while (date.getMonth() === month) {
      const endDate = moment(new Date(date));
      if (endDate.diff(new Date(), "days") > 0) {
        if (!holidays.isHoliday(new Date(date))) {
          let workingDate = new Date(date);
          return workingDate;
        }
      }
      date.setDate(date.getDate() + 1);
    }
    return new Date();
  };

Please let me know how will it work!!

Thanks