Package datetime

Class Handler

  • All Implemented Interfaces:

    public class Handler
    extends Object
    implements Cloneable
    This class provides utility methods for post-processing of the complex date & time data generated by NLU code of a solution and to convert it into LocalDate and LocalTime objects.

    For convenience a static singleton is provided. It is accessible by the static methods.

    The interpret methods recognize several date and time features, given as keys of the input map:

    KeyPossible ValuesExamples
    year{1950 - 2050}, {MODIFIER}2018 → ['year': 2018], next year → ['year': 'next']
    quarter{1 - 4}, {MODIFIER}2nd quarter → ['quarter': 2], last quarter → ['quarter': 'previous']
    month{1 - 12}, {MODIFIER}april → ['month': 4], this month → ['month': 'this']
    month_modifier{MODIFIER}next april → ['month_modifier': 'next', 'month': 4]
    week{1 - 53}, {MODIFIER}week 23 → ['week': 23], last week → ['week': 'previous']
    day_of_month{1 - 31}, {MODIFIER}23. april → ['day_of_month': 23, 'month': 4], the next day → ['day_of_month': 'next']
    weekday{WEEKDAY}wednesday → ['weekday': 'wed']
    weekday_modifier{MODIFIER}next wednesday → ['weekday_modifier': 'next', 'weekday': 'wed']
    named_relative{NAMED_RELATIVE}tomorrow → ['named_relative': 'tomorrow']
    named{NAMED}day after tomorrow→ ['named': 'day_after_tomorrow']
    hour{1 - 12}4 o'clock → ['hour': 4, 'meridiem':'ampm']
    minute{0 - 59}13:15 → ['hour': 1, 'meridiem':'pm', 'minute':15]
    second{0 - 59}13:15:45 → ['hour':1, 'meridiem':'pm', minute:15, second:45]
    meridiem{AMPM}3 pm → ['hour':3, 'meridiem':'pm']
    time_of_day{TIME_OF_DAY}morning → ['time_of_day': 'morning']
    time_of_day_modifier{MODIFIER}this evening → ['time_of_day_modifier': 'this', 'time_of_day':'evening']
    relation{RELATION}in 5 days → ['relation':'in', 'offset': ['day': 5]]
    direction{DIRECTION}next couple of days → ['direction':'next', 'duration':['day': 'couple']]
    season{SEASON}autumn → ['season': 'autumn']
    season_modifier{MODIFIER}next autumn → ['season_modifier': 'next', 'season': 'autumn']
    time1, time2A time rangebetween 4 and 5 o'clock → ['relation': 'between', 'time1': ['hour': 4, 'meridiem': 'ampm'], 'time2': ['hour': 5, 'meridiem': 'pm']]
    date1, date2A date rangebetween monday and wednesday → ['relation': 'between', 'date1': ['weekday': 'mon'], 'date2': ['weekday': 'wed']]

    Nested Expressions
    KeyPossible ValuesExamples
    duration[DATEUNIT]:{1 - 99}3 weeks and 4 days → ['duration': ['week':3, 'day':4]]
    offset[DATEUNIT]:{1 - 99}5 months ago → ['relation': 'ago', 'offset: ['month':5]]
    date_anchor[DATE]3 days before today → ['relation': 'before', 'offset':['day': 3], 'date_anchor': ['named': 'today']]
    time_anchor[TIME]20 past 3pm → ['relation': 'after', 'offset':['minute':20], 'time_anchor':['hour':3, 'meridiem':'pm']]
    date[DATE]['date': ['weekday': 'mon']]
    time[TIME}['time': ['named_relative': 'now']]

    Value sets
    NamePossible Values
    {MODIFIER}previous_previous, previous, this, next, next_next
    {WEEKDAY}mon, tue, wed, thu, fri, sat, sun, satsun
    {NAMED}christmas_eve, christmas_day, new_years_eve, new_years_day, midsummer_eve
    {NAMED_RELATIVE}today, yesterday, tomorrow, day before yesterday, day after tomorrow
    {RELATIVE}day_before_yesterday, yesterday, tomorrow, day_after_tomorrow
    {RELATION}after, ago, around, before, between, during, in
    {DIRECTION}this, next, previous
    {SEASON}spring, summer, autumn, winter
    [DATEUNIT]year, month, fortnight, week, day

    The interpret methods return a map containing date and/or time data of the following format:

    {DATESPEC} is a map containg the following data:
    type"point" or "range"

    {TIMESPEC} is a map containg the following data:
    type"point" or "range"
    • Constructor Detail

      • Handler

        public Handler()
    • Method Detail

      • destroy

        public static void destroy()
      • reset

        public void reset()
      • setAnchor_

        public void setAnchor_​(String anchor)
        Sets the anchor to be used by relative date/time expressions given to the interpret_ methods.

        The following inputs are recognized:

        • null - unsets the date and time anchors
        • "now" - sets the date anchor to today's date and the time anchor to the current time.
        • <date> [ 'T' <time> ] - sets the date anchor (and optionally the time anchor) to the given date (and time).
        <date> must have the following form: YYYY [ '-' MM [ '-' DD ] ], e.g. 2018-10-03
        • YYYY - year, 4 digits
        • MM - month of year, 2 digits: 01 - 12
        • DD - day of month, 2 digits: 01 - 31
        <time> must have the following form: HH [ MM [ SS ] ], e.g. 1531
        • HH - hours, 2 digits: 00-23 (24 hours clock)
        • MM - minutes, 2 digits: 00 - 59
        • SS - seconds, 2 digits: 00 - 59
      • interpret_

        public Map<String,​Object> interpret_​(Map<String,​Object> input,
                                                   String anchorOrDirection1,
                                                   String anchorOrDirection2)
        Inteprets the given date & time features against the given anchor and direction. One of the anchorOrDirection parameters must specify the direction ("back" or "forward"), the other one an anchor date (and time).
      • interpret_

        public Map<String,​Object> interpret_​(Map<String,​Object> input,
                                                   String anchorOrDirection)
        Inteprets the given date & time features against the given anchor or direction. Parameter anchorOrDirection either specifies the direction ("back" or "forward") or an anchor date (and time).
      • interpret_

        public Map<String,​Object> interpret_​(Map<String,​Object> input)
        Inteprets the given date & time features against the current anchor of this instance.