Class DateFieldTools

java.lang.Object
org.dlese.dpc.index.document.DateFieldTools

public class DateFieldTools extends Object
Provides support for converting dates to strings and vice-versa using seconds as the default time granularity. The strings are structured so that lexicographic sorting orders them by date, which makes them suitable for use as field values and search terms. This class simply wraps the appropriate methods from DateTools and applies a resolution of seconds.
Author:
John Weatherley
See Also:
  • DateTools
  • Constructor Details

    • DateFieldTools

      public DateFieldTools()
  • Method Details

    • dateToString

      public static final String dateToString(Date date)
      Converts a Date to a string suitable for indexing using resolution to seconds.
      Parameters:
      date - The Date
      Returns:
      A string in format yyyyMMddHHmmss; using UTC as timezone
    • timeToString

      public static final String timeToString(long time)
      Converts a millisecond time to a string suitable for indexing using resolution to seconds.
      Parameters:
      time - Time in millisonds
      Returns:
      A string in format yyyyMMddHHmmss; using UTC as timezone
    • stringToDate

      public static final Date stringToDate(String dateString) throws ParseException
      Converts a string produced by timeToString(long) or dateToString(java.util.Date) back to a time, represented as a Date object. Is also able to parse dates encoded in the old Lucene 1.x DateField format, for compatibility with old indexes (this functionality will go away in a future release).
      Parameters:
      dateString - A string produced by timeToString or dateToString
      Returns:
      The parsed time as a Date object
      Throws:
      ParseException - If parse error
    • stringToTime

      public static final long stringToTime(String dateString) throws ParseException
      Converts a string produced by timeToString(long) or dateToString(java.util.Date) back to a time, represented as the number of milliseconds since January 1, 1970, 00:00:00 GMT. Is also able to parse dates encoded in the old Lucene 1.x DateField format, for compatibility with old indexes (this functionality will go away in a future release).
      Parameters:
      dateString - A string produced by timeToString or dateToString
      Returns:
      The number of milliseconds since January 1, 1970, 00:00:00 GMT
      Throws:
      ParseException - If parse error