-
Notifications
You must be signed in to change notification settings - Fork 7
DateProcessor
Dates and partial dates are processed using the JSR-310 library. This basic processor will only parse dates where an exact result (no ambiguity) can be found. The processor will return the date as 3 separate fields to handle partial dates.
Note : For dates that only contain numbers, those 3 separators are supported : dash(-), slash(/) and dot(.).
##Supported Gregorian big-endian(Year-Month-Day) including some ISO 8601
- 1987-06-03 (1987-6-3)
- 1987-06 (1987-6)
- 1987
- 19870603 (zeros are mandatory here)
- 1987 Jun 03 (1987 Jun 3)
##Supported Gregorian little-endian(Day-Month-Year)
- 3 Jun 1987 (03 Jun 1987)
- 31-12-2012*
- 31-XII-2012 (month as Roman numerals)
##Supported Middle-endian(Month-Day-Year)
- Jun 3 1987 (Jun 03 1987)
- 12-31-2012*
##Other supported date format:
- Jun 1987
- Jun
* If it's not possible to clearly identify the day and the month (like 11-10-2012) the date will not be parsed.
##Usage Here is a very basic example using the mock object MockRawOccurrenceModel and MockOccurrenceModel.
//initialize the processor with the matching field name inside the model.
//eventStartYear,eventStartMonth,eventStartDay are Integer
AbstractDataProcessor dateProcessor = new DateProcessor("eventDate", "eventStartYear", "eventStartMonth", "eventStartDay");
MockRawOccurrenceModel mockRawModel = new MockRawOccurrenceModel();
MockOccurrenceModel mockModel = new MockOccurrenceModel();
//Set the date as string
mockRawModel.setEventDate("2010-06-30");
dateProcessor.processBean(mockRawModel, mockModel, null, null);
System.out.print(mockModel.getEventStartYear() + ",");
System.out.print(mockModel.getEventStartMonth() + ",");
System.out.print(mockModel.getEventStartDay());
//prints: 2010,6,30
Another basic example using the ProcessingResult
//...
//set an invalid date
mockRawModel.setEventDate("2010-30-30");
ProcessingResult pr = new ProcessingResult();
dateProcessor.processBean(mockRawModel, mockModel, null, pr);
System.out.print(pr.getErrorList().get(0));
//prints: The date [2010-30-30] could not be processed.
Another basic example using a partial date
//...
mockRawModel.setEventDate("Jun 2009");
dateProcessor.processBean(mockRawModel, mockModel, null, null);
System.out.print(mockModel.getEventStartYear() + ",");
System.out.print(mockModel.getEventStartMonth() + ",");
System.out.print(mockModel.getEventStartDay());
//prints: 2009,6,null
#DateIntervalProcessor
Considering the number of different ways to write a date, the current implementation of DateIntervalProcessor is simplified and may not be suitable in all scenarios.
Date intervals are processed using an algorithm based on the symmetry of a block of text. It checks for identical punctuation on both sides of a unique divider. e.g. 1977-08-16/1977-08-20
has 2 dashes (-) on either side of a unique slash (/). The resultant start and end dates should not be considered valid but more like date candidates within the provided text.
Partial dates or interval with notation like 2004-12-02/05 are not yet supported. ##Usage
AbstractDataProcessor dateIntervalProcessor = new DateIntervalProcessor("eventDate", "eventStartDate", "eventEndDate");
MockRawOccurrenceModel mockRawModel = new MockRawOccurrenceModel();
MockOccurrenceModel mockModel = new MockOccurrenceModel();
mockRawModel.setEventDate("1977-08-16/1977-08-20");
dateIntervalProcessor.processBean(mockRawModel, mockModel, null, null);
System.out.println(mockModel.getEventStartDate()+","+mockModel.getEventEndDate());
//prints: 1977-08-16,1977-08-20