Skip to content

Commit eb7e5ca

Browse files
authored
ZmanimFormatter - Deprecate getXSDateTime(Date date, Calendar calendar)
- Deprecate getXSDateTime(Date date, Calendar calendar) - Formatting will use the classes timezone. - Remove private unused formatDigits method - Update JavaDocs to avoid warnings on recent JDKs and other tweaks
1 parent b93eea3 commit eb7e5ca

File tree

1 file changed

+30
-36
lines changed

1 file changed

+30
-36
lines changed

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

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Zmanim Java API
3-
* Copyright (C) 2004-2022 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)
@@ -32,21 +32,23 @@
3232
* example the {@link com.kosherjava.zmanim.AstronomicalCalendar#getTemporalHour()} returns the length of the hour in
3333
* milliseconds. This class can format this time.
3434
*
35-
* @author © Eliyahu Hershfeld 2004 - 2022
35+
* @author © Eliyahu Hershfeld 2004 - 2025
3636
*/
3737
public class ZmanimFormatter {
3838
/**
39-
* Setting to prepent a zero to single digit hours.
39+
* Setting to prepend a zero to single digit hours.
4040
* @see #setSettings(boolean, boolean, boolean)
4141
*/
4242
private boolean prependZeroHours = false;
4343

4444
/**
45+
* Should seconds be used in formatting time.
4546
* @see #setSettings(boolean, boolean, boolean)
4647
*/
4748
private boolean useSeconds = false;
4849

4950
/**
51+
* Should milliseconds be used in formatting time.
5052
* @see #setSettings(boolean, boolean, boolean)
5153
*/
5254
private boolean useMillis = false;
@@ -67,25 +69,28 @@ public class ZmanimFormatter {
6769
private static DecimalFormat milliNF = new DecimalFormat("000");
6870

6971
/**
72+
* The SimpleDateFormat class.
7073
* @see #setDateFormat(SimpleDateFormat)
7174
*/
7275
private SimpleDateFormat dateFormat;
7376

7477
/**
78+
* The TimeZone class.
7579
* @see #setTimeZone(TimeZone)
7680
*/
77-
private TimeZone timeZone = null; // TimeZone.getTimeZone("UTC");
81+
private TimeZone timeZone = null;
7882

79-
// private DecimalFormat decimalNF;
8083

8184
/**
85+
* Method to return the TimeZone.
8286
* @return the timeZone
8387
*/
8488
public TimeZone getTimeZone() {
8589
return timeZone;
8690
}
8791

8892
/**
93+
* Method to set the TimeZone.
8994
* @param timeZone
9095
* the timeZone to set
9196
*/
@@ -132,17 +137,13 @@ public void setTimeZone(TimeZone timeZone) {
132137
public static final int XSD_DURATION_FORMAT = 5;
133138

134139
/**
135-
* constructor that defaults to this will use the format "h:mm:ss" for dates and 00.00.00.0 for {@link Time}.
140+
* Constructor that defaults to this will use the format "h:mm:ss" for dates and 00.00.00.0 for {@link Time}.
136141
* @param timeZone the TimeZone Object
137142
*/
138143
public ZmanimFormatter(TimeZone timeZone) {
139144
this(0, new SimpleDateFormat("h:mm:ss"), timeZone);
140145
}
141146

142-
// public ZmanimFormatter() {
143-
// this(0, new SimpleDateFormat("h:mm:ss"), TimeZone.getTimeZone("UTC"));
144-
// }
145-
146147
/**
147148
* ZmanimFormatter constructor using a formatter
148149
*
@@ -241,7 +242,7 @@ public String format(int millis) {
241242
}
242243

243244
/**
244-
* A method that formats {@link Time}objects.
245+
* A method that formats {@link Time} objects.
245246
*
246247
* @param time
247248
* The time <code>Object</code> to be formatted.
@@ -279,7 +280,7 @@ public String format(Time time) {
279280
public String formatDateTime(Date dateTime, Calendar calendar) {
280281
this.dateFormat.setCalendar(calendar);
281282
if (this.dateFormat.toPattern().equals("yyyy-MM-dd'T'HH:mm:ss")) {
282-
return getXSDateTime(dateTime, calendar);
283+
return getXSDateTime(dateTime);
283284
} else {
284285
return this.dateFormat.format(dateTime);
285286
}
@@ -296,33 +297,25 @@ public String formatDateTime(Date dateTime, Calendar calendar) {
296297
* href="http://www.iso.ch/markete/8601.pdf">[ISO 8601]</a> for details. The date/time string format must include a
297298
* time zone, either a Z to indicate Coordinated Universal Time or a + or - followed by the difference between the
298299
* difference from UTC represented as hh:mm.
299-
* @param dateTime the Date Object
300-
* @param calendar Calendar Object
300+
* @param date Date Object
301+
* @param calendar Calendar Object that is now ignored.
301302
* @return the XSD dateTime
303+
* @deprecated This method will be removed in v3.0
304+
*/
305+
@Deprecated (since="2.5", forRemoval=true)
306+
public String getXSDateTime(Date date, Calendar calendar) {
307+
return getXSDateTime(date);
308+
}
309+
310+
/**
311+
* Format the Date using the format "yyyy-MM-dd'T'HH:mm:ssXXX"
312+
* @param date the Date to format.
313+
* @return the Date formatted using the format "yyyy-MM-dd'T'HH:mm:ssXXX
302314
*/
303-
public String getXSDateTime(Date dateTime, Calendar calendar) {
304-
String xsdDateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss";
305-
/*
306-
* if (xmlDateFormat == null || xmlDateFormat.trim().equals("")) { xmlDateFormat = xsdDateTimeFormat; }
307-
*/
308-
SimpleDateFormat dateFormat = new SimpleDateFormat(xsdDateTimeFormat);
315+
public String getXSDateTime(Date date) {
316+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
309317
dateFormat.setTimeZone(getTimeZone());
310-
311-
StringBuilder sb = new StringBuilder(dateFormat.format(dateTime));
312-
// Must also include offset from UTF.
313-
int offset = calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET);// Get the offset (in milliseconds)
314-
// If there is no offset, we have "Coordinated Universal Time"
315-
if (offset == 0)
316-
sb.append("Z");
317-
else {
318-
// Convert milliseconds to hours and minutes
319-
int hrs = offset / (60 * 60 * 1000);
320-
// In a few cases, the time zone may be +/-hh:30.
321-
int min = offset % (60 * 60 * 1000);
322-
char posneg = hrs < 0 ? '-' : '+';
323-
sb.append(posneg + formatDigits(hrs) + ':' + formatDigits(min));
324-
}
325-
return sb.toString();
318+
return new StringBuilder(dateFormat.format(date)).toString();
326319
}
327320

328321
/**
@@ -450,6 +443,7 @@ public static String toXML(AstronomicalCalendar astronomicalCalendar) {
450443
sb.append(" timeZoneOffset=\"")
451444
.append((tz.getOffset(astronomicalCalendar.getCalendar().getTimeInMillis()) / ((double) HOUR_MILLIS)))
452445
.append("\"");
446+
// sb.append(" useElevationAllZmanim=\"").append(astronomicalCalendar.useElevationAllZmanim).append("\""); //TODO likely using reflection
453447

454448
sb.append(">\n");
455449

0 commit comments

Comments
 (0)