Class Zman
java.lang.Object
com.kosherjava.zmanim.util.Zman
A wrapper class for astronomical times / zmanim that is mostly intended to allow sorting collections of astronomical times.
It has fields for both date/time and duration based zmanim, name / labels as well as a longer description or explanation of a
zman.
Here is an example of various ways of sorting zmanim.
First create the Calendar for the location you would like to calculate:
String locationName = "Lakewood, NJ";
double latitude = 40.0828; // Lakewood, NJ
double longitude = -74.2094; // Lakewood, NJ
double elevation = 20; // optional elevation correction in Meters
// the String parameter in getTimeZone() has to be a valid timezone listed in TimeZone.getAvailableIDs()
TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
GeoLocation location = new GeoLocation(locationName, latitude, longitude, elevation, timeZone);
ComprehensiveZmanimCalendar czc = new ComprehensiveZmanimCalendar(location);
Zman sunset = new Zman(czc.getSunset(), "Sunset");
Zman shaah16 = new Zman(czc.getShaahZmanis16Point1Degrees(), "Shaah zmanis 16.1");
Zman sunrise = new Zman(czc.getSunrise(), "Sunrise");
Zman shaah = new Zman(czc.getShaahZmanisGra(), "Shaah zmanis GRA");
ArrayList<Zman> zl = new ArrayList<Zman>();
zl.add(sunset);
zl.add(shaah16);
zl.add(sunrise);
zl.add(shaah);
//will sort sunset, shaah 1.6, sunrise, shaah GRA
System.out.println(zl);
Collections.sort(zl, Zman.DATE_ORDER);
// will sort sunrise, sunset, shaah, shaah 1.6 (the last 2 are not in any specific order)
Collections.sort(zl, Zman.DURATION_ORDER);
// will sort sunrise, sunset (the first 2 are not in any specific order), shaah GRA, shaah 1.6
Collections.sort(zl, Zman.NAME_ORDER);
// will sort shaah 1.6, shaah GRA, sunrise, sunset
- Author:
- © Eliyahu Hershfeld 2007-2026
- TODO:
- Add secondary sorting. As of now the
Comparators in this class do not sort by secondary order. This means that when sorting aCollectionof zmanim and using theDATE_ORDERComparatorwill have the duration based zmanim at the end, but they will not be sorted by duration. This should be N/A for label based sorting.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<Zman> AComparatorthat will compare and sort zmanim by date/time order.private StringA longer description or explanation of a zman.private longThe duration if the zman is atemporal hour(or the various shaah zmanis base times such asshaah Zmanis GRAorshaah Zmanis 16.1°).static final Comparator<Zman> AComparatorthat will compare and sort duration based zmanim such astemporal hour(or the various shaah zmanis times such asshaah zmanis GRAorshaah zmanis 16.1°).private GeoLocationThe location information of the zman.private StringThe name / label of the zman.static final Comparator<Zman> AComparatorthat will compare and sort zmanim by zmanim label order.private InstantTheInstantof the zman -
Constructor Summary
ConstructorsConstructorDescriptionThe constructor setting a duration based zman such astemporal hour(or the various shaah zmanis times such asshaah zmanis GRAorshaah Zmanis 16.1°) and label.Zman(Instant instant, GeoLocation geoLocation, String label) The constructor setting aInstantbased zman and a label.The constructor setting aInstantbased zman and a label. -
Method Summary
Modifier and TypeMethodDescriptionReturns the longer description or explanation of a zman.longReturns a duration based zman such astemporal hour(or the various shaah zmanis times such asshaah zmanis GRAorshaah zmanis 16.1°).Returns the {link TimeZone} of the zman.getLabel()Returns the name / label of the zman such as "Sof Zman Krias Shema GRA".getZman()Returns theInstantbased zman.voidsetDescription(String description) Sets the longer description or explanation of a zman.voidsetDuration(long duration) Sets a duration based zman such astemporal hour(or the various shaah zmanis times asshaah zmanis GRAorshaah zmanis 16.1°).voidsetGeoLocation(GeoLocation geoLocation) Sets theGeoLocationof the zman.voidSets the name / label of the zman such as "Sof Zman Krias Shema GRA".voidSets aInstantbased zman.toString()toXML()A method that returns an XML formattedStringrepresenting the serializedObject.
-
Field Details
-
label
-
zman
-
duration
The duration if the zman is atemporal hour(or the various shaah zmanis base times such asshaah Zmanis GRAorshaah Zmanis 16.1°). -
description
A longer description or explanation of a zman. -
geoLocation
The location information of the zman. -
DATE_ORDER
AComparatorthat will compare and sort zmanim by date/time order. Compares its two arguments by the zman's date/time order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Please note that this class will handle cases where either theZmanis a null orgetZman()returns a null. -
NAME_ORDER
AComparatorthat will compare and sort zmanim by zmanim label order. Compares its two arguments by the zmanim label name order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Please note that this class will sort cases where either theZmanis a null orlabelreturns a null as emptyStrings. -
DURATION_ORDER
AComparatorthat will compare and sort duration based zmanim such astemporal hour(or the various shaah zmanis times such asshaah zmanis GRAorshaah zmanis 16.1°). Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. Please note that this class will sort cases whereZmanis a null.
-
-
Constructor Details
-
Zman
The constructor setting aInstantbased zman and a label. In most cases you will likely want to callZman(Instant, GeoLocation, String)that also sets the location.- Parameters:
instant- theInstantof the zman.label- the label of the zman such as "Sof Zman Krias Shema GRA".- See Also:
-
Zman
The constructor setting aInstantbased zman and a label. In most cases you will likely want to callZman(Instant, GeoLocation, String)that also sets the geo location.- Parameters:
instant- theInstantof the zman.geoLocation- theGeoLocationof the zman.label- the label of the zman such as "Sof Zman Krias Shema GRA".
-
Zman
The constructor setting a duration based zman such astemporal hour(or the various shaah zmanis times such asshaah zmanis GRAorshaah Zmanis 16.1°) and label.- Parameters:
duration- a duration based zman such as (AstronomicalCalendar.getTemporalHour()label- the label of the zman such as "Shaah Zmanis GRA".- See Also:
-
-
Method Details
-
getZman
-
setZman
-
getGeoLocation
-
setGeoLocation
Sets theGeoLocationof the zman.- Parameters:
geoLocation- theGeoLocationof the zman.
-
getDuration
Returns a duration based zman such astemporal hour(or the various shaah zmanis times such asshaah zmanis GRAorshaah zmanis 16.1°).- Returns:
- the duration based zman.
- See Also:
-
setDuration
Sets a duration based zman such astemporal hour(or the various shaah zmanis times asshaah zmanis GRAorshaah zmanis 16.1°).- Parameters:
duration- duration based zman such asAstronomicalCalendar.getTemporalHour().- See Also:
-
getLabel
Returns the name / label of the zman such as "Sof Zman Krias Shema GRA". There are no automatically set labels and you must set them usingsetLabel(String).- Returns:
- the name/label of the zman.
- See Also:
-
setLabel
-
getDescription
Returns the longer description or explanation of a zman. There is no default value for this and it must be set usingsetDescription(String)- Returns:
- the description or explanation of a zman.
- See Also:
-
setDescription
Sets the longer description or explanation of a zman.- Parameters:
description- the zman description to set.- See Also:
-
toXML
A method that returns an XML formattedStringrepresenting the serializedObject. Very similar to the toString method but the return value is in an xml format. The format currently used (subject to change) is:<Zman> <Label>Sof Zman Krias Shema GRA</Label> <Zman>1969-02-08T09:37:56.820</Zman> <TimeZone> <TimezoneName>America/Montreal</TimezoneName> <TimeZoneDisplayName>Eastern Standard Time</TimeZoneDisplayName> <TimezoneGMTOffset>-5</TimezoneGMTOffset> <TimezoneDSTOffset>1</TimezoneDSTOffset> </TimeZone> <Duration>0</Duration> <Description>Sof Zman Krias Shema GRA is 3 sha'os zmaniyos calculated from sunrise to sunset.</Description> </Zman>- Returns:
- The XML formatted
String.
-
toString
-