How to Use the Zmanim API
Created by KosherJava
First ensure that the Zmanim jar (download) is in your classpath
Import the package and create an instance of either the AstronomicalCalendar, ZmanimCalendar or ComplexZmanimCalendar.
String locationName = "Lakewood, NJ";
double latitude = 40.096; //Lakewood, NJ
double longitude = -74.222; //Lakewood, NJ
double elevation = 0; //optional elevation
TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
GeoLocation location = new GeoLocation(locationName, latitude, longitude, elevation, timeZone);
ComplexZmanimCalendar czc = new ComplexZmanimCalendar(location);
Note: The TimeZone has to be a valid timezone listed in the java.util.TimeZone.getAvailableIDs().
Note: For locations such as Israel where the beginning and end of dailight savings time can fluctuate from year to year, create a SimpleTimeZone with the known start and end of DST.
To generate zmanim, invoke:
Date sunrise = czc.getSunrise(); Date alos16 = czc.getAlos16point1Degrees();The date that zmanim are generated for are stored in the Calendar object within the ZmanimCalendar. By default it is the date that the ZmanimCalendar was created. It can easily be reset in many ways.
czc.getCalendar().set(1969, Calendar.FEBRUARY, 8);or
czc.setCalendar(new GregorianCalendar(1969, Calendar.FEBRUARY, 8));when generating zmanim for a range of dates, the date can be rolled forward
czc.getCalendar().roll(Calendar.DAY_OF_YEAR, 1);The real power of this API is the ease in calculating zmanim that are not part of the API. The mothods for doing zmanim calculations not present in the ComplexZmanimCalendar or it’s superclass the ZmanimCalendar are contained in the AstronomicalCalendar, the base class of the calendars in our API since they are generic methods for calculating time based on degrees or time before or after sunrise and sunset and are of interest for calculation beyond zmanim calculations. Here are some examples: To get alos calculated as 14º below the horizon (as calculated in the calendars published in Montreal) add AstronomicalCalendar.ASTRONOMICAL_ZENITH (90º) to the 14º offset (measurements are from the vertical, so sunrise and sunset are 90º below the vertical):
Date alos14 = czc.getSunriseOffsetByDegrees(AstronomicalCalendar.ASTRONOMICAL_ZENITH + 14);To get the time of mincha gedola calculated based on the MGA using a shaah zmanis based on the day starting 16.1º below the horizon (and ending 16.1º after sunset) the following calculation can be used:
Date minchaGedola = czc.getTimeOffset(czc.getAlos16point1Degrees(), czc.getShaahZmanis16Point1Degrees() * 6.5);A slightly more complex example would be calculating plag hamincha based on a shaah zmanis that is not present in this API. While a drop more complex it is still rather easy. For example if you wanted to calculate plag based on the day starting 12º before sunrise and ending 12º after sunset as calculated in the calendars in Manchester, England (there is nothing that would prevent your calculating the day using sunrise and sunset offsets that are not identical degrees, but this would lead to chatzos being a time other than the solar transit (solar midday)). The steps involved would be to first calculate the shaah zmanis and than use that time in milliseconds to calculate 10.75 hours after sunrise starting at 12º before sunset
long shaahZmanis = czc.getSolarHour(czc.getSunriseOffsetByDegrees(AstronomicalCalendar.ASTRONOMICAL_ZENITH + 12), czc.getSunriseOffsetByDegrees(AstronomicalCalendar.ASTRONOMICAL_ZENITH + 12)); Date plag = getTimeOffset(czc.getSunriseOffsetByDegrees(AstronomicalCalendar.ASTRONOMICAL_ZENITH + 12), shaahZmanis * 10.75);Below is a full example (from the FAQ: Where is the Zmanim API Main Method?) of a very simple zmanim program that outputs sunrise, sof zman krias shema and sunset for the current day in Lakewood, NJ. Please ensure that the Zmanim jar (download) is in your classpath.
/**
* This program is a simple demonstration of the kosherjava.com Zmanim API.
* To compile, ensure that the Zmanim Jar is in your classpath.
*/
import net.sourceforge.zmanim.*;
import net.sourceforge.zmanim.util.*;
import java.util.TimeZone;
public class SimpleZmanim{
public static void main(String [] args) {
String locationName = "Lakewood, NJ";
double latitude = 40.096; //latitude of Lakewood, NJ
double longitude = -74.222; //longitude of Lakewood, NJ
double elevation = 0; //optional elevation
//use a Valid Olson Database timezone listed in java.util.TimeZone.getAvailableIDs()
TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
//create the location object
GeoLocation location = new GeoLocation(locationName, latitude, longitude, elevation, timeZone);
//create the ZmanimCalendar
ZmanimCalendar zc = new ZmanimCalendar(location);
//optionally set the internal calendar
//zc.getCalendar().set(1969, Calendar.FEBRUARY, 8);
System.out.println("Today's Zmanim for " + locationName);
System.out.println("Sunrise: " + zc.getSunrise()); //output sunrise
System.out.println("Sof Zman Shema GRA: " + zc.getSofZmanShmaGRA()); //output Sof Zman Shema GRA
System.out.println("Sunset: " + zc.getSunset()); //output sunset
}
}
The following would compile and execute this code (sample from a DOS prompt in Windows).
C:\path\to\code>javac SimpleZmanim.java C:\path\to\code>java SimpleZmanim Today's Zmanim for Lakewood, NJ Sunrise: Thu Nov 05 06:30:27 EST 2009 Sof Zman Shema GRA: Thu Nov 05 09:05:21 EST 2009 Sunset: Thu Nov 05 16:50:02 EST 2009Please see the Zmanim API documentation for a more complete view of the API.
I was wondering if there’s a way to install the zmanim calculator on my Nokia 3100 (J2me equipped). i tried the .jar file but it won’t work. I’m totally naive about these things, but maybe you can help me out?
thanks
Andy,
At this point there is no way to use this on a J2ME device. For one, J2ME does not support floating point data types (double and float) that is used in the code. There are libraries for this, but it would not work without code changes. Secondly, there is no real front end for the API. the 2 sample output classes generate PDF and Excel documents with zmanim.
I was looking at the code for the zmanim API, and I found that by default, the software uses the SunTimesCalculator class for the implementation of the AstronomicalCalculator. I was wondering if you could comment on why you picked that implementation over the other two classed that are provided.
Thanks,
Yossie
Do you have this code in .net by any chance?
There is no .NET implementation yet. I do have a .NET dll that uses J# that was created by AdminJew, but it is not very easy to use since it requires the use of Java within .NET. One complicating factor in porting to .NET is that .NET does not easily support switching timezones. The code should be easy to port otherwise.
Is there a way to incorporate this by using an httprequest from an asp page. Like an xml page, where I would send the variables and get a response with the correct candle lighting time?
thanks
Is there a zmanim Java applet available? I would like something that I can place on my desktop as an Active Desktop item. Such things are available for candlelighting times (for example, see http://www.torahtots.com/timecapsule/cities/philadelphia.htm), but I have not found anything for zmanim, and I don’t have the applet programming skills to make it myself.
Thanks,
Michael
Jack,
you seem to be requesting a REST style Web Service. This is very simple using the Zmanim API, since the toString method returns an XML representation of the calendar including any zmanim that you might need. All you need is a Java Servlet that would return data from the API.
Michael,
At the suggestion of Dr. Irv Bromberg I started the process of modifying a visual clock that shows zmanim. It is very rough at this point, but can be seen at the alpha quality Zmanim Clock page. There are many clocks cluttering this test page, all using slightly different configurations. Clicking on the clock will bring up an actual list of zmanim. I will see if I can find time to update the code.
A more up to date zmanim clock is now available. It is of pre-alpha quality.
shalom
i would like to get the PHP lignes to obtain a block with shabbat parcha and zmanim candles for paris france
i want them please !!! READY to copy and past because i am not prgrammer
see my website http://www.rungiscacher.com
kol tuv
Mordekhai,
Moishe Beshkin (see his KosherDev blog) wrote the WordPress Zmanim Widget plugin that does what you are looking for. Since your site does not appear to be a WordPress site, I suggest that you contact him to see if there is a way his code can be used in a non-WordPress PHP page.
[...] to make me something different. Then thanks go to Eliyohu Hershfeld, which developed a wonderfull Java API for detecting zmanim Also I found very good code, which converts current date to Jewish one, by Zvi [...]
Is there a way to calculate times based on minutes, something like getTimeOffsetByMinutes(int minute);
Anonymous,
The base class of the Calendar classes in the Zmanim API, the AstronomicalCalendar has a method getTimeOffset(Date time, double offset) that does exactly what you are looking for. The API uses it internally to calculate times such as the 72 minute zman. Please see the Elevation Now Only Impacts Sunrise and Sunset Calculations in the Zmanim API post to understand why sea level sunrise and sunset should be used. The example below shows how to calculate alos as 72 minute before sunrise, and tzais as 72 minutes after sunset.
String locationName = "Lakewood, NJ"; double latitude = 40.096; //Lakewood, NJ double longitude = -74.222; //Lakewood, NJ double elevation = 0; //optional elevation TimeZone timeZone = TimeZone.getTimeZone("America/New_York"); GeoLocation location = new GeoLocation(locationName, latitude, longitude, elevation, timeZone); //Use any of the API's Calendar classes //AstronomicalCalendar zCal = new ComplexZmanimCalendar(location); //ZmanimCalendar zCal = new ComplexZmanimCalendar(location); ComplexZmanimCalendar zCal = new ComplexZmanimCalendar(location); //Return the time 72 minutes before sunrise Date alos = zCal.getTimeOffset(getSeaLevelSunrise(), -72 * MINUTE_MILLIS); //Return the time 72 minutes after sunset Date tzais = zCal.getTimeOffset(getSeaLevelSunset(), 72 * MINUTE_MILLIS);