KosherJava Zmanim Homepage

net.sourceforge.zmanim.util
Class ZmanimFormatter

java.lang.Object
  extended by net.sourceforge.zmanim.util.ZmanimFormatter

public class ZmanimFormatter
extends Object

A class used to format non Date times generated by the Zmanim package. For example the AstronomicalCalendar.getTemporalHour() returns the length of the hour in milliseconds. This class can format this time.

Version:
0.9.0
Author:
© Eliyahu Hershfeld 2004 - 2007

Field Summary
static int DECIMAL_FORMAT
          Format using standard decimal format with 5 positions after the decimal.
(package private) static long HOUR_MILLIS
          constant for milliseconds in an hour (3,600,000)
(package private) static long MINUTE_MILLIS
          constant for milliseconds in a minute (60,000)
static int SEXAGESIMAL_FORMAT
          Format using hours and minutes.
static int SEXAGESIMAL_MILLIS_FORMAT
          Format using hours, minutes, seconds and milliseconds.
static int SEXAGESIMAL_SECONDS_FORMAT
          Format using hours, minutes and seconds.
static int SEXAGESIMAL_XSD_FORMAT
          Format using hours, minutes, seconds and milliseconds using the xsd:time format.
(package private)  boolean useDecimal
           
static int XSD_DURATION_FORMAT
          Format using the XSD Duration format.
 
Constructor Summary
ZmanimFormatter()
           
ZmanimFormatter(int format, SimpleDateFormat dateFormat)
          ZmanimFormatter constructor using a formatter
 
Method Summary
 String format(double milliseconds)
          A method that formats milliseconds into a time format.
 String format(int millis)
          A method that formats milliseconds into a time format.
 String format(Time time)
          A method that formats Timeobjects.
 String formatDateTime(Date dateTime, Calendar calendar)
          Formats a date using this classe's date format.
 String formatXSDDurationTime(long millis)
          This returns the xml representation of an xsd:duration object.
 String formatXSDDurationTime(Time time)
          This returns the xml representation of an xsd:duration object.
 SimpleDateFormat getDateFormat()
           
 String getXSDateTime(Date dateTime, Calendar cal)
          The date:date-time function returns the current date and time as a date/time string.
 void setDateFormat(SimpleDateFormat sdf)
           
 void setTimeFormat(int format)
          Sets the format to use for formatting.
static String toXML(AstronomicalCalendar ac)
          A method that returns an XML formatted String representing the serialized Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

useDecimal

boolean useDecimal

SEXAGESIMAL_XSD_FORMAT

public static final int SEXAGESIMAL_XSD_FORMAT
Format using hours, minutes, seconds and milliseconds using the xsd:time format. This format will return 00.00.00.0 when formatting 0.

See Also:
Constant Field Values

DECIMAL_FORMAT

public static final int DECIMAL_FORMAT
Format using standard decimal format with 5 positions after the decimal.

See Also:
Constant Field Values

SEXAGESIMAL_FORMAT

public static final int SEXAGESIMAL_FORMAT
Format using hours and minutes.

See Also:
Constant Field Values

SEXAGESIMAL_SECONDS_FORMAT

public static final int SEXAGESIMAL_SECONDS_FORMAT
Format using hours, minutes and seconds.

See Also:
Constant Field Values

SEXAGESIMAL_MILLIS_FORMAT

public static final int SEXAGESIMAL_MILLIS_FORMAT
Format using hours, minutes, seconds and milliseconds.

See Also:
Constant Field Values

MINUTE_MILLIS

static final long MINUTE_MILLIS
constant for milliseconds in a minute (60,000)

See Also:
Constant Field Values

HOUR_MILLIS

static final long HOUR_MILLIS
constant for milliseconds in an hour (3,600,000)

See Also:
Constant Field Values

XSD_DURATION_FORMAT

public static final int 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:
Constant Field Values
Constructor Detail

ZmanimFormatter

public ZmanimFormatter()

ZmanimFormatter

public ZmanimFormatter(int format,
                       SimpleDateFormat dateFormat)
ZmanimFormatter constructor using a formatter

Parameters:
format - int The formatting style to use. Using ZmanimFormatter.SEXAGESIMAL_SECONDS_FORMAT will format the time time of 90*60*1000 + 1 as 1:30:00
Method Detail

setTimeFormat

public void setTimeFormat(int format)
Sets the format to use for formatting.

Parameters:
format - int the format constant to use.

setDateFormat

public void setDateFormat(SimpleDateFormat sdf)

getDateFormat

public SimpleDateFormat getDateFormat()

format

public String format(double milliseconds)
A method that formats milliseconds into a time format.

Parameters:
milliseconds - The time in milliseconds.
Returns:
String The formatted String

format

public String format(int millis)
A method that formats milliseconds into a time format.

Parameters:
millis - The time in milliseconds.
Returns:
String The formatted String

format

public String format(Time time)
A method that formats Timeobjects.

Parameters:
time - The time Object to be formatted.
Returns:
String The formatted String

formatDateTime

public String formatDateTime(Date dateTime,
                             Calendar calendar)
Formats a date using this classe's date format.

Parameters:
dateTime - the date to format
calendar - the Calendar used to help format based on the Calendar's DST and other settings.
Returns:
the formatted String

getXSDateTime

public String getXSDateTime(Date dateTime,
                            Calendar cal)
The date:date-time function returns the current date and time as a date/time string. The date/time string that's returned must be a string in the format defined as the lexical representation of xs:dateTime in [3.3.8 dateTime] of [XML Schema 1.1 Part 2: Datatypes]. The date/time format is basically CCYY-MM-DDThh:mm:ss, although implementers should consult [XML Schema 1.1 Part 2: Datatypes] and [ISO 8601] for details. The date/time string format must include a time zone, either a Z to indicate Coordinated Universal Time or a + or - followed by the difference between the difference from UTC represented as hh:mm.


formatXSDDurationTime

public String formatXSDDurationTime(long millis)
This returns the xml representation of an xsd:duration object.

Parameters:
millis - the duration in milliseconds
Returns:
the xsd:duration formatted String

formatXSDDurationTime

public String formatXSDDurationTime(Time time)
This returns the xml representation of an xsd:duration object.

Parameters:
time - the duration as a Time object
Returns:
the xsd:duration formatted String

toXML

public static String toXML(AstronomicalCalendar ac)
A method that returns an XML formatted String representing the serialized Object. The format used is:
  <AstronomicalTimes date="1969-02-08" type="net.sourceforge.zmanim.AstronomicalCalendar algorithm="US Naval Almanac Algorithm" location="Lakewood, NJ" latitude="40.095965" longitude="-74.22213" elevation="31.0" timeZoneName="Eastern Standard Time" timeZoneID="America/New_York" timeZoneOffset="-5">
     <Sunrise>2007-02-18T06:45:27-05:00</Sunrise>
     <TemporalHour>PT54M17.529S</TemporalHour>
     ...
   </AstronomicalTimes>
 
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 temporal hour. The output of this method is returned by the toString }.

Returns:
The XML formatted String. The format will be:
  <AstronomicalTimes date="1969-02-08" type="net.sourceforge.zmanim.AstronomicalCalendar algorithm="US Naval Almanac Algorithm" location="Lakewood, NJ" latitude="40.095965" longitude="-74.22213" elevation="31.0" timeZoneName="Eastern Standard Time" timeZoneID="America/New_York" timeZoneOffset="-5">
     <Sunrise>2007-02-18T06:45:27-05:00</Sunrise>
     <TemporalHour>PT54M17.529S</TemporalHour>
     ...
  </AstronomicalTimes>
 

KosherJava Zmanim Homepage

Copyright © 2004 - 2009 Eliyahu Hershfeld. All Rights Reserved. Released under the GPL 2 license