org.griphyn.common.util
Class Currently

java.lang.Object
  extended by org.griphyn.common.util.Currently

public class Currently
extends Object

Create a common interface to handle obtaining string timestamps. The difficult part is to allow for an ISO 8601 date formatting.

Version:
$Revision: 50 $
Author:
Jens-S. V??ckler, Yong Zhao
See Also:
Date, SimpleDateFormat

Field Summary
private static String[] c_expression
          Store the regular expressions necessary to parse ISO timestamps.
private static Pattern[] c_pattern
          Stores compiled patterns at first use, quasi-Singleton.
static String DEFAULT_FORMAT
          Default time format, which is compact and has a timezone
private  SimpleDateFormat m_formatter
          This is used to format the time stamp.
 
Constructor Summary
Currently()
          Default ctor: Create a new instance with a default formatting string for timestamps.
Currently(SimpleDateFormat format)
          Ctor: Create a new instance with a formatting string for time stamps.
Currently(String formatString)
          Ctor: Create a new instance with a formatting string for time stamps.
 
Method Summary
 SimpleDateFormat getDateFormat()
          Accessor: Obtains the default timestamp format for all queues.
static String iso8601(boolean zuluTime)
          Ignores any internal date format, and tries to show a complete date/timp stamp of the current time in extended ISO 8601 format.
static String iso8601(boolean zuluTime, boolean extendedFormat, boolean withMillis, Date now)
          Ignores any internal date format, and tries to show a complete date/timp stamp in extended ISO 8601 format.
 String now()
          Obtains the current time as formatted string according to the format option.
 String now(Date then)
          Obtains the current time as formatted string according to the format option.
static Date parse(String stamp)
          Parses one of the ISO 8601 that it produces.
 void setDateFormat(SimpleDateFormat format)
          Accessor: Sets the default timestamp format for all queues.
 void setDateFormat(String format)
          Accessor: Sets the default timestamp format for all queues.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_formatter

private SimpleDateFormat m_formatter
This is used to format the time stamp.


DEFAULT_FORMAT

public static final String DEFAULT_FORMAT
Default time format, which is compact and has a timezone

See Also:
Constant Field Values

c_expression

private static final String[] c_expression
Store the regular expressions necessary to parse ISO timestamps.


c_pattern

private static Pattern[] c_pattern
Stores compiled patterns at first use, quasi-Singleton.

Constructor Detail

Currently

public Currently()
Default ctor: Create a new instance with a default formatting string for timestamps.


Currently

public Currently(String formatString)
Ctor: Create a new instance with a formatting string for time stamps.

Parameters:
formatString - complies to SimpleDateFormat.

Currently

public Currently(SimpleDateFormat format)
Ctor: Create a new instance with a formatting string for time stamps.

Parameters:
format - is a description of the simple date format to use.
Method Detail

getDateFormat

public SimpleDateFormat getDateFormat()
Accessor: Obtains the default timestamp format for all queues.

Returns:
the currently active timestamp prefix format.
See Also:
setDateFormat( String ), setDateFormat( SimpleDateFormat )

setDateFormat

public void setDateFormat(SimpleDateFormat format)
Accessor: Sets the default timestamp format for all queues.

Parameters:
format - is the new timestamp prefix format.
See Also:
setDateFormat( SimpleDateFormat ), getDateFormat()

setDateFormat

public void setDateFormat(String format)
Accessor: Sets the default timestamp format for all queues.

Parameters:
format - is the new timestamp prefix format as a string.
See Also:
setDateFormat( String ), getDateFormat()

now

public String now()
Obtains the current time as formatted string according to the format option.

Returns:
the current time as formatted string.
See Also:
now( Date )

now

public String now(Date then)
Obtains the current time as formatted string according to the format option.

Parameters:
then - is a timestamp expressed as Date.
Returns:
the current time as formatted string.
See Also:
now()

parse

public static Date parse(String stamp)
Parses one of the ISO 8601 that it produces. Note, it will not parse the full range of ISO timestamps.

Parameters:
stamp - is the textual timestamp representation.
Returns:
a time or null, if unparsable.

iso8601

public static String iso8601(boolean zuluTime)
Ignores any internal date format, and tries to show a complete date/timp stamp of the current time in extended ISO 8601 format. UTC time (Zulu time) or a local timezone will be used. A sample for UTC output is 2002-04-23T02:49:58Z A sample for local zone (CDT) is 2002-04-22T21:49:58-05:00

Parameters:
zuluTime - returns a UTC formatted stamp, if true. Otherwise the time will be formatted according to the local zone.
Returns:
an ISO 8601 formatted date and time representation for the current time in extended format without millisecond resolution
See Also:
iso8601( boolean, boolean, boolean, Date )

iso8601

public static String iso8601(boolean zuluTime,
                             boolean extendedFormat,
                             boolean withMillis,
                             Date now)
Ignores any internal date format, and tries to show a complete date/timp stamp in extended ISO 8601 format. UTC time (Zulu time) or a local timezone will be used.

zoneformatfractionexample
localbasicintegral20020523T140427-0500
UTCbasicintegral20020523190427Z
localextd.integral2002-05-23T14:04:27-05:00
UTCextd.integral2002-05-23T19:04:27Z
localbasicmillis20020523T140427.166-0500
UTCbasicmillis20020523190427.166Z
localextd.millis2002-05-23T14:04:27.166-05:00
UTCextd.millis2002-05-23T19:04:27.166Z

Parameters:
zuluTime - returns a UTC formatted stamp, if true. Otherwise the time will be formatted according to the local zone. Local time should be prefixed with the 'T'.
extendedFormat - will use the extended ISO 8601 format which separates the different timestamp items. If false, the basic format will be used. In UTC and basic format, the 'T' separator will be omitted.
withMillis - will put the millisecond extension into the timestamp. If false, the time will be without millisecond fraction. The separator is taken from DecimalFormatSymbols.getMinusSign(), which usually is a period or a comma.
now - is a time stamp as Date.
Returns:
an ISO 8601 formatted date and time representation for the given point in time.


Copyright © 2007 The University of Southern California. All Rights Reserved.