hebcal/hebcal-es6

Is there a way to check if a specific date is a shabbos mevarchim? and also get the molad for that rosh chodesh?

Closed this issue ยท 4 comments

So far the only way I can see is to get all events for a month and check for each event if it's on the same day, is there a way to get all events for a day? and if yes can I get only specific event types??

Have you tried using this API?

HebrewCalendar.getHolidaysOnDate(date, [il]) โ‡’ Array.<Event>

Returns an array of Events on this date (or undefined if no events)

Kind: static method of HebrewCalendar

Param Type Description
date HDate | Date | number Hebrew Date, Gregorian date, or absolute R.D. day number
[il] boolean use the Israeli schedule for holidays

Alternatively if you just want to get Mevarchim HaChodesh, you can use the HDate.onOrBefore(6) to find the nearest Shabbat to the 29th of a month.

  const monthsInYear = HDate.monthsInYear(year);
  for (let month = 1; month <= monthsInYear; month++) {
    const monthName = HDate.getMonthName(month, year);

    if (month === months.ELUL) {
      continue;
    }

    // Don't worry about month overrun; will get "Nisan" for month=14
    const nextMonthName = HDate.getMonthName(month + 1, year);
    add(new MevarchimChodeshEvent(new HDate(29, month, year).onOrBefore(6), nextMonthName));
  }

Or you could also do something like this:

  const events = HebrewCalendar.calendar({
    year: 5784,
    isHebrewYear: true,
    mask: flags.SHABBAT_MEVARCHIM,
  });

Taking into account @mjradwin's response, I would like to highlight that you have the option to specify a start and end date in the calendar options:

const events = HebrewCalendar.calendar({
    year: 5784,
    isHebrewYear: true,
    mask: flags.SHABBAT_MEVARCHIM,
    start: new Date("2023-12-01"), // Replace this with your desired start date,
    end: new Date("2023-12-07"), // Replace this with your desired end date,
});

I encountered a similar requirement in the past. What I did was retrieve the start date and end date of the week for the desired date. Once you have these dates, you can use them as the start and end calendar dates. This way, you will obtain the events for that particular week, including Mevarchim Shabbos.

Lastly, if you want to calculate the molad directly, you can also do this:

import {Molad, months} from '@hebcal/core';
const m = new Molad(5787, months.SIVAN);
console.log(m.render('en'));
console.log(m.render('he'));

Molad

Represents a molad, the moment when the new moon is "born"

Kind: global class