Class Zman

java.lang.Object
com.kosherjava.zmanim.util.Zman

public class Zman extends Object
A wrapper class for a 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);
 ComplexZmanimCalendar czc = new ComplexZmanimCalendar(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-2023
TODO:
Add secondary sorting. As of now the Comparators in this class do not sort by secondary order. This means that when sorting a Collection of zmanim and using the DATE_ORDER Comparator will 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 Details

    • label

      private String label
      The name / label of the zman.
    • zman

      private Date zman
      The Date of the zman
    • duration

      private long duration
      The duration if the zman is a temporal hour (or the various shaah zmanis base times such as shaah Zmanis GRA or shaah Zmanis 16.1°).
    • description

      A longer description or explanation of a zman.
    • geoLocation

      The location information of the zman.
    • DATE_ORDER

      public static final Comparator<Zman> DATE_ORDER
      A Comparator that 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 the Zman is a null or getZman() returns a null.
    • NAME_ORDER

      public static final Comparator<Zman> NAME_ORDER
      A Comparator that 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 will sort cases where either the Zman is a null or label returns a null as empty Strings.
    • DURATION_ORDER

      public static final Comparator<Zman> DURATION_ORDER
      A Comparator that will compare and sort duration based zmanim such as temporal hour (or the various shaah zmanis times such as shaah zmanis GRA or shaah 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 will sort cases where Zman is a null.
  • Constructor Details

  • Method Details

    • getZman

      public Date getZman()
      Returns the Date based zman.
      Returns:
      the zman.
      See Also:
    • setZman

      public void setZman(Date date)
      Sets a Date based zman.
      Parameters:
      date - a Date based zman
      See Also:
    • getGeoLocation

      Returns the {link TimeZone} of the zman.
      Returns:
      the time zone
    • setGeoLocation

      public void setGeoLocation(GeoLocation geoLocation)
      Sets the GeoLocation of the zman.
      Parameters:
      geoLocation - the GeoLocation of the zman.
    • getDuration

      public long getDuration()
      Returns a duration based zman such as temporal hour (or the various shaah zmanis times such as shaah zmanis GRA or shaah zmanis 16.1°).
      Returns:
      the duration based zman.
      See Also:
    • setDuration

      public void setDuration(long duration)
      Sets a duration based zman such as temporal hour (or the various shaah zmanis times as shaah zmanis GRA or shaah zmanis 16.1°).
      Parameters:
      duration - duration based zman such as AstronomicalCalendar.getTemporalHour().
      See Also:
    • getLabel

      public String 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 using setLabel(String).
      Returns:
      the name/label of the zman.
      See Also:
    • setLabel

      public void setLabel(String label)
      Sets the the name / label of the zman such as "Sof Zman Krias Shema GRA".
      Parameters:
      label - the name / label to set for the zman.
      See Also:
    • getDescription

      Returns the longer description or explanation of a zman. There is no default value for this and it must be set using setDescription(String)
      Returns:
      the description or explanation of a zman.
      See Also:
    • setDescription

      public void setDescription(String description)
      Sets the longer description or explanation of a zman.
      Parameters:
      description - the zman description to set.
      See Also:
    • toXML

      public String toXML()
      A method that returns an XML formatted String representing the serialized Object. 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

      public String toString()
      Overrides:
      toString in class Object
      See Also: