Skip to content

Commit c4ce23b

Browse files
authored
Zman.java allow storing a GeoLocation, JavaDoc tweaks for new JDKs
1 parent 85f2989 commit c4ce23b

File tree

1 file changed

+51
-9
lines changed
  • src/main/java/com/kosherjava/zmanim/util

1 file changed

+51
-9
lines changed

src/main/java/com/kosherjava/zmanim/util/Zman.java

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Zmanim Java API
3-
* Copyright (C) 2004-2024 Eliyahu Hershfeld
3+
* Copyright (C) 2004-2025 Eliyahu Hershfeld
44
*
55
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
66
* Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
@@ -55,7 +55,7 @@
5555
* // will sort shaah 1.6, shaah GRA, sunrise, sunset
5656
* </pre>
5757
*
58-
* @author &copy; Eliyahu Hershfeld 2007-2024
58+
* @author &copy; Eliyahu Hershfeld 2007-2025
5959
* @todo Add secondary sorting. As of now the {@code Comparator}s in this class do not sort by secondary order. This means that when sorting a
6060
* {@link java.util.Collection} of <em>zmanim</em> and using the {@link #DATE_ORDER} {@code Comparator} will have the duration based <em>zmanim</em>
6161
* at the end, but they will not be sorted by duration. This should be N/A for label based sorting.
@@ -82,16 +82,34 @@ public class Zman {
8282
* A longer description or explanation of a <em>zman</em>.
8383
*/
8484
private String description;
85+
86+
/**
87+
* The location information of the <em>zman</em>.
88+
*/
89+
private GeoLocation geoLocation;
8590

8691
/**
87-
* The constructor setting a {@link Date} based <em>zman</em> and a label.
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.
8894
* @param date the Date of the <em>zman</em>.
8995
* @param label the label of the <em>zman</em> such as "<em>Sof Zman Krias Shema GRA</em>".
90-
* @see #Zman(long, String)
96+
* @see #Zman(Date, GeoLocation, String)
9197
*/
9298
public Zman(Date date, String label) {
93-
this.label = label;
99+
this(date, null, label);
100+
}
101+
102+
/**
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>.
106+
* @param geoLocation the {@link GeoLocation} of the <em>zman</em>.
107+
* @param label the label of the <em>zman</em> such as "<em>Sof Zman Krias Shema GRA</em>".
108+
*/
109+
public Zman(Date date, GeoLocation geoLocation, String label) {
94110
this.zman = date;
111+
this.geoLocation = geoLocation;
112+
this.label = label;
95113
}
96114

97115
/**
@@ -125,6 +143,22 @@ public Date getZman() {
125143
public void setZman(Date date) {
126144
this.zman = date;
127145
}
146+
147+
/**
148+
* Returns the {link TimeZone} of the <em>zman</em>.
149+
* @return the time zone
150+
*/
151+
public GeoLocation getGeoLocation() {
152+
return geoLocation;
153+
}
154+
155+
/**
156+
* Sets the {@code GeoLocation} of the <em>zman</em>.
157+
* @param geoLocation the {@code GeoLocation} of the <em>zman</em>.
158+
*/
159+
public void setGeoLocation(GeoLocation geoLocation) {
160+
this.geoLocation = geoLocation;
161+
}
128162

129163
/**
130164
* Returns a duration based <em>zman</em> such as {@link com.kosherjava.zmanim.AstronomicalCalendar#getTemporalHour() temporal hour}
@@ -241,6 +275,12 @@ public int compare(Zman zman1, Zman zman2) {
241275
* &lt;Zman&gt;
242276
* &lt;Label&gt;Sof Zman Krias Shema GRA&lt;/Label&gt;
243277
* &lt;Zman&gt;1969-02-08T09:37:56.820&lt;/Zman&gt;
278+
* &lt;TimeZone&gt;
279+
* &lt;TimezoneName&gt;America/Montreal&lt;/TimezoneName&gt;
280+
* &lt;TimeZoneDisplayName&gt;Eastern Standard Time&lt;/TimeZoneDisplayName&gt;
281+
* &lt;TimezoneGMTOffset&gt;-5&lt;/TimezoneGMTOffset&gt;
282+
* &lt;TimezoneDSTOffset&gt;1&lt;/TimezoneDSTOffset&gt;
283+
* &lt;/TimeZone&gt;
244284
* &lt;Duration&gt;0&lt;/Duration&gt;
245285
* &lt;Description&gt;Sof Zman Krias Shema GRA is 3 sha'os zmaniyos calculated from sunrise to sunset.&lt;/Description&gt;
246286
* &lt;/Zman&gt;
@@ -253,6 +293,7 @@ public String toXML() {
253293
sb.append("<Zman>\n");
254294
sb.append("\t<Label>").append(getLabel()).append("</Label>\n");
255295
sb.append("\t<Zman>").append(getZman() == null ? "": formatter.format(getZman())).append("</Zman>\n");
296+
sb.append("\t" + getGeoLocation().toXML().replaceAll("\n", "\n\t"));
256297
sb.append("\n\t<Duration>").append(getDuration()).append("</Duration>\n");
257298
sb.append("\t<Description>").append(getDescription()).append("</Description>\n");
258299
sb.append("</Zman>");
@@ -264,10 +305,11 @@ public String toXML() {
264305
*/
265306
public String toString() {
266307
StringBuilder sb = new StringBuilder();
267-
sb.append("\nLabel:\t\t\t").append(this.getLabel());
268-
sb.append("\nZman:\t\t\t").append(getZman());
269-
sb.append("\nDuration:\t\t\t").append(getDuration());
270-
sb.append("\nDescription:\t\t\t").append(getDescription());
308+
sb.append("\nLabel:\t").append(this.getLabel());
309+
sb.append("\nZman:\t").append(getZman());
310+
sb.append("\nGeoLocation:\t").append(getGeoLocation().toString().replaceAll("\n", "\n\t"));
311+
sb.append("\nDuration:\t").append(getDuration());
312+
sb.append("\nDescription:\t").append(getDescription());
271313
return sb.toString();
272314
}
273315
}

0 commit comments

Comments
 (0)