ucar.unidata.util
Class DatePattern

java.lang.Object
  extended by ucar.unidata.util.DatePattern

public class DatePattern
extends Object

handle user defined simple date/time patterns (such as yyyymm hh:nn)

Version:
$Revision: 1.54 $
Author:
Willem Nieuwenhuis

Nested Class Summary
 class DatePattern.DmyPattern
           
 
Constructor Summary
DatePattern(String dmtpat)
          Constructor: creates a regular expression to extract a date based on a template.
 
Method Summary
 int get(char field)
          Retrieve the value of the field.
 DateTime getDateTime()
           
 String getRegex()
          Get the regular expression that is generated from the template
 List<Character> getValidFields()
          Return the fields for which the template matched the search string.
static void main(String[] args)
           
 boolean match(String search)
          Match a search string against the compile pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatePattern

public DatePattern(String dmtpat)
Constructor: creates a regular expression to extract a date based on a template. The template uses date/time elements only (numerically only!):
  • y, Y : Year
  • m, M : Month
  • d, D : Day
  • h, H : Hour
  • n, N : Minute (m is already in use for MONTH)
  • s, S : Seconds

    Parameters:
    dmtpat - the user defined date/time pattern
  • Method Detail

    getValidFields

    public List<Character> getValidFields()
    Return the fields for which the template matched the search string. For example the template 'yyyymm' applied to the search string 'GLR200704' will return [YEAR, MONTH].

    Returns:
    The list with found fields

    get

    public int get(char field)
    Retrieve the value of the field. If no value was parsed the value will be -1. Recognized field values are:
  • YEAR
  • MONTH
  • DAY
  • HOUR
  • MINUTE
  • SECOND

    Parameters:
    field - the field to retrieve the value for
    Returns:
    the value of the field

  • match

    public boolean match(String search)
    Match a search string against the compile pattern.

    Parameters:
    search - the search string
    Returns:
    true if there is a match

    getRegex

    public String getRegex()
    Get the regular expression that is generated from the template

    Returns:
    The regular expression

    getDateTime

    public DateTime getDateTime()
    Returns:
    the date / time of the latest match() call

    main

    public static void main(String[] args)