public class DateCondition extends Object implements IImporterCondition, IXMLConfigurable
A condition based on the date value(s) of matching
metadata fields given the supplied date format. If multiple values are
found for a field, only one of them needs to match for this condition to
be true.
If the value is not a valid date, it is considered not to be matching
(i.e., false
).
The default operator is "eq" (equals).
This condition accepts zero, one, or two value matchers:
true
).
To successfully parse a date, you can specify a date format,
as per the formatting options found on DateTimeFormatter
.
The default format when not specified is EPOCH (the difference, measured in
milliseconds, between the date and midnight, January 1, 1970).
When defining a date value matcher, you can specify an absolute date (i.e. a constant date value) to be used for comparison. Supported formats for configuring an absolute date are:
yyyy-MM-dd -> date (e.g. 2015-05-31) yyyy-MM-ddThh:mm:ss[.SSS] -> date and time with optional milliseconds (e.g. 2015-05-31T22:44:15)
Date value matchers can also specify a moment in time relative to the
current date using the TODAY
or NOW
keyword,
optionally followed by a number of time units to add/remove.
TODAY
is the current day without the hours, minutes, and
seconds, where as NOW
is the current day with the hours,
minutes, and seconds. You can also decide whether you want the
current date to be fixed for the lifetime of this condition (does not change
after being set for the first time), or whether
it should be refreshed on every invocation to reflect the passing of time.
When comparing dates at a more granular level (e.g., hours, minutes, seconds), it may be important to take time zones into account. If the time zone (id or offset) is part of a document field date value and the configured date format supports time zones, it will be be interpreted as a date in the encountered time zone.
In cases where you want to overwrite the value's existing time zone or
specify one for dates without time zones, you can do so with
the setDocZoneId(ZoneId)
method.
Explicitly setting a time zone will not "convert" a date to that time zone,
but will rather assume it was created in the supplied time zone.
When using XML configuration to define the condition dates, you can
specify the time zone using the conditionZoneId
option.
Operators can be parsed using symbols or text abbreviations. Text abbreviations are useful when you do now want to concern yourself when used in XML. Possible representations are:
Symbol | Abbreviation | Meaning |
---|---|---|
> | gt | greater than |
>=, => | ge | greater equal |
< | lt | lower than |
<=, =< | le | lowe equal |
=, == | eq,is | equals |
<condition
class="com.norconex.importer.handler.condition.impl.DateCondition"
format="(document field date format)"
docZoneId="(force a time zone on evaluated fields.)"
conditionZoneId="(time zone of configured condition dates.)">
<fieldMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(expression matching date fields to evaluate)
</fieldMatcher>
<!--
Use one or two (for ranges) conditions where:
Possible operators are:
gt -> greater than
ge -> greater equal
lt -> lower than
le -> lower equal
eq -> equals
Condition date value format are either one of:
yyyy-MM-dd -> date (e.g. 2015-05-31)
yyyy-MM-ddThh:mm:ss[.SSS] -> date and time with optional
milliseconds (e.g. 2015-05-31T22:44:15)
TODAY[-+]9[YMDhms][*] -> the string "TODAY" (at 0:00:00) minus
or plus a number of years, months, days,
hours, minutes, or seconds
(e.g. 1 week ago: TODAY-7d).
* means TODAY can change from one
invocation to another to adjust to a
change of current day
NOW[-+]9[YMDhms][*] -> the string "NOW" (at current time)
minus
or plus a number of years, months, days,
hours, minutes, or seconds
(e.g. 1 week ago: NOW-7d).
* means NOW changes from one invocation
to another to adjust to the current
time.
-->
<valueMatcher
operator="[gt|ge|lt|le|eq]"
date="(a date)"/>
</condition>
<condition
class="DateCondition"
format="yyyy-MM-dd'T'HH:mm:ssZ"
conditionZoneId="America/New_York">
<fieldMatcher>publish_date</fieldMatcher>
<valueMatcher
operator="ge"
date="TODAY-7"/>
<valueMatcher
operator="lt"
date="TODAY"/>
</condition>
The above example will only keep documents from the last seven days, not including today.
Modifier and Type | Class and Description |
---|---|
static class |
DateCondition.DynamicFixedDateTimeSupplier |
static class |
DateCondition.DynamicFloatingDateTimeSupplier |
static class |
DateCondition.StaticDateTimeSupplier |
static class |
DateCondition.TimeUnit |
static class |
DateCondition.ValueMatcher |
Constructor and Description |
---|
DateCondition() |
DateCondition(TextMatcher fieldMatcher) |
DateCondition(TextMatcher fieldMatcher,
DateCondition.ValueMatcher valueMatcher) |
DateCondition(TextMatcher fieldMatcher,
DateCondition.ValueMatcher rangeStart,
DateCondition.ValueMatcher rangeEnd) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
ZoneId |
getDocZoneId()
Gets the time zone id documents are considered to be.
|
TextMatcher |
getFieldMatcher() |
String |
getFormat() |
DateCondition.ValueMatcher |
getValueMatcher() |
DateCondition.ValueMatcher |
getValueMatcherRangeEnd() |
int |
hashCode() |
void |
loadFromXML(XML xml) |
void |
saveToXML(XML xml) |
void |
setDocZoneId(ZoneId docZoneId)
Sets the time zone id documents are considered to be.
|
void |
setFieldMatcher(TextMatcher fieldMatcher)
Sets the text matcher of field names.
|
void |
setFormat(String format) |
void |
setValueMatcher(DateCondition.ValueMatcher firstValueMatcher) |
void |
setValueMatcherRangeEnd(DateCondition.ValueMatcher secondValueMatcher) |
boolean |
testDocument(HandlerDoc doc,
InputStream input,
ParseState parseState)
Tests a given document.
|
String |
toString() |
public DateCondition()
public DateCondition(TextMatcher fieldMatcher)
public DateCondition(TextMatcher fieldMatcher, DateCondition.ValueMatcher valueMatcher)
public DateCondition(TextMatcher fieldMatcher, DateCondition.ValueMatcher rangeStart, DateCondition.ValueMatcher rangeEnd)
public TextMatcher getFieldMatcher()
public void setFieldMatcher(TextMatcher fieldMatcher)
fieldMatcher
- text matcherpublic DateCondition.ValueMatcher getValueMatcher()
public void setValueMatcher(DateCondition.ValueMatcher firstValueMatcher)
public DateCondition.ValueMatcher getValueMatcherRangeEnd()
public void setValueMatcherRangeEnd(DateCondition.ValueMatcher secondValueMatcher)
public ZoneId getDocZoneId()
public void setDocZoneId(ZoneId docZoneId)
docZoneId
- zone idpublic String getFormat()
public void setFormat(String format)
public boolean testDocument(HandlerDoc doc, InputStream input, ParseState parseState) throws ImporterHandlerException
IImporterCondition
testDocument
in interface IImporterCondition
doc
- the document to testinput
- document contentparseState
- whether the document has been parsed already or not (a
parsed document should normally be text-based)true
if the condition evaluates as suchImporterHandlerException
- problem reading the documentpublic void loadFromXML(XML xml)
loadFromXML
in interface IXMLConfigurable
public void saveToXML(XML xml)
saveToXML
in interface IXMLConfigurable
Copyright © 2009–2023 Norconex Inc.. All rights reserved.