1515 */
1616package com .kosherjava .zmanim .util ;
1717
18- import java .text .SimpleDateFormat ;
18+ import java .time .Instant ;
19+ import java .time .format .DateTimeFormatter ;
1920import java .util .Comparator ;
20- import java .util .Date ;
2121
2222/**
2323 * A wrapper class for astronomical times / <em>zmanim</em> that is mostly intended to allow sorting collections of astronomical times.
3636 * TimeZone timeZone = TimeZone.getTimeZone("America/New_York");
3737 * GeoLocation location = new GeoLocation(locationName, latitude, longitude, elevation, timeZone);
3838 * ComprehensiveZmanimCalendar czc = new ComprehensiveZmanimCalendar(location);
39- * Zman sunset = new Zman(czc.getSunset(), "Sunset");
39+ * Zman sunset = new Zman(czc.getSunset(), "Sunset");
4040 * Zman shaah16 = new Zman(czc.getShaahZmanis16Point1Degrees(), "Shaah zmanis 16.1");
4141 * Zman sunrise = new Zman(czc.getSunrise(), "Sunrise");
4242 * Zman shaah = new Zman(czc.getShaahZmanisGra(), "Shaah zmanis GRA");
@@ -67,9 +67,9 @@ public class Zman {
6767 private String label ;
6868
6969 /**
70- * The {@link Date } of the <em>zman</em>
70+ * The {@link Instant } of the <em>zman</em>
7171 */
72- private Date zman ;
72+ private Instant zman ;
7373
7474 /**
7575 * The duration if the <em>zman</em> is a {@link com.kosherjava.zmanim.AstronomicalCalendar#getTemporalHour() temporal hour} (or the various
@@ -87,27 +87,27 @@ public class Zman {
8787 * The location information of the <em>zman</em>.
8888 */
8989 private GeoLocation geoLocation ;
90-
90+
9191 /**
92- * The constructor setting a {@link Date } based <em>zman</em> and a label. In most cases you will likely want to call
93- * {@link #Zman(Date , GeoLocation, String)} that also sets the location.
94- * @param date the Date of the <em>zman</em>.
95- * @param label the label of the <em>zman</em> such as "<em>Sof Zman Krias Shema GRA</em>".
96- * @see #Zman(Date , GeoLocation, String)
92+ * The constructor setting a {@link Instant } based <em>zman</em> and a label. In most cases you will likely want to call
93+ * {@link #Zman(Instant , GeoLocation, String)} that also sets the location.
94+ * @param instant the <code>Instant</code> of the <em>zman</em>.
95+ * @param label the label of the <em>zman</em> such as "<em>Sof Zman Krias Shema GRA</em>".
96+ * @see #Zman(Instant , GeoLocation, String)
9797 */
98- public Zman (Date date , String label ) {
99- this (date , null , label );
98+ public Zman (Instant instant , String label ) {
99+ this (instant , null , label );
100100 }
101101
102102 /**
103- * The constructor setting a {@link Date } based <em>zman</em> and a label. In most cases you will likely want to call
104- * {@link #Zman(Date , GeoLocation, String)} that also sets the geo location.
105- * @param date the Date of the <em>zman</em>.
103+ * The constructor setting a {@link Instant } based <em>zman</em> and a label. In most cases you will likely want to call
104+ * {@link #Zman(Instant , GeoLocation, String)} that also sets the geo location.
105+ * @param instant the <code>Instant</code> of the <em>zman</em>.
106106 * @param geoLocation the {@link GeoLocation} of the <em>zman</em>.
107107 * @param label the label of the <em>zman</em> such as "<em>Sof Zman Krias Shema GRA</em>".
108108 */
109- public Zman (Date date , GeoLocation geoLocation , String label ) {
110- this .zman = date ;
109+ public Zman (Instant instant , GeoLocation geoLocation , String label ) {
110+ this .zman = instant ;
111111 this .geoLocation = geoLocation ;
112112 this .label = label ;
113113 }
@@ -119,29 +119,29 @@ public Zman(Date date, GeoLocation geoLocation, String label) {
119119 * {@link com.kosherjava.zmanim.ComprehensiveZmanimCalendar#getShaahZmanis16Point1Degrees() <em>shaah Zmanis 16.1°</em>}) and label.
120120 * @param duration a duration based <em>zman</em> such as ({@link com.kosherjava.zmanim.AstronomicalCalendar#getTemporalHour()}
121121 * @param label the label of the <em>zman</em> such as "<em>Shaah Zmanis GRA</em>".
122- * @see #Zman(Date , String)
122+ * @see #Zman(Instant , String)
123123 */
124124 public Zman (long duration , String label ) {
125125 this .label = label ;
126126 this .duration = duration ;
127127 }
128128
129129 /**
130- * Returns the {@code Date } based <em>zman</em>.
131- * @return the <em>zman</em>.
132- * @see #setZman(Date )
130+ * Returns the {@code Instant } based <em>zman</em>.
131+ * @return the <code>Instant</code> of the < em>zman</em>.
132+ * @see #setZman(Instant )
133133 */
134- public Date getZman () {
134+ public Instant getZman () {
135135 return this .zman ;
136136 }
137137
138138 /**
139- * Sets a {@code Date } based <em>zman</em>.
140- * @param date a {@code Date } based <em>zman</em>
139+ * Sets a {@code Instant } based <em>zman</em>.
140+ * @param instant an {@code Instant } based <em>zman</em>
141141 * @see #getZman()
142142 */
143- public void setZman (Date date ) {
144- this .zman = date ;
143+ public void setZman (Instant instant ) {
144+ this .zman = instant ;
145145 }
146146
147147 /**
@@ -229,8 +229,8 @@ public void setDescription(String description) {
229229 */
230230 public static final Comparator <Zman > DATE_ORDER = new Comparator <Zman >() {
231231 public int compare (Zman zman1 , Zman zman2 ) {
232- long firstTime = (zman1 == null || zman1 .getZman () == null ) ? Long .MAX_VALUE : zman1 .getZman ().getTime ();
233- long secondTime = (zman2 == null || zman2 .getZman () == null ) ? Long .MAX_VALUE : zman2 .getZman ().getTime ();
232+ long firstTime = (zman1 == null || zman1 .getZman () == null ) ? Long .MAX_VALUE : zman1 .getZman ().toEpochMilli ();
233+ long secondTime = (zman2 == null || zman2 .getZman () == null ) ? Long .MAX_VALUE : zman2 .getZman ().toEpochMilli ();
234234 return Long .valueOf (firstTime ).compareTo (Long .valueOf (secondTime ));
235235 }
236236 };
@@ -288,7 +288,7 @@ public int compare(Zman zman1, Zman zman2) {
288288 * @return The XML formatted <code>String</code>.
289289 */
290290 public String toXML () {
291- SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSS" );
291+ DateTimeFormatter formatter = DateTimeFormatter . ofPattern ("yyyy-MM-dd'T'HH:mm:ss.SSS" );
292292 StringBuilder sb = new StringBuilder ();
293293 sb .append ("<Zman>\n " );
294294 sb .append ("\t <Label>" ).append (getLabel ()).append ("</Label>\n " );
0 commit comments