26 : mYear ( d.year ), mMonth ( d.month ), mDay ( d.day ),
27 mDayOfWeek ( d.day_of_week ),
28 mHebrewMonthLength ( d.hebrew_month_length ),
29 mSecularMonthLength ( d.secular_month_length ),
30 mOnHebrewLeapYear ( d.hebrew_leap_year_p ),
31 mOnSecularLeapYear ( d.secular_leap_year_p ),
32 mKvia ( d.kvia ), mHebrewDayNumber ( d.hebrew_day_number )
43 Converter::secularToHebrewConversion( year, month, day, &result );
50 Converter::hebrewToSecularConversion( year, month, day, &result );
76 return mHebrewMonthLength;
81 return mSecularMonthLength;
86 return mOnHebrewLeapYear;
91 return mOnSecularLeapYear;
101 return mHebrewDayNumber;
106 long Converter::absolute_from_gregorian(
int year,
int month,
int day )
108 int xyear, day_number;
111 day_number = day + 31 * ( month - 1 );
113 day_number -= ( 23 + ( 4 *
month ) ) / 10;
114 if ( gregorian_leap_year_p( year ) ) {
121 + ( -( xyear / 100 ) )
127 long Converter::absolute_from_hebrew(
int year,
int month,
int day )
129 long sum = day + hebrew_elapsed_days( year ) - 1373429L;
133 int months = hebrew_months_in_year( year );
134 for ( i = 7; i <= months; ++i ) {
137 for ( i = 1; i <
month; ++i ) {
141 for ( i = 7; i <
month; ++i ) {
149 void Converter::gregorian_from_absolute(
long date,
int *yearp,
int *monthp,
154 for ( year = date / 366;
155 date >= absolute_from_gregorian( year + 1, 1, 1 ); ++
year ) {}
159 ( date >= absolute_from_gregorian( year, 1 + month, 1 ) );
162 day = 1 + date - absolute_from_gregorian( year, month, 1 );
169 void Converter::hebrew_from_absolute(
long date,
int *yearp,
int *monthp,
174 gregorian_from_absolute( date, &gyear, &gmonth, &gday );
176 while ( date >= absolute_from_hebrew( 1 + year, 7, 1 ) ) {
179 months = hebrew_months_in_year( year );
181 date > absolute_from_hebrew( year, month,
183 month = 1 + ( month % months ) ) {}
184 day = 1 + date - absolute_from_hebrew( year, month, 1 );
191 int Converter::hebrew_months_in_year(
int year )
201 int Converter::hebrew_month_length(
int year,
int month )
220 if ( ( hebrew_year_length( year ) % 10 ) == 5 ) {
228 if ( ( hebrew_year_length( year ) % 10 ) == 3 ) {
248 int Converter::secular_month_length(
int year,
int month )
267 if ( gregorian_leap_year_p( year ) ) {
279 bool Converter::gregorian_leap_year_p(
int year )
281 if ( ( year % 4 ) != 0 ) {
284 if ( ( year % 400 ) == 0 ) {
287 if ( ( year % 100 ) == 0 ) {
294 bool Converter::hebrew_leap_year_p(
int year )
296 switch ( year % 19 ) {
314 long Converter::hebrew_elapsed_days(
int year )
316 static int saved_year[
MEMORY] = { -1, -1, -1, -1, -1 };
317 static long saved_value[
MEMORY];
320 for ( i = 0; i <
MEMORY; ++i ) {
321 if ( year == saved_year[i] ) {
322 return saved_value[i];
325 for ( i = 0; i < MEMORY-1; ++i ) {
326 saved_year[i] = saved_year[1 + i];
327 saved_value[i] = saved_value[1 + i];
329 saved_year[MEMORY - 1] =
year;
330 saved_value[MEMORY - 1] = hebrew_elapsed_days2( year );
331 return saved_value[MEMORY - 1];
336 long Converter::hebrew_elapsed_days2(
int year )
338 long prev_year = year - 1;
339 long months_elapsed = 235L * ( prev_year / 19 ) +
341 12L * ( prev_year % 19 ) +
343 ( ( ( prev_year % 19 ) * 7 + 1 ) / 19 );
345 long parts_elapsed = 5604 + 13753 * months_elapsed;
346 long day = 1 + 29 * months_elapsed + parts_elapsed / 25920;
347 long parts = parts_elapsed % 25920;
348 int weekday = day % 7;
350 ( ( parts >= 19440 ) ||
355 switch ( alt_day % 7 ) {
366 int Converter::hebrew_year_length(
int year )
368 return hebrew_elapsed_days( 1 + year ) - hebrew_elapsed_days( year );
372 void Converter::secularToHebrewConversion(
int syear,
int smonth,
int sday,
375 int hyear, hmonth, hday;
378 absolute = absolute_from_gregorian( syear, smonth, sday );
380 hebrew_from_absolute( absolute, &hyear, &hmonth, &hday );
382 result->
year = hyear;
383 result->
month = hmonth;
385 finish_up( absolute, hyear, hmonth, syear, smonth, result );
389 void Converter::hebrewToSecularConversion(
int hyear,
int hmonth,
int hday,
392 int syear, smonth, sday;
395 absolute = absolute_from_hebrew( hyear, hmonth, hday );
396 gregorian_from_absolute( absolute, &syear, &smonth, &sday );
397 result->
year = hyear;
398 result->
month = hmonth;
400 finish_up( absolute, hyear, hmonth, syear, smonth, result );
404 void Converter::finish_up(
long absolute,
int hyear,
int hmonth,
405 int syear,
int smonth,
412 result->
kvia = ( hebrew_year_length( hyear ) % 10 ) - 3;
int hebrewMonthLength() const
static HebrewDate fromHebrew(int year, int month, int day)
static HebrewDate fromSecular(int year, int month, int day)
bool isOnSecularLeapYear() const
This class converts dates between the Hebrew and Gregorian (secular) calendars.
HebrewDate(struct DateResult)
int hebrewDayNumber() const
bool isOnHebrewLeapYear() const
int secularMonthLength() const