Class ZmanimFormatter
java.lang.Object
com.kosherjava.zmanim.util.ZmanimFormatter
A class used to format both
Instant times generated by the Zmanim package as well as Duration used for temporal
hours / sha'os zmaniyos. For example the AstronomicalCalendar.getTemporalHour() returns the
length of the hour as a Duration.- Author:
- © Eliyahu Hershfeld 2004 - 2026
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DateTimeFormatterTheDateTimeFormatterclass used by the formatter.private DecimalFormatthe formatter for hours.private static final DecimalFormatthe formatter for minutes as milliseconds.private static final DecimalFormatthe formatter for minutes as seconds.private booleanSetting to prepend a zero to single digit hours.static final intFormat using hours and minutes.static final intFormat using hours, minutes, seconds and milliseconds.static final intFormat using hours, minutes and seconds.static final intFormat using hours, minutes, seconds and milliseconds using the xsd:time format.private intSet by the constructor; defaults toSEXAGESIMAL_SECONDS_FORMATwhen using the single-argument constructor.private booleanShould milliseconds be used in formatting time.private booleanShould seconds be used in formatting time.static final intFormat using the XSD Duration format.private ZoneIdThe TimeZone class. -
Constructor Summary
ConstructorsConstructorDescriptionZmanimFormatter(int timeFormat, DateTimeFormatter dateTimeFormatter, ZoneId zoneId) ZmanimFormatter constructor using various formatting options.ZmanimFormatter(ZoneId zoneId) -
Method Summary
Modifier and TypeMethodDescriptionA method that formats aDurationinto aStringformat of "00:00", "00:00:00" or "00:00:00.000" depending on the settings of the formatter.formatInstant(Instant instant, ZoneId zoneId) Formats anInstantusing this class'sgetDateTimeFormatter().formatXSDateTime(Instant instant) Format theInstantusing the format "yyyy-MM-dd'T'HH:mm:ssXXX".formatXSDDurationTime(Duration duration) This returns the xml representation of an xsd:duration object.returns theDateTimeFormatterObject.Method to return theZoneId.private static booleanincludeMethod(Method method) Determines if a method should be output by thetoXML(AstronomicalCalendar)voidsetDateTimeFormatter(DateTimeFormatter dateTimeFormatter) Sets theDateTimeFormatterObject.private voidsetSettings(boolean prependZeroHours, boolean useSeconds, boolean useMillis) Sets various format settings.voidsetTimeFormat(int format) Sets the time format to use for formattingDurations.voidMethod to set theZoneId.static StringtoJSON(AstronomicalCalendar astronomicalCalendar) A method that returns a JSON formattedStringrepresenting the serializedObject.static StringtoXML(AstronomicalCalendar astronomicalCalendar) A method that returns an XML formattedStringrepresenting the serializedObject.
-
Field Details
-
prependZeroHours
-
useSeconds
-
useMillis
-
minuteSecondNF
the formatter for minutes as seconds. -
hourNF
the formatter for hours. -
milliNF
the formatter for minutes as milliseconds. -
dateTimeFormatter
TheDateTimeFormatterclass used by the formatter.- See Also:
-
zoneId
-
SEXAGESIMAL_XSD_FORMAT
Format using hours, minutes, seconds and milliseconds using the xsd:time format. This format will return00.00.00.0when formatting 0.- See Also:
-
timeFormat
Set by the constructor; defaults toSEXAGESIMAL_SECONDS_FORMATwhen using the single-argument constructor.- See Also:
-
SEXAGESIMAL_FORMAT
-
SEXAGESIMAL_SECONDS_FORMAT
Format using hours, minutes and seconds.- See Also:
-
SEXAGESIMAL_MILLIS_FORMAT
Format using hours, minutes, seconds and milliseconds.- See Also:
-
XSD_DURATION_FORMAT
Format using the XSD Duration format. This is in the format of PT1H6M7.869S (P for period (duration), T for time, H, M and S indicate hours, minutes and seconds.- See Also:
-
-
Constructor Details
-
ZmanimFormatter
- Parameters:
zoneId- theZoneIdObject.
-
ZmanimFormatter
ZmanimFormatter constructor using various formatting options.- Parameters:
timeFormat- The formatting style to use forDurationused to represent shaos zmaniyos. The formatting will be as follows.SEXAGESIMAL_SECONDS_FORMAT(the default) - Will format an hour and a half as "1:30:00", and half an hour as "0:30:00".SEXAGESIMAL_XSD_FORMAT- Will format an hour and a half as "01:30:00.000", and half an hour as "00:30:00.000".SEXAGESIMAL_MILLIS_FORMAT- Will format an hour and a half as "1:30:00.000", and half an hour as "0:30:00.000".SEXAGESIMAL_FORMATwill format an hour and a half as "1:30", and half an hour as "0:30".XSD_DURATION_FORMATwill format the time as : "PT1H30M", and half an hour as "PT30M".
dateTimeFormatter- theDateTimeFormatterObject.zoneId- theZoneIdObject.
-
-
Method Details
-
getZoneId
-
setZoneId
-
setTimeFormat
Sets the time format to use for formattingDurations.- Parameters:
format- the format constant to use. SeeZmanimFormatter(int, DateTimeFormatter, ZoneId)for documentation on the formats.
-
setDateTimeFormatter
Sets theDateTimeFormatterObject.- Parameters:
dateTimeFormatter- theDateTimeFormatterObjectto set.
-
getDateTimeFormatter
returns theDateTimeFormatterObject.- Returns:
- the
DateTimeFormatterObject.
-
setSettings
Sets various format settings.- Parameters:
prependZeroHours- if to prepend a zero for single digit hours (so that 1 o'clock is displayed as 01).useSeconds- should seconds be used in the time format.useMillis- should milliseconds be used in formatting time.
-
format
A method that formats aDurationinto aStringformat of "00:00", "00:00:00" or "00:00:00.000" depending on the settings of the formatter. See the documentation onZmanimFormatter(int, DateTimeFormatter, ZoneId)for details.- Parameters:
duration- TheDurationto format.- Returns:
- String The formatted
String.
-
formatInstant
Formats anInstantusing this class'sgetDateTimeFormatter().- Parameters:
instant- theInstantto format.zoneId- theZoneIdused to help format based on theInstant's DST and other settings.- Returns:
- the formatted String
- See Also:
-
formatXSDateTime
Format theInstantusing the format "yyyy-MM-dd'T'HH:mm:ssXXX".- Parameters:
instant- theInstantto format.- Returns:
- the
Instantformatted using the format "yyyy-MM-dd'T'HH:mm:ssXXX".
-
formatXSDDurationTime
This returns the xml representation of an xsd:duration object. This simply usesDuration.toString()that formats it in the standard XSD ISO-8601 (e.g., "PT1H30M")- Parameters:
duration- the duration to format- Returns:
- the xsd:duration ISO-8601 formatted String
-
toXML
A method that returns an XML formattedStringrepresenting the serializedObject. The format used is:If a zman does not occur, the value "N/A" will be returned. Note that the output uses the xsd:dateTime format for times such as sunrise, and xsd:duration format for times that are a duration such as the length of a<AstronomicalTimes date="1969-02-08" type="com.kosherjava.zmanim.AstronomicalCalendar" algorithm="US Naval Almanac Algorithm" location="Montreal, Quebec" latitude="45.497" longitude="-73.63" elevation="85.0" timeZoneName="Eastern Standard Time" timeZoneID="America/New_York" timeZoneOffset="-5"> <SeaLevelSunset>1969-02-08T17:11:26-05:00</SeaLevelSunset> <TemporalHour>PT50M23.259S</TemporalHour> ... </AstronomicalTimes>temporal hour. The output of this method is returned by thetoString.- Parameters:
astronomicalCalendar- the AstronomicalCalendar Object- Returns:
- The XML
Stringformatted as described above. - TODO:
- Add proper schema, and support for nulls. XSD duration (for solar hours), should probably return nil and not P.
-
toJSON
A method that returns a JSON formattedStringrepresenting the serializedObject. The format used is:Note that the output uses the xsd:dateTime format for times such as sunrise, and xsd:duration format for times that are a duration such as the length of a{ "metadata":{ "date":"1969-02-08", "type":"com.kosherjava.zmanim.AstronomicalCalendar", "algorithm":"US Naval Almanac Algorithm", "location":"Montreal, Quebec", "latitude":"45.497", "longitude":"-73.63", "elevation":"85.0", "timeZoneName":"Eastern Standard Time", "timeZoneID":"America/New_York", "timeZoneOffset":"-5"}, "AstronomicalTimes":{ "SeaLevelSunset":"1969-02-08T17:11:26-05:00", "TemporalHour":"PT50M23.259S" ... } }temporal hour. If a zman does not occur, the value "N/A" will be returned.- Parameters:
astronomicalCalendar- the AstronomicalCalendar Object- Returns:
- The JSON
Stringformatted as described above.
-
includeMethod
Determines if a method should be output by thetoXML(AstronomicalCalendar)- Parameters:
method- the method in question- Returns:
- if the method should be included in serialization
-