Class DateProviderFactory

java.lang.Object
com.norconex.importer.handler.condition.impl.DateProviderFactory

public final class DateProviderFactory extends Object

Creates suppliers of static or dynamic dates, from a formatted string.

To successfully parse a date string, 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).

Static dates:

You can specify a static date (i.e. a constant date value). 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)
 

Dynamic dates:

The date string can also represent 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, producing the same date at each supplier invocation (i.e., does not change after being created for the first time), or whether it should be refreshed on every invocation to reflect the passing of time.

Time zones:

If the time zone (id or offset) is part of the formatted date string, it will be honored. If not specified, it will use the provided time zone argument, or fall back to UTC if the time zone argument is null.

Date format:

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.
 
  • Method Details

    • create

      public static DateProvider create(@NonNull @NonNull String dateStr, ZoneId zoneId)
      Create a new date supplier based on the given string. The ZoneId is ignored for a static date, which is expected to have it as part of its string representation if required. Dynamic dates will default to UTC time-zone if not is supplied.
      Parameters:
      dateStr - date string to parse
      zoneId - zone id for the date supplier, if applicable
      Returns:
      zoned date time supplier