Package datetime
Class Handler
- Object
-
- Handler
-
- All Implemented Interfaces:
Cloneable
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 intoLocalDate
andLocalTime
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 theinput
map:Features Key Possible Values Examples 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, time2 A time range between 4 and 5 o'clock → ['relation': 'between', 'time1': ['hour': 4, 'meridiem': 'ampm'], 'time2': ['hour': 5, 'meridiem': 'pm']] date1, date2 A date range between monday and wednesday → ['relation': 'between', 'date1': ['weekday': 'mon'], 'date2': ['weekday': 'wed']]
Nested Expressions Key Possible Values Examples 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 Name Possible 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
Theinterpret
methods return a map containing date and/or time data of the following format: Key Value date {DATESPEC} time {TIMESPEC}
{DATESPEC} is a map containg the following data: Key Value type "point"
or"range"
start List<LocalDate>
end List<LocalDate>
{TIMESPEC} is a map containg the following data: Key Value type "point"
or"range"
start List<LocalTime>
end List<LocalTime>
-
-
Constructor Summary
Constructors Constructor Description Handler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
destroy()
static Map<String,Object>
interpret(Map<String,Object> input)
Calls tointerpret_(Map)
on the singleton instance.static Map<String,Object>
interpret(Map<String,Object> input, String anchorOrDirection)
Calls tointerpret_(Map,String,String)
on the singleton instance.static Map<String,Object>
interpret(Map<String,Object> input, String anchorOrDirection1, String anchorOrDirection2)
Calls tointerpret_(Map,String)
on the singleton instance.Map<String,Object>
interpret_(Map<String,Object> input)
Inteprets the given date & time features against the current anchor of this instance.Map<String,Object>
interpret_(Map<String,Object> input, String anchorOrDirection)
Inteprets the given date & time features against the given anchor or direction.Map<String,Object>
interpret_(Map<String,Object> input, String anchorOrDirection1, String anchorOrDirection2)
Inteprets the given date & time features against the given anchor and direction.void
reset()
static void
setAnchor(String anchor)
Calls tosetAnchor_(java.lang.String)
on the singleton instance.void
setAnchor_(String anchor)
Sets the anchor to be used by relative date/time expressions given to theinterpret_ methods
.
-
-
-
Method Detail
-
destroy
public static void destroy()
-
reset
public void reset()
-
setAnchor
public static void setAnchor(String anchor)
Calls tosetAnchor_(java.lang.String)
on the singleton instance.
-
setAnchor_
public void setAnchor_(String anchor)
Sets the anchor to be used by relative date/time expressions given to theinterpret_ 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).
- YYYY - year, 4 digits
- MM - month of year, 2 digits: 01 - 12
- DD - day of month, 2 digits: 01 - 31
- HH - hours, 2 digits: 00-23 (24 hours clock)
- MM - minutes, 2 digits: 00 - 59
- SS - seconds, 2 digits: 00 - 59
-
interpret
public static Map<String,Object> interpret(Map<String,Object> input)
Calls tointerpret_(Map)
on the singleton instance. The implementation is thread-safe.
-
interpret
public static Map<String,Object> interpret(Map<String,Object> input, String anchorOrDirection1, String anchorOrDirection2)
Calls tointerpret_(Map,String)
on the singleton instance. The implementation is thread-safe.
-
interpret
public static Map<String,Object> interpret(Map<String,Object> input, String anchorOrDirection)
Calls tointerpret_(Map,String,String)
on the singleton instance. The implementation is thread-safe.
-
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 theanchorOrDirection
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. ParameteranchorOrDirection
either specifies the direction ("back" or "forward") or an anchor date (and time).
-
-