Class TimeStampExtractor


  • public class TimeStampExtractor
    extends Object

    Allows to extract time information from file names.

    Usage:

    • create a new instance providing a date interpretation pattern and a filename interpretation pattern
    • the date interpretation pattern must be composed of the following components:
      • year, given as yyyy
      • month, given as MM or MMM
      • days in month, given as dd
      • day in year, given as DDD
      • hour of day, in 12 hour format, given as hh
      • hour of day, in 24 hour format, given as HH
      • minute of hour, given as mm
      • second of minute, given as ss
      , which may appear in arbitrary order and can be separated using the characters _, ., and -.
      Examples:
      • yyyyMMMdd_hhmmss
      • yyyyMMdd_hhmmss
      • yyyyMMdd
    • the filename interpretation pattern must contain at least one of the placeholders ${startDate} and ${endDate}. Examples:
      • sst_*_${startDate}.nc
      • sst_*_${startDate}_${endDate}*.nc
    • call extractTimeStamps(String) to receive the start and stop time of the respective filename
    • for filenames containing only a single date, start and stop time are identical

    Limitations:

    • If both start date and end date are provided, the first pattern found in the filename is always considered the start date.
    • Constructor Detail

      • TimeStampExtractor

        public TimeStampExtractor​(String dateInterpretationPattern,
                                  String filenameInterpretationPattern)
        Creates a new instance with the given date and file interpretation patterns.
        Parameters:
        dateInterpretationPattern - the date interpretation pattern; see class documentation for specification.
        filenameInterpretationPattern - the filename interpretation pattern; see class documentation for specification.
        Throws:
        IllegalStateException - if the filename interpretation pattern contains neither ${startDate} nor ${endDate}.
    • Method Detail

      • extractTimeStamps

        public ProductData.UTC[] extractTimeStamps​(String fileName)
                                            throws ValidationException
        Provides the start and stop time of the respective filename.
        Parameters:
        fileName - The filename to extract time information from.
        Returns:
        An array of length 2 containing start and stop time, never null.
        Throws:
        ValidationException - if the given filename does not match the given date pattern.