ucar.unidata.util
Class TimestampFormat

java.lang.Object
  extended by java.text.Format
      extended by ucar.unidata.util.TimestampFormat
All Implemented Interfaces:
Serializable, Cloneable

public class TimestampFormat
extends Format

TODO: serious synchronization issues

Version:
$Revision: 1.11 $ $Date: 2006/05/05 19:19:38 $
Author:
$Author: jeffmc $
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
Format.Field
 
Field Summary
static String isoTimeFmtPattern
          SimpleDateFormat pattern to describe ISO 8601 complete date plus hours, minutes, seconds and a decimal fraction of a second.
 
Constructor Summary
TimestampFormat()
          _more_
TimestampFormat(DateFormat delegate)
          _more_
TimestampFormat(DateFormat delegate, Calendar cal)
          _more_
 
Method Summary
static Timestamp computeTimestamp(String ddhhmm, Timestamp ref)
          Given a time string and a time reference, compute the time the string represents.
static int domOff(int dom, Calendar ref)
          Return the number of days to add() to ref DAY_OF_MONTH to get ref DAY_OF_MONTH = dom, such that the time in ref changes the least.
 StringBuffer format(Object ts, StringBuffer buf, FieldPosition pos)
          _more_
 StringBuffer format(Timestamp ts, StringBuffer buf, FieldPosition fp)
          Formats an Timestamp to produce a string.
 DateFormat getDelegate()
          _more_
static String isoformat(Timestamp ts)
          _more_
static StringBuffer isoformat(Timestamp ts, StringBuffer buf, FieldPosition fp)
          Formats an Timestamp to produce a string.
static void main(String[] args)
          _more_
 Timestamp parse(String source)
          _more_
 Timestamp parse(String source, ParsePosition status)
          Parses a string to produce a Timestamp.
 Object parseObject(String source, ParsePosition status)
          _more_
 void setDelegate(DateFormat delegate)
          _more_
static void tdomOff(String[] args)
          _more_
static void test0(String[] args)
          _more_
static void testHodOff(String[] args)
          _more_
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isoTimeFmtPattern

public static final String isoTimeFmtPattern
SimpleDateFormat pattern to describe ISO 8601 complete date plus hours, minutes, seconds and a decimal fraction of a second. http://www.w3.org/TR/NOTE-datetime

See Also:
SimpleDateFormat, Constant Field Values
Constructor Detail

TimestampFormat

public TimestampFormat()
_more_


TimestampFormat

public TimestampFormat(DateFormat delegate)
_more_

Parameters:
delegate -

TimestampFormat

public TimestampFormat(DateFormat delegate,
                       Calendar cal)
_more_

Parameters:
delegate -
cal -
Method Detail

isoformat

public static StringBuffer isoformat(Timestamp ts,
                                     StringBuffer buf,
                                     FieldPosition fp)
Formats an Timestamp to produce a string. ISO 8601 Complete date plus hours, minutes, seconds and a decimal fraction of a second. http://www.w3.org/TR/NOTE-datetime

Parameters:
ts - Timestamp to format
buf - StringBuffer where the text is to be appended
fp - On input: an alignment field, if desired. On output: the offsets of the alignment field.
Returns:
the value passed in as toAppendTo

isoformat

public static String isoformat(Timestamp ts)
_more_

Parameters:
ts -
Returns:
_more_

domOff

public static int domOff(int dom,
                         Calendar ref)
Return the number of days to add() to ref DAY_OF_MONTH to get ref DAY_OF_MONTH = dom, such that the time in ref changes the least. Ties favor earlier time. Assumes dom is in ref MONTH, the month prior, or the month after

Parameters:
dom - int day of month, 1-31
ref - Calendar containing the reference time. exclusive access to ref should be guaranteed by the caller.
Returns:
_more_

computeTimestamp

public static Timestamp computeTimestamp(String ddhhmm,
                                         Timestamp ref)
                                  throws ParseException
Given a time string and a time reference, compute the time the string represents. All times are UTC, Gregorian Calendar.

Parameters:
ddhhmm - String timestamp of the form [DD]HHMM where DD is 2 digits day of month (01-31) (may be missing) HH is 2 digits hour of day (00-23) MM is 2 digits minute of hour (00-59)
ref - Timestamp of some moment near to and generally after the time represented by ddhhmm
Returns:
Timestamp corresponding to ddhhmm.
Throws:
ParseException

setDelegate

public void setDelegate(DateFormat delegate)
_more_

Parameters:
delegate -

getDelegate

public DateFormat getDelegate()
_more_

Returns:
_more_

format

public StringBuffer format(Timestamp ts,
                           StringBuffer buf,
                           FieldPosition fp)
Formats an Timestamp to produce a string.

Parameters:
ts - Timestamp to format
buf - StringBuffer where the text is to be appended
fp - On input: an alignment field, if desired. On output: the offsets of the alignment field.
Returns:
the value passed in as toAppendTo

format

public StringBuffer format(Object ts,
                           StringBuffer buf,
                           FieldPosition pos)
_more_

Specified by:
format in class Format
Parameters:
ts -
buf -
pos -
Returns:
_more_

parse

public Timestamp parse(String source,
                       ParsePosition status)
Parses a string to produce a Timestamp.

Parameters:
source - String to parse
status - Input-Output parameter.

Before calling, set status.index to the offset you want to start parsing at in the source. After calling, status.index is the end of the text you parsed. If error occurs, index is unchanged.

When parsing, leading whitespace is discarded (with successful parse), while trailing whitespace is left as is.

Returns:
_more_

parse

public Timestamp parse(String source)
                throws ParseException
_more_

Parameters:
source -
Returns:
_more_
Throws:
ParseException

parseObject

public Object parseObject(String source,
                          ParsePosition status)
_more_

Specified by:
parseObject in class Format
Parameters:
source -
status -
Returns:
_more_

test0

public static void test0(String[] args)
_more_

Parameters:
args -

tdomOff

public static void tdomOff(String[] args)
_more_

Parameters:
args -

testHodOff

public static void testHodOff(String[] args)
_more_

Parameters:
args -

main

public static void main(String[] args)
_more_

Parameters:
args -