Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a JewishDate constructor that takes sunset into account #193

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 22 additions & 0 deletions src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Calendar;
import java.util.GregorianCalendar;

import com.kosherjava.zmanim.ComplexZmanimCalendar;

/**
* The JewishDate is the base calendar class, that supports maintenance of a {@link java.util.GregorianCalendar}
* instance along with the corresponding Jewish date. This class can use the standard Java Date and Calendar
Expand Down Expand Up @@ -992,6 +994,17 @@ public JewishDate(int jewishYear, int jewishMonth, int jewishDayOfMonth) {
public JewishDate() {
resetDate();
}

/**
* A constructor that initializes the date to the current system date while taking into account sunset.
*/
public JewishDate(ComplexZmanimCalendar czc) {
if (Calendar.getInstance().after(czc.getSunset())) {
resetDateWithSunset();
} else {
resetDate();
}
}

/**
* A constructor that initializes the date to the {@link java.util.Date Date} paremeter.
Expand Down Expand Up @@ -1220,6 +1233,15 @@ public void resetDate() {
Calendar calendar = Calendar.getInstance();
setDate(calendar);
}

/**
* Resets this date to the current system date plus one (after sunset).
*/
public void resetDateWithSunset() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, 1);
setDate(calendar);
}

/**
* Returns a string containing the Jewish date in the form, "day Month, year" e.g. "21 Shevat, 5729". For more
Expand Down