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

JS doesn't produce the same results as Java #8

Closed
shalomscott opened this issue Apr 11, 2020 · 3 comments
Closed

JS doesn't produce the same results as Java #8

shalomscott opened this issue Apr 11, 2020 · 3 comments
Labels

Comments

@shalomscott
Copy link
Contributor

I'd like to start off by saying that I am a huge fan of this port. In my opinion it's miles ahead of anything else out there for JS. Even though the README states this project is in alpha stage, I've found it to be quite complete and reliable.
With that out of the way, something I just realized is that the results of lib seem to be a few seconds off from what the Java library produces. To illustrate this:

I used the Zmanim Calendar Generator to generate zmanim for my location (Hashmonaim) and used this as a reference for the Java results.

zmanim-calendar-generator

Taking a look at candle lighting for 2020-04-10:
zmanim-excel

This matches up exactly with MyZmanim.com. I even compared several zmanim and different days. The largest discrepancy I found was 1 second (!). I'm pretty convinced MyZmanim uses the Java zmanim project.

However, when I try to produce the results in JS using this lib, I get results that are on average 5 seconds off:

const moment = require('moment');
const { ComplexZmanimCalendar, GeoLocation } = require('kosher-zmanim');

const cal = new ComplexZmanimCalendar(
	new GeoLocation('Hashmonaim', 31.93263, 35.02327, 255.18, 'Asia/Jerusalem')
);

cal.setMoment(moment('2020-04-10'));

console.log(cal.getCandleLighting()); // Fri Apr 10 2020 18:47:44 GMT+0300 (Israel Daylight Time)

Its just a couple seconds but they're crucial when minutes are rounded. I hope I'm missing something simple. Struck me as really strange especially because the source of this project is so similar to the Java. Makes me think that this might have to do with a loss of precision when handling big numbers in JS. Although, from a few quick greps I couldn't find any huge number literals.

@shalomscott
Copy link
Contributor Author

P.S. I'd love to get involved in solving this issue. I just first wanted to know if you were aware of it.

@BehindTheMath
Copy link
Owner

There were several bugs in the last version. Please try again with v0.6.0 and let me know if there is still an issue.

As far as we know, MyZmanim uses their own proprietary calculations, and does not use KosherJava or any of its ports. The author of KosherJava frequently gets complaints that his calculations are different than MyZmanim.

@shalomscott
Copy link
Contributor Author

Amazing! Both libraries now produce the exact same result, down to the millisecond!

I used the Java zmanim project directly this time so I could get an exact comparison. This is what I got from Java:

ComplexZmanimCalendar cal = new ComplexZmanimCalendar(
        new GeoLocation(
                "Hasmonaim",
                31.93263,
                35.02327,
                255.18,
                TimeZone.getTimeZone("Asia/Jerusalem"))
);

cal.getCalendar().set(2020, Calendar.APRIL, 10);

System.out.println(cal.getCandleLighting().getTime()); // 1586533670912 (Fri Apr 10 2020 18:47:50)

And the JS using the updated kosher-zmanim:

const { ComplexZmanimCalendar, GeoLocation } = require("kosher-zmanim");

const cal = new ComplexZmanimCalendar(
  new GeoLocation("Hashmonaim", 31.93263, 35.02327, 255.18, "Asia/Jerusalem")
);

cal.setDate("2020-04-10");

console.log(cal.getCandleLighting().toJSDate().getTime()); // 1586533670912 (Fri Apr 10 2020 18:47:50)

Awesome stuff 👍

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

No branches or pull requests

2 participants