Package org.dlese.dpc.index.document
Class DateFieldTools
java.lang.Object
org.dlese.dpc.index.document.DateFieldTools
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final StringdateToString(Date date) Converts a Date to a string suitable for indexing using resolution to seconds.static final DatestringToDate(String dateString) Converts a string produced bytimeToString(long)ordateToString(java.util.Date)back to a time, represented as a Date object.static final longstringToTime(String dateString) Converts a string produced bytimeToString(long)ordateToString(java.util.Date)back to a time, represented as the number of milliseconds since January 1, 1970, 00:00:00 GMT.static final StringtimeToString(long time) Converts a millisecond time to a string suitable for indexing using resolution to seconds.
-
Constructor Details
-
DateFieldTools
public DateFieldTools()
-
-
Method Details
-
dateToString
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
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
Converts a string produced bytimeToString(long)ordateToString(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
Converts a string produced bytimeToString(long)ordateToString(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
-