The release of the iPhone 3G got me thinking about zmanim on the iPhone. While I would eventually like to create a free native iPhonezmanim app, for now I created a simple iPhone web app to test out the UI. While only of alpha quality, the iZmanim web app (no longer available) should work properly on an iPhone (tested in Safari on Windows and iPhone emulators). There is a settings page that persists changes made. The iZmanim web app was built using the iUI framework. iZmanim can be tested with any WebKit browser. For the full effect, try it using the iPhone Tester on Safari. Please note that it will not properly load in IE or Firefox.
If any Cocoa/Objective-C/iPhone developers would like to give a hand in developing the native iZmanim, please contact me.
Note: This post is about an old beta release. The current version of the KosherJava Zmanim API is available on GitHub and from the Zmanim Download page.
The second beta release of the Zmanim API 1.1 is now available on the download page. Changes in this release include additional code refactoring, building on the refactoring done in the last few releases. As in the previous release, included is the zmanimAstronomical-1.1_beta_2.jar, a release that only includes the AstronomicalCalendar class and supporting classes. As part of the changes, an effort was put in to make the code simpler to port to other languages. This mostly involved moving formatting code out of the main classes. The only interface changes were the addition of a few new methods to the GeoLocation class. It is likely that the next release will remove the empty GeoLocation constructor that can lead to inadvertent errors. This removal might break existing code. I hope to post details about these changes in the near future.
I was recently contacted by Jan Terje Johansen, a developer at Datek Wireless AS in Norway, with an interesting bug report. Datek uses the Zmanim API (the AstronomicalCalendar base class) to allow their clients (the power company and stadiums) to remotely (via a web interface) control streetlights and stadium lights throughout Norway using a wireless lighting control system that they developed. The zmanim code is used to allow setting the lighting times based on an offset of sunrise/sunset. For the technically curious, they are controlled primarily through GPRS, with SMS as fallback. A version under development uses ZigBee. The bug encountered was that for Tromsoe (Tromsø), Norway, as well as other areas within the Arctic Circle that experience the midnight sun, from May 13 to May 17 (the date of last rise of the season in Tromsoe), the Zmanim API produced correct sunrise/sunset times, but the date component was a day off (the API returned all times as Java Dates at the time; version 3.0 of the API moved to the java.time API of the JSR-310 Date and Time API introduced in Java 8). For non-automated systems, the date component is not important, but in their case it would cause the lights to go on/off on the wrong day. Jan provided a suggested patch that worked well. The actual fix I used was slightly different because I took advantage of the time spent on fixing the bug to refactor and simplify the code. This change as well as a few other changes are part of the Zmanim 1.1 beta release that will likely be released as a final release in a few days. Jan mentioned that:
“IMHO your API is easily the best and most accurate Open Source sunset/sunrise API out there”. He continued: “Officially (according to the Norwegian Meteorology Institute), the midnight sunset/sunrise is from May 20 to July 22 in Tromsoe, ie. the complete sun is above the horizon 24 hours. Parts of sun is visible 24 hours a day in Tromsoe from May 18th to July 25th. This is the same as in your calculations.” … “I have tested your calculations against other official midnight sunrise/sunset (part of sun) dates in Northern-Norway (North Cape, Hammerfest, Longyearbyen (78,049762N -15,458252E [sic; Longyearbyen is at about 78.22, 15.65])) and they are spot on.”
In response to my question regarding his testing of the NOAACalculator versus the USNO-based SunTimesCalculator, he had an interesting and very practical answer:
“We prefer to use USNO calculator as it is more in tune with the sunrise/sunset times printed in most newspapers. You see, our experience is that most users don’t look at the sun to determine sunrise/sunset but read the times in the newspaper. If our times don’t correspond to the printed ones, something is wrong with our system in their mind.”
Note: This post is about an old release candidate. The RC1 files are no longer available; the links below point to the final 1.1 release (see the Zmanim API 1.1 Released post). The current version of the KosherJava Zmanim API is available on GitHub and from the Zmanim Download page.
A release candidate (RC1) of the Zmanim API 1.1 is now available on the download page. Changes in this release include a slight cleanup of the recently releasedNOAACalculator code (it does not change calculated times), as well as fixes to the date (but not time) of calculations for locations near the Arctic Circle. This date fix builds on the February release of the API to fix an Arctic Circle issue and a similar issue encountered when trying to generate zmanim for locations outside the local time zone. Also included in this release is the zmanimAstronomical-1.1.jar, a release that only includes the AstronomicalCalendar class and supporting classes. There was also some code refactoring to make the code easier to maintain. A detailed post will follow (hopefully within the next week or so).
The Zmanim API was developed from the ground up as an API which allows for easy plugging in of different algorithms. The Zmanim API ships with three “Calculator” implementations. Two calculators implement the US Naval Observatory’s algorithm, the SunTimesCalculator and the ZmanimCalculator (no longer available). Both produce identical zmanim using slightly different code and are included for comparison. There is also the JSuntimeCalculator (no longer available – see the information on the NOAACalculator below), an implementation of the NOAA algorithm by Jonathan Stott. I was recently contacted by Eliezer Bulka, who wanted to know why sunrise/sunset times generated by the NOAA algorithm were about 2 minutes off from the sunrise/sunset times generated by the NOAA JavaScript implementation that is the source of the JSuntimeCalculator. Comparing apples to apples required modifying the NOAA JavaScript to allow entry of decimal latitude/longitude and changing the output to display seconds. No change was made to the algorithm itself. I then ported the JavaScript directly to Java. This involved nothing more than slight syntax changes between the languages. Once this was done, I noticed that the sunrise/sunset output from the Java port exactly matched the output of the NOAA JavaScript. Analysis of Jonathan’s code showed (or at least my interpretation of it did) that there were two areas that caused the difference. One is that he used a slightly different method of computing the Julian date, a key part of the algorithm. His change includes the time of day as part of the calculation. The net result of this change is that solar time generated using his algorithm varies based on the time of day the calculation is run, something that is incorrect. This means that there can be a discrepancy of up to one calendar day. If the user calculated sunrise at 11:59 PM, sunrise would be calculated for the following day even if the user attempted to calculate it for today. In addition, the other calculations do not match the output of the matching NOAA code. I have deprecated the JSuntimeCalculator and in its place added the NOAACalculator that was the result of the direct port of the NOAA code, shoehorned into the Zmanim API Calculator interface. I ran some tests to compare the maximum and minimum discrepancy between the two implementations, and calculations for Lakewood, NJ (latitude 40.0828, longitude -74.2094) show a discrepancy of between 1 minute 34 seconds and 1 minute 37 seconds for sunrise and sunset across an entire year of calculations. I also compared the USNO algorithm to the new NOAA implementation and ended up with a maximum deviation of less than 30 seconds, where they had previously been about 1.5 minutes apart. While I do believe that the Julian date calculation is a bug, I do not know that this is the case for the rest of the calculation, but it is clear that it does not match the NOAA implementation that it was based on, and I recommend that you download the latest version that has the new NOAACalculator that fixes this issue. In addition to this fix, an additional patch will be released later this week that will address issues with calculations within the Arctic Circle. Stay tuned for the next post.