hconverter
C code to convert dates between Hebrew, Gregorian and Julian calendars
Data Structures | Typedefs | Enumerations | Functions
hconverter.h File Reference

Public header file for hconverter library.

More...

Go to the source code of this file.

Data Structures

struct  hc_date_s
 
struct  heb_time_s
 Hebrew time: hour and parts. More...
 

Typedefs

typedef enum hc_day_of_week hc_day_of_week
 
typedef enum hc_calendar_type hc_calendar_type
 Supported types of calendar. More...
 
typedef struct hc_date_s hc_date
 
typedef struct heb_time_s heb_time
 Hebrew time: hour and parts. More...
 
typedef enum heb_year_type heb_year_type
 enum of possible layouts of the variable length Hebrew months Cheshvan and Kislev in a given year. More...
 

Enumerations

enum  hc_day_of_week {
  SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
  THURSDAY, FRIDAY, SATURDAY
}
 
enum  hc_calendar_type { NONE, GREGORIAN, JULIAN, HEBREW }
 Supported types of calendar. More...
 
enum  heb_year_type { SHORT_HEB_YEAR, NORMAL_HEB_YEAR, FULL_HEB_YEAR }
 enum of possible layouts of the variable length Hebrew months Cheshvan and Kislev in a given year. More...
 

Functions

int set_hc_date (hc_date *, int year, int month, int day, hc_calendar_type)
 
int hc_convert (hc_date *date, hc_calendar_type target_calendar)
 This function converts a date from one calendar to another. More...
 
int hc_check (hc_date *date)
 Check validity of data in hc_date. More...
 
int hc_is_leap_year (int year, hc_calendar_type calendar_type)
 Check if year is leap in given calendar. More...
 
hc_day_of_week hc_get_day_of_week (hc_date *date)
 Function to get day of week out of a hc_date. More...
 
int hc_get_month_length (int year, int month, hc_calendar_type calendar_type)
 Function to get the length of a month. More...
 
int hc_compute_keviut (const int year, int *rosh_hashana_dow, int *pesach_dow, int *ck, int *leap)
 Compute year "keviut" and put the result into 4 integers. More...
 
int hc_set_hc_heb_time (heb_time *time, int hour, int part)
 Convenience method to set heb_time struct value. More...
 
int hc_compute_molad_rosh_hashana (int year, hc_calendar_type cal_type, hc_date *date, heb_time *time)
 Compute the date time of molad of Rosh Hashana for given year. More...
 
int hc_compute_molad (const int year, int month, const hc_calendar_type cal_type, hc_date *date, heb_time *time)
 Compute the date and time of molad (new moon according to the Hebrew calendar) for given year and month. More...
 
heb_year_type hc_get_heb_year_type (int year)
 Compute number of days in excess of 58 in Cheshvan and Kislev combined. More...
 

Detailed Description

Public header file for hconverter library.

Date
Dec 29, 1998
Author
Isaac Mushinsky

Contains all functional offerings of this library: convert dates between Hebrew, Gregorian and Julian calendars as well as compute certain specific times for the new moon, types of Jewish year.

Note about Hebrew month ordering.

Although each Hebrew year starts with the month of Tishrei, Tishrei is not the first in the order of months. There are a couple of reasons for this. Nisan is called the "first month" in the Torah for most purposes. Also, on a Hebrew leap year the 13th month (adar 2) is added before Nisan, not before Tishrei. This makes it more convenient to senumerate months not in chronological order but rather starting from Nisan to the end of year (Elul), and then returning to Tishrei through Adar. Thus the Hebrew months here are represented by integers as follows:

so despite a lower month index, Nisan follows after Adar. For example, the date 5776-01-01 follows 5776-13-29 in yyyy-mm-dd notation.

Note about keviut

Keviut determines layout of the Jewish year, including all holidays and readings of the Torah. It is customary to abbreviate it to 4 parameters:

Only 14 combinations of these are actually possible.

Typedef Documentation

Supported types of calendar.

  • GREGORIAN
  • JULIAN
  • HEBREW
typedef struct hc_date_s hc_date

Structure representing a date.

Convenience enum for days of week: SUNDAY=0, MONDAY=1, ..., FRIDAY=6

typedef struct heb_time_s heb_time

Hebrew time: hour and parts.

This type is specific to Hebrew calendar. Time is measured in hours and chalokim ("parts"), which are 1/1080 of an hour.

enum of possible layouts of the variable length Hebrew months Cheshvan and Kislev in a given year.

  • SHORT_HEB_YEAR means that both Cheshvan and Kislev are 29 days long
  • NORMAL_HEB_YEAR means 29 days in Cheshvan and 30 days in Kislev
  • FULL_HEB_YEAR means that both months are 30 days long

Enumeration Type Documentation

Supported types of calendar.

  • GREGORIAN
  • JULIAN
  • HEBREW

Convenience enum for days of week: SUNDAY=0, MONDAY=1, ..., FRIDAY=6

enum of possible layouts of the variable length Hebrew months Cheshvan and Kislev in a given year.

  • SHORT_HEB_YEAR means that both Cheshvan and Kislev are 29 days long
  • NORMAL_HEB_YEAR means 29 days in Cheshvan and 30 days in Kislev
  • FULL_HEB_YEAR means that both months are 30 days long

Function Documentation

int hc_check ( hc_date date)

Check validity of data in hc_date.

Returns 1 if the date is valid, 0 if the date is invalid in corresponding calendar. The following are invalid: nonpositive Hebrew year, month less than 1 or more than number of months in given year, day less than one or more than days in month.

Parameters
[in]datean hc_date
Returns
0 if invalid, 1 otherwise.
int hc_compute_keviut ( const int  year,
int *  rosh_hashana_dow,
int *  pesach_dow,
int *  ck,
int *  leap 
)

Compute year "keviut" and put the result into 4 integers.

Keviut determines layout of the Jewish year, including all holidays and readings of the Torah. See keviut for more information. Here, we output the "keviut" parameters by setting values of 4 integers whose pointers are supplied with parameters. For any of these output parameters, null pointers are allowed and will be ignored, so users can pass NULL rather than allocate integers for output that they do not need.

Parameters
[in]yearHebrew year
[out]rosh_hashana_dowDay of week for Eosh Hashana (1 Tishrei)
[out]pesach_dowDay of week for Pesach (0 = saturday)
[out]ckreturns 0, 1, 2 (SHORT, REGULAR, FULL) for number of days in excess of 58 in Chesh=van and Kislev combined. (see #hc_heb_year_type)
[out]itwill return 1 for leap years and 0 otherwise
int hc_compute_molad ( const int  year,
int  month,
const hc_calendar_type  cal_type,
hc_date date,
heb_time time 
)

Compute the date and time of molad (new moon according to the Hebrew calendar) for given year and month.

Output parameters are hc_date and heb_time objects, passed in to be populated. No New memory is allocated.

Parameters
[in]year
[in]month
[in]hc_calendar_typeGREGORIAN, JULIAN or HEBREW
[out]datepointer to hc_date struct to store result
[out]timepointer to heb_time to store time result
int hc_compute_molad_rosh_hashana ( int  year,
hc_calendar_type  cal_type,
hc_date date,
heb_time time 
)

Compute the date time of molad of Rosh Hashana for given year.

This is equivalent to <hc_compute_molad> with month set to 7 (Tishrei).

The output params hc_date and heb_time objects are passed in to be populated.

Parameters
[in]year
[in]hc_calendar_typeGREGORINA, JULIAN or HEBREW
[out]datepointer to hc_date struct to store result
[out]timepointer to heb_time to store time result
int hc_convert ( hc_date date,
hc_calendar_type  target_calendar 
)

This function converts a date from one calendar to another.

The given hc_date structure is modified during this call, so no new memory is allocated here.

Parameters
[out]dateThis object will be modified so that it has the target hc_calendar_type set along with corresponding date.
[in]target_calendarsee hc_calendar_type
Returns
0 on success, -1 if the input date is invalid.
hc_day_of_week hc_get_day_of_week ( hc_date date)

Function to get day of week out of a hc_date.

Parameters
date
Returns
a #hc_day of week: 0 for Saturday, 1 for Sunday, ..., 6 for Friday
heb_year_type hc_get_heb_year_type ( int  year)

Compute number of days in excess of 58 in Cheshvan and Kislev combined.

Parameters
[in]yearHebrew year >=1
Returns
can take 3 values:
  • SHORT_HEB_YEAR (0) - both Cheshvan and Kislev 29 days long
  • NORMAL_HEB_YEAR (1) - 29 days in Cheshvan, 30 days in Kislev
  • FULL _HEB_YEAR (2) - 30 days in both Cheshvan and Kislev
int hc_get_month_length ( int  year,
int  month,
hc_calendar_type  calendar_type 
)

Function to get the length of a month.

Parameters
[in]year
[in]month.For Hebrew, see (note) about the special month order.
[in]calendar_typesee hc_calendar_type
Returns
length of month in days
int hc_is_leap_year ( int  year,
hc_calendar_type  calendar_type 
)

Check if year is leap in given calendar.

For Gregorian or Julian calendar this means that length of the year is 366 days. In Hebrew calendar it means that the year has 13 months instead of 12.

Parameters
[in]yearHebrew year >=1
[in]calendar_typesee hc_calendar_type
Returns
1 for leap year, 0 for non-leap year
int hc_set_hc_heb_time ( heb_time time,
int  hour,
int  part 
)

Convenience method to set heb_time struct value.

Parameters
param[out]time
param[in]hour
param[in]part
int set_hc_date ( hc_date ,
int  year,
int  month,
int  day,
hc_calendar_type   
)

Convenience method to set the entire hc_date in one call.

Parameters
[out]datepointer to hc_date structure
[in]year
[in]month
[in]day
[in]calendar_type