1
1
/*
2
2
* Zmanim Java API
3
- * Copyright (C) 2004-2022 Eliyahu Hershfeld
3
+ * Copyright (C) 2004-2025 Eliyahu Hershfeld
4
4
*
5
5
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
6
6
* Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
32
32
* example the {@link com.kosherjava.zmanim.AstronomicalCalendar#getTemporalHour()} returns the length of the hour in
33
33
* milliseconds. This class can format this time.
34
34
*
35
- * @author © Eliyahu Hershfeld 2004 - 2022
35
+ * @author © Eliyahu Hershfeld 2004 - 2025
36
36
*/
37
37
public class ZmanimFormatter {
38
38
/**
39
- * Setting to prepent a zero to single digit hours.
39
+ * Setting to prepend a zero to single digit hours.
40
40
* @see #setSettings(boolean, boolean, boolean)
41
41
*/
42
42
private boolean prependZeroHours = false ;
43
43
44
44
/**
45
+ * Should seconds be used in formatting time.
45
46
* @see #setSettings(boolean, boolean, boolean)
46
47
*/
47
48
private boolean useSeconds = false ;
48
49
49
50
/**
51
+ * Should milliseconds be used in formatting time.
50
52
* @see #setSettings(boolean, boolean, boolean)
51
53
*/
52
54
private boolean useMillis = false ;
@@ -67,25 +69,28 @@ public class ZmanimFormatter {
67
69
private static DecimalFormat milliNF = new DecimalFormat ("000" );
68
70
69
71
/**
72
+ * The SimpleDateFormat class.
70
73
* @see #setDateFormat(SimpleDateFormat)
71
74
*/
72
75
private SimpleDateFormat dateFormat ;
73
76
74
77
/**
78
+ * The TimeZone class.
75
79
* @see #setTimeZone(TimeZone)
76
80
*/
77
- private TimeZone timeZone = null ; // TimeZone.getTimeZone("UTC");
81
+ private TimeZone timeZone = null ;
78
82
79
- // private DecimalFormat decimalNF;
80
83
81
84
/**
85
+ * Method to return the TimeZone.
82
86
* @return the timeZone
83
87
*/
84
88
public TimeZone getTimeZone () {
85
89
return timeZone ;
86
90
}
87
91
88
92
/**
93
+ * Method to set the TimeZone.
89
94
* @param timeZone
90
95
* the timeZone to set
91
96
*/
@@ -132,17 +137,13 @@ public void setTimeZone(TimeZone timeZone) {
132
137
public static final int XSD_DURATION_FORMAT = 5 ;
133
138
134
139
/**
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}.
136
141
* @param timeZone the TimeZone Object
137
142
*/
138
143
public ZmanimFormatter (TimeZone timeZone ) {
139
144
this (0 , new SimpleDateFormat ("h:mm:ss" ), timeZone );
140
145
}
141
146
142
- // public ZmanimFormatter() {
143
- // this(0, new SimpleDateFormat("h:mm:ss"), TimeZone.getTimeZone("UTC"));
144
- // }
145
-
146
147
/**
147
148
* ZmanimFormatter constructor using a formatter
148
149
*
@@ -241,7 +242,7 @@ public String format(int millis) {
241
242
}
242
243
243
244
/**
244
- * A method that formats {@link Time}objects.
245
+ * A method that formats {@link Time} objects.
245
246
*
246
247
* @param time
247
248
* The time <code>Object</code> to be formatted.
@@ -279,7 +280,7 @@ public String format(Time time) {
279
280
public String formatDateTime (Date dateTime , Calendar calendar ) {
280
281
this .dateFormat .setCalendar (calendar );
281
282
if (this .dateFormat .toPattern ().equals ("yyyy-MM-dd'T'HH:mm:ss" )) {
282
- return getXSDateTime (dateTime , calendar );
283
+ return getXSDateTime (dateTime );
283
284
} else {
284
285
return this .dateFormat .format (dateTime );
285
286
}
@@ -296,33 +297,25 @@ public String formatDateTime(Date dateTime, Calendar calendar) {
296
297
* href="http://www.iso.ch/markete/8601.pdf">[ISO 8601]</a> for details. The date/time string format must include a
297
298
* time zone, either a Z to indicate Coordinated Universal Time or a + or - followed by the difference between the
298
299
* 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.
301
302
* @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
302
314
*/
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" );
309
317
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 ();
326
319
}
327
320
328
321
/**
@@ -450,6 +443,7 @@ public static String toXML(AstronomicalCalendar astronomicalCalendar) {
450
443
sb .append (" timeZoneOffset=\" " )
451
444
.append ((tz .getOffset (astronomicalCalendar .getCalendar ().getTimeInMillis ()) / ((double ) HOUR_MILLIS )))
452
445
.append ("\" " );
446
+ // sb.append(" useElevationAllZmanim=\"").append(astronomicalCalendar.useElevationAllZmanim).append("\""); //TODO likely using reflection
453
447
454
448
sb .append (">\n " );
455
449
0 commit comments