Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ public int getMoladChalakim() {
* the month. As with other cases in this class, this is 1-based, not zero-based.
* @return the number of days in the month in the given year
*/
private static int getLastDayOfGregorianMonth(int year, int month) {
// @VisibleForTesting
protected static int getLastDayOfGregorianMonth(int year, int month) {
return YearMonth.of(year, month).lengthOfMonth();
}

Expand Down Expand Up @@ -1280,12 +1281,8 @@ public Object clone() {
return clone;
}

/**
* Overrides {@link Object#hashCode()}.
* @see Object#hashCode()
*/
@Override
public int hashCode() {
return Integer.hashCode(gregorianAbsDate);
}
@Override
public int hashCode() {
return gregorianAbsDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

package com.kosherjava.zmanim.hebrewcalendar;

import static org.junit.Assert.assertEquals;

import org.junit.*;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;

/**
* Validate the days in a Hebrew month (in various types of years) are correct.
*/
Expand Down Expand Up @@ -111,4 +117,15 @@ private void assertShalemLeap(int year) {
Assert.assertTrue(jewishDate.isJewishLeapYear( ));
}

@Test
public void earlyGregorian() {
LocalDate localDate = LocalDate.of(1582, Month.OCTOBER, 15);
JewishDate jewishDate = new JewishDate(localDate);

assertEquals(DayOfWeek.FRIDAY, localDate.getDayOfWeek());
assertEquals(5343, jewishDate.getJewishYear());
assertEquals(JewishDate.TISHREI, jewishDate.getJewishMonth());
assertEquals(19, jewishDate.getJewishDayOfMonth());
}

} // End of UT_DaysInJewishMonth class
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

package com.kosherjava.zmanim.hebrewcalendar;

import static org.junit.Assert.assertEquals;

import org.junit.*;

import java.time.Month;

/**
* Verify correct calculations of when a Hebrew leap year occurs.
*/
Expand Down Expand Up @@ -63,4 +67,39 @@ private void shouldNotBeLeapYear(int year) {
Assert.assertFalse(jewishDate.isJewishLeapYear( ));
}

@Test
public void icu() {
for (int y = 0; y < 10000; y++) {
assertEquals(isLeapYearICU(y), JewishDate.isJewishLeapYear(y));
}
}

/** android.icu.util.HebrewCalendar */
public static boolean isLeapYearICU(int year) {
int x = (year * 12 + 17) % 19;
return x >= ((x < 0) ? -7 : 12);
}

@Test
public void leapYears(){
final int MONTH_FEBRUARY = Month.FEBRUARY.getValue();
for (int y = 0; y < 10000; y++) {
assertEquals(isLeapYearWiki(y), JewishDate.getLastDayOfGregorianMonth(y, MONTH_FEBRUARY) == 29);
}
}

/** https://en.wikipedia.org/wiki/Leap_year#Algorithm */
private static boolean isLeapYearWiki(int year) {
if (year % 4 != 0) {
return false;
}
if (year % 100 != 0) {
return true;
}
if (year % 400 != 0) {
return false;
}
return true;
}

} // End of UT_JewishLeapYear class
Loading