org.das2.util
Class TimeParser

java.lang.Object
  extended by org.das2.util.TimeParser

public class TimeParser
extends java.lang.Object

TimeParser designed to quickly parse strings with a specified format. This parser has been shown to perform around 20 times faster than that the generalized parser.


Nested Class Summary
static interface TimeParser.FieldHandler
           
 
Field Summary
static java.lang.String TIMEFORMAT_Z
          %Y-%m-%dT%H:%M:%S.%{milli}Z
 
Method Summary
static TimeParser create(java.lang.String formatString)
           %[fieldLength]<1-char code> or %[fieldLength]{} fieldLength=0 --> makes field length indeterminate, deliminator must follow.
static TimeParser create(java.lang.String formatString, java.lang.String fieldName, TimeParser.FieldHandler handler)
          This version allows for extension by specifying an external handler.
 java.lang.String format(Datum start, Datum end)
          format the range into a string.
 double getEndTime(Units units)
           
 java.lang.String getRegex()
           
 double getTime(Units units)
           
 Datum getTimeDatum()
           
 DatumRange getTimeRange()
          Returns the implicit interval as a DatumRange.
static java.lang.String iso8601String(java.lang.String exampleTime)
          must contain T or space to delimit date and time.
 TimeParser parse(java.lang.String timeString)
           
 void resetSeconds()
          reset the seconds register.
 TimeParser setDigit(int digitNumber, int digit)
          This allows for string split into elements to be interpretted here.
 void setDigit(java.lang.String format, double value)
          set the digit with the integer part, and move the fractional part to the less significant digits.
 TimeParser setDigit(java.lang.String format, int value)
          Set the digit using the format code.
 void sloppyColumns()
          force the parser to look for delimiters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEFORMAT_Z

public static final java.lang.String TIMEFORMAT_Z
%Y-%m-%dT%H:%M:%S.%{milli}Z

See Also:
Constant Field Values
Method Detail

iso8601String

public static java.lang.String iso8601String(java.lang.String exampleTime)
must contain T or space to delimit date and time.

Parameters:
exampleTime - "1992-353T02:00"
Returns:
"%Y-%jT%H%M" etc.

create

public static TimeParser create(java.lang.String formatString)
  %[fieldLength]<1-char code>  or
  %[fieldLength]{}

  fieldLength=0 --> makes field length indeterminate, deliminator must follow.

  %Y   4-digit year
  %y    2-digit year
  %j     3-digit day of year
  %m   2-digit month
  %b   3-char month name
  %d    2-digit day
  %H    2-digit hour
  %M    2-digit minute
  %S     2-digit second
  %{milli}  3-digit milliseconds
  


create

public static TimeParser create(java.lang.String formatString,
                                java.lang.String fieldName,
                                TimeParser.FieldHandler handler)
This version allows for extension by specifying an external handler. %3{fieldName} 2 characters are passed to the handler %Y 4-digit year %y 2-digit year %m month %2m 2-digit month %d 2-digit day %H 2-digit hour %M 2-digit minute %S 2-digit second %{milli} 3-digit milliseconds


resetSeconds

public void resetSeconds()
reset the seconds register. setDigit( String formatCode, double val ) accumulates fractional part in the seconds.


sloppyColumns

public void sloppyColumns()
force the parser to look for delimiters


parse

public TimeParser parse(java.lang.String timeString)
                 throws java.text.ParseException
Throws:
java.text.ParseException

setDigit

public void setDigit(java.lang.String format,
                     double value)
set the digit with the integer part, and move the fractional part to the less significant digits.

Parameters:
format -
value -

setDigit

public TimeParser setDigit(java.lang.String format,
                           int value)
Set the digit using the format code. If multiple digits are found, then the integer provided should be the misinterpreted integer. For example, if the format is "%Y%m%d", the integer 20080830 is split apart into 2008,08,30.

Parameters:
format - spec like "%Y%m%d"
value - integer like 20080830.
Returns:

setDigit

public TimeParser setDigit(int digitNumber,
                           int digit)
This allows for string split into elements to be interpretted here. This is to add flexibility to external parsers that have partially parsed the number already. examples: TimeParser p= TimeParser.create("%Y %m %d"); p.setDigit(0,2007).setDigit(1,12).setDigit(2,5).getTime( Units.us2000 ); p.format(); // maybe in the future

Parameters:
digitNumber, - the digit to set (starting with 0).
Throws:
java.lang.IllegalArgumentException - if the digit has a custom field handler
java.lang.IllegalArgumentException - if the digit does not exist.

getTime

public double getTime(Units units)

getTimeDatum

public Datum getTimeDatum()

getTimeRange

public DatumRange getTimeRange()
Returns the implicit interval as a DatumRange. For example, "Jan 1, 2003" would have a getTimeDatum of "Jan 1, 2003 00:00:00", and getDatumRange() would go from midnight to mignight.


getEndTime

public double getEndTime(Units units)

getRegex

public java.lang.String getRegex()

format

public java.lang.String format(Datum start,
                               Datum end)
format the range into a string.

Parameters:
start -
end - currently ignored, and may be used in the future
Returns:
formatted string.