Class DateCondition

java.lang.Object
com.norconex.importer.handler.condition.impl.DateCondition
All Implemented Interfaces:
Configurable<DateConditionConfig>, Condition, ConfigurableCondition<DateConditionConfig>, FailablePredicate<DocHandlerContext,IOException>

public class DateCondition extends Object implements ConfigurableCondition<DateConditionConfig>

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).

Single date vs range of dates:

This condition accepts zero, one, or two value matchers:

  • 0: Use no value matcher to simply evaluate whether the value is a date.
  • 1: Use one value matcher to evaluate if the value is lower/greater and/or the same as the specified date.
  • 2: Use two value matchers to define a date range to evaluate (both matches have to evaluate to true).

Metadata date field format:

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).

Absolute date conditions:

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)
 

Relative date conditions:

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.

Time zones:

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 this filter configured format supports time zones, it will respect the time zone in the encountered time zone.

In cases where you want to specify the time zone for values without one, you can do so with the DateConditionConfig.setDocZoneId(ZoneId) method. Explicitly setting a document time zone that way has no effect if the date already defines its own zone. The default time zone when none is specified is UTC.

When using XML configuration to define the condition dates, you can specify the time zone using the conditionZoneId option.

Operator
See Also: