zmanim icon indicating copy to clipboard operation
zmanim copied to clipboard

How do i add a day to JewishCalendar?

Open chacham2 opened this issue 4 years ago • 4 comments

How do i add a day to the calendar?

I'm still playing with this as i learn to use it (in vb, via ikvm). So, i may just be doing it wrong. Anyway, i want to list times, parasha, daf, and probably the date. Times uses ZmanimCalendar; parasha and daf use JewishCalendar; date uses JewishDate.

I set up a few variables to get the object i think i need:

Private ReadOnly Today As New JewishCalendar
Private ReadOnly Shabbos As New JewishCalendar
Private ReadOnly Yom As New JewishDate
Private ReadOnly Zmanim As New ZmanimCalendar(New util.GeoLocation(Name, Latitude, Longitude, java.util.TimeZone.getTimeZone(TimeZone)))

formatParsha() requires it to be Shabbos, so i used this successfully:

Dim Saturday As Date = Date.Today.AddDays(DayOfWeek.Saturday - DateAndTime.Today.DayOfWeek)
Shabbos.setGregorianDate(Saturday.Year, Saturday.Month - 1, Saturday.Day)
Debug.WriteLine(Formatter.formatParsha(Shabbos))

Daf needs no calculations, so:

Debug.WriteLine(Formatter.formatDafYomiBavli(Today.getDafYomiBavli))

The date is easy as well:

Debug.WriteLine(Formatter.format(Yom))

Okay, now it is a new day, and i want to show the date, time, and possibly new parasha. Do i have to reset each of the objects, or is there a way to advance the day by one easily.

chacham2 avatar May 13 '21 17:05 chacham2

@chacham2 , See JewishDate.forward(int field, int amount). For the zmanim that are directly tied to the GregorianCalendar just maintain a calendar and roll it, and set the GregorianCalendar AstronomicalCalendar.setCalendar(Calendar calendar). Please let me know if this addresses your question.

KosherJava avatar May 14 '21 12:05 KosherJava

I'm trying to understand how to use that. Maybe i can form simpler questions to get it straight in my own head:

  1. If i instantiate ZmanimCalendar, it gives me zmanim for today. When it runs overnight and the computer clock changes, will the zmanim now be the next day, or do i need to reset it?

  2. I want to find the parasha of the week for use with formatParsha(). However, that requires an instantiation of JewishCalendar set to this week's Shabbos. Starting with ZmanimCalendar, how do i get a JewishCalendar for the coming Shabbos. (The Shabbos may be in the following month, so i assume adding days is required.) Do i need to maintain the date separately and keep it in sync?

  3. I want to display the day's daf. That requires formatDafYomiBavli() which requires JewishCalendar.getDafYomiBavli() which requires an instantiation of JewishCalendar. Similar to #2, starting with ZmanimCalendar, how do i get a JewishCalendar?

Or, am i approaching this entirely wrong?

chacham2 avatar May 14 '21 14:05 chacham2

If i instantiate ZmanimCalendar, it gives me zmanim for today. When it runs overnight and the computer clock changes, will the zmanim now be the next day, or do i need to reset it?

No. The class is not time aware and nothing will change.

I want to find the parasha of the week for use with formatParsha(). However, that requires an instantiation of JewishCalendar set to this week's Shabbos. Starting with ZmanimCalendar, how do i get a JewishCalendar for the coming Shabbos. (The Shabbos may be in the following month, so i assume adding days is required.) Do i need to maintain the date separately and keep it in sync?

Jump to the next Shabbos. If getParsha() returns a real parsha, good, if not, move forward 7 days and try again.

I want to display the day's daf. That requires formatDafYomiBavli() which requires JewishCalendar.getDafYomiBavli() which requires an instantiation of JewishCalendar. Similar to #2, starting with ZmanimCalendar, how do i get a JewishCalendar?

Use ZmanimCalendar.getCalendar().getCalendar() for a reference to the GregorianCalendar used by the ZmanimCalendar. Pass this to JewishCalendar.setDate​(Calendar calendar) to set it there. At that point you can just get the daf. Ultimately you want to manage the calendar in one place, and you may as well do it in the ZmanimCalendar by setting the GregorianCalendar there.

Please let me know if this addressed your questions.

KosherJava avatar May 14 '21 15:05 KosherJava

Sorry, for the basic questions. I'm trying to have it all click so i get what the best approach is.

No. The class is not time aware and nothing will change.

Thank you. That answers that question.

Jump to the next Shabbos. If getParsha() returns a real parsha, good, if not, move forward 7 days and try again.

Wouldn't that always return nothing? I think i'd need to add one day at a time and check. Though, 6- JewishCalendar.getDayOfWeek() ought to give me the right amount of days to add. My question is how to add them. One way would be to use JewishDate.forward(), and then JewishCalendar.setDate(JewishDate.getLocalDate()) or something. I'm not quite sure. Though, at that point it seems easier to just use the system date directly via JewishCalendar.setGregorianDate.

Ultimately you want to manage the calendar in one place, and you may as well do it in the ZmanimCalendar by setting the GregorianCalendar there.

This is so confusing. I just need four objects: ZmanimCalendar, JewishCalendar set to today and another set to the coming Shabbos, and JewishDate set to today. Maybe i can just reset when the day changes. That is, JewishDate.resetDate(), JewishCalendar.resetDate(), and Zemanim.setCalendar(JewishCalendar.getGregorianCalendar). For Shabbos, just maintain a local date in vb, and use JewishCalendar.setGregorianDate(year, month, date) as shown above. I feel like i'm reinventing the wheel though.


Do you want typos reported? While looking at the documentation i found:

https://github.com/KosherJava/zmanim/blob/master/src/main/java/com/kosherjava/zmanim/hebrewcalendar/JewishDate.java#L1331 one day t a time -> one day at a time

https://github.com/KosherJava/zmanim/blob/master/src/main/java/com/kosherjava/zmanim/ZmanimCalendar.java#L66 second edition published -> second edition, published

https://github.com/KosherJava/zmanim/blob/master/src/main/java/com/kosherjava/zmanim/ZmanimCalendar.java#L78 a degree based offset -> a degree-based offset (not sure about this one)

chacham2 avatar May 14 '21 16:05 chacham2

@chacham2, there is now a getUpcomingParsha(). See https://github.com/KosherJava/zmanim/commit/52e49 . Does this address your issue?

KosherJava avatar Nov 27 '22 04:11 KosherJava

Very likely does, thank you.

Fwiw, i am no longer working on the project though. After this, that, and the other, someone else took over the project and took another route. Regardless, this is a nice addition!

chacham2 avatar Nov 27 '22 10:11 chacham2