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

Wrong ( I think ) sof Zman kisush levanah due to how java clanendar works with dayligh savings time boundry #178

Closed
elazarrosenthal opened this issue Nov 21, 2021 · 5 comments

Comments

@elazarrosenthal
Copy link

I noticed the wrong time on an app I have whne comparing to another calendar

I put together this test

I think the java Calendar date math does not properly handle the Daylight savings time shift

Any Sugestions


package com.kosherjava.zmanim;

import com.kosherjava.zmanim.hebrewcalendar.JewishCalendar;

import java.util.Date;
import java.util.TimeZone;

public class TestMain {
static void printinfo(Date d) {

    JewishCalendar jc = new JewishCalendar(d);

    System.out.println(d);
    System.out.println(jc.getMolad());

    System.out.println(jc.getMoladAsDate());
    System.out.println(jc.getTchilasZmanKidushLevana3Days());
    System.out.println(jc.getTchilasZmanKidushLevana7Days());
    System.out.println(jc.getSofZmanKidushLevanaBetweenMoldos());
    System.out.println(jc.getSofZmanKidushLevana15Days());

}

public static void main(String[] args) {


    Date d = new Date();
    printinfo(d);
    System.out.println("=====================================");
    TimeZone.setDefault(TimeZone.getTimeZone("EST"));
    printinfo(d);


}

}

output
Sun Nov 21 18:49:34 EST 2021 <<<<<<<<<<<<<< note date run moled was before DST
1 Kislev, 5782
Thu Nov 04 18:34:46 EDT 2021
Sun Nov 07 17:34:46 EST 2021
Thu Nov 11 17:34:46 EST 2021
Fri Nov 19 12:56:48 EST 2021 <<<<<<<<<<<<< this 12 should be 11
Fri Nov 19 18:34:46 EST 2021

Sun Nov 21 18:49:34 EST 2021
1 Kislev, 5782
Thu Nov 04 17:34:46 EST 2021
Sun Nov 07 17:34:46 EST 2021
Thu Nov 11 17:34:46 EST 2021
Fri Nov 19 11:56:48 EST 2021 <<<<<<<<<<<<<<<<<< correct but does not match
Fri Nov 19 17:34:46 EST 2021

@elazarrosenthal
Copy link
Author

this seems to fix

public Date getSofZmanKidushLevanaBetweenMoldos() {
	Date molad = getMoladAsDate();
	Calendar cal = Calendar.getInstance();
	cal.setTime(molad);
	// add half the time between molad and molad (half of 29 days, 12 hours and 793 chalakim (44 minutes, 3.3
	// seconds), or 14 days, 18 hours, 22 minutes and 666 milliseconds)

// cal.add(Calendar.DAY_OF_MONTH, 14);
// cal.add(Calendar.HOUR_OF_DAY, 18);
cal.add(Calendar.HOUR, 24*14+18);
cal.add(Calendar.MINUTE, 22);
cal.add(Calendar.SECOND, 1);
cal.add(Calendar.MILLISECOND, 666);
return cal.getTime();
}

@KosherJava
Copy link
Owner

@elazarrosenthal , Thank you for the report. I will have a look at the issue later this week. In the meantime you can use the ComplexZmanimCalendar.getSofZmanKidushLevanaBetweenMoldos() method that seems to return the correct time. This is used in both the Excel Zmanim Calendar and the Zmanim Map. As seen in the documentation, there is an intentional use of Standard Time. However, the forward looking calculation for the molad time done in the HebrewCalendar class is for the next molad, and at the bug seems to lie in the fact that the calculation is done when DST is still in effect and the molad time is after the transition back to standard time. The code used in the ComplexZmanimCalendar class calculates it for the current date set in the calendar, and therefore bypasses this issue.
Your suggested patch may be correct, but I will spend some time trying to determine the optimal fix.

@elazarrosenthal
Copy link
Author

elazarrosenthal commented Nov 22, 2021 via email

@elazarrosenthal
Copy link
Author

I think the ComplexZmanimCalendar.getSofZmanKidushLevanaBetweenMoldos() has the same bug
and it also requires having tghe date on or close to the date
the JewishCalendar version will return the data for any day in the month

I sent you a screen shot of my app
the kidush levanah stuff was mainly intnded as a test for my self thats why the output is not as clean as the rest
the email also inclueded a pic of a RAbbi Premok calendar which made me aware of the problems I had

@KosherJava
Copy link
Owner

Thank you very much @elazarrosenthal for pointing out this issue. It is now fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants