www.espertech.comDocumentation

Chapter 12. EPL Reference: Date-Time Methods

12.1. Overview
12.2. How to Use
12.2.1. Syntax
12.3. Calendar and Formatting Reference
12.3.1. Between
12.3.2. Format
12.3.3. Get (By Field)
12.3.4. Get (By Name)
12.3.5. Minus
12.3.6. Plus
12.3.7. RoundCeiling
12.3.8. RoundFloor
12.3.9. RoundHalf
12.3.10. Set (By Field)
12.3.11. WithDate
12.3.12. WithMax
12.3.13. WithMin
12.3.14. WithTime
12.3.15. ToCalendar
12.3.16. ToDate
12.3.17. ToMillisec
12.4. Interval Algebra Reference
12.4.1. Examples
12.4.2. Interval Algebra Parameters
12.4.3. Performance
12.4.4. Limitations
12.4.5. After
12.4.6. Before
12.4.7. Coincides
12.4.8. During
12.4.9. Finishes
12.4.10. Finished By
12.4.11. Includes
12.4.12. Meets
12.4.13. Met By
12.4.14. Overlaps
12.4.15. Overlapped By
12.4.16. Starts
12.4.17. Started By

EPL date-time methods work on date-time values to perform common tasks such as comparing times and time periods, adding or subtracting time periods, setting or rounding calendar fields and querying fields.

Date-time methods operate on:

  1. Any expression or event property that returns either a long-type millisecond value, a java.util.Calendar or java.util.Date including subclasses. Consider the built-in single-row function current_timestamp for use with date-time methods.

  2. Any event for which the event type declares a start timestamp property name and optionally also an end timestamp property name. Date-time methods operate on events by means of the stream-alias.method-name syntax.

The below table summarizes the built-in date-time methods available:

Table 12.1. Date-Time Methods

MethodResult
after(event or timestamp)

Returns true if an event happens after another event, or a timestamp is after another timestamp.

Section 12.4.5, “After”.

before(event or timestamp)

Returns true if an event happens before another event, or a timestamp is before another timestamp.

Section 12.4.6, “Before”.

between(timestamp, timestamp, boolean, boolean)

Returns true if a timestamp is between two timestamps.

Section 12.3.1, “Between”.

coincides(event or timestamp)

Returns true if an event and another event happen at the same time, or two timestamps are the same value.

Section 12.4.7, “Coincides”.

during(event or timestamp)

Returns true if an event happens during the occurrence of another event, or when a timestamps falls within the occurrence of an event.

Section 12.4.8, “During”.

finishes(event or timestamp)

Returns true if an event starts after another event starts and the event ends at the same time as the other event.

Section 12.4.9, “Finishes”.

finishedBy(event or timestamp)

Returns true if an event starts before another event starts and ends at the same time as the other event.

Section 12.4.10, “Finished By”.

format()

Formats the date-time returning a string.

Section 12.3.2, “Format”.

get(field)

Returns the value of the given date-time value field.

Section 12.3.3, “Get (By Field)”.

getMillisOfSecond()

getSecondOfMinute()

getMinuteOfHour()

getHourOfDay()

getDayOfWeek()

getDayOfMonth()

getDayOfYear()

getWeekyear()

getMonthOfYear()

getYear()

getEra()

Returns the value of the given date-time value field.

Section 12.3.4, “Get (By Name) ”.

includes(event or timestamp)

Returns true if the parameter event happens during the occurrence of the event, or when a timestamps falls within the occurrence of an event.

Section 12.4.11, “Includes”.

meets(event or timestamp)

Returns true if the event's end time is the same as another event's start time.

Section 12.4.12, “Meets”.

metBy(event or timestamp)

Returns true if the event's start time is the same as another event's end time.

Section 12.4.13, “Met By”.

minus(duration-millis)

Returns a date-time with the specified duration in long-type milliseconds taken away.

Section 12.3.5, “Minus”.

minus(time-period)

Returns a date-time with the specified duration in time-period syntax taken away.

Section 12.3.5, “Minus”.

overlaps(event or timestamp)

Returns true if the event starts before another event starts and finishes after the other event starts, but before the other event finishes (events have an overlapping period of time).

Section 12.4.14, “Overlaps”.

overlappedBy(event or timestamp)

Returns true if the parameter event starts before the input event starts and the parameter event finishes after the input event starts, but before the input event finishes (events have an overlapping period of time).

Section 12.4.15, “Overlapped By”.

plus(duration-millis)

Returns a date-time with the specified duration in long-type milliseconds added.

Section 12.3.6, “Plus”.

plus(time-period)

Returns a date-time with the specified duration in time-period syntax added.

Section 12.3.6, “Plus”.

roundCeiling(field)

Returns a date-time rounded to the highest whole unit of the date-time field.

Section 12.3.7, “RoundCeiling”.

roundFloor(field)

Returns a date-time rounded to the lowest whole unit of the date-time field.

Section 12.3.8, “RoundFloor”.

roundHalf(field)

Returns a date-time rounded to the nearest whole unit of the date-time field.

Section 12.3.9, “RoundHalf”.

set(field, value)

Returns a date-time with the specified field set to the value returned by a value expression.

Section 12.3.10, “Set (By Field)”.

starts(event or timestamp)

Returns true if an event and another event start at the same time and the event's end happens before the other event's end.

Section 12.4.16, “Starts”.

startedBy(event or timestamp)

Returns true if an event and another event start at the same time and the other event's end happens before the input event's end.

Section 12.4.17, “Started By”.

withDate(year,month,day)

Returns a date-time with the specified date, retaining the time fields.

Section 12.3.11, “WithDate”.

withMax(field)

Returns a date-time with the field set to the maximum value for the field.

Section 12.3.12, “WithMax”.

withMin(field)

Returns a date-time with the field set to the minimum value for the field.

Section 12.3.13, “WithMin”.

withTime(hour,minute,sec,msec)

Returns a date-time with the specified time, retaining the date fields.

Section 12.3.14, “WithTime”.

toCalendar()

Returns the Calendar object for this date-time value.

Section 12.3.15, “ToCalendar”.

toDate()

Returns the Date object for this date-time value.

Section 12.3.16, “ToDate”.

toMillisec()

Returns the long-type milliseconds value for this date-time value.

Section 12.3.17, “ToMillisec”.


The syntax for date-time methods is the same syntax as for any chained invocation:

input_val.datetime_method_name( [method_parameter [, method_parameter [,...]]])
	  .[ datetime_method_name(...) [...]] 

Following the input_val input value is the . (dot) operator and the datetime_method_name date-time method name. It follows in parenthesis a comma-separated list of method parameter expressions. Additional date-time methods can be chained thereafter.

The input value can be any expression or event property that returns a value of type long or java.util.Calendar or java.util.Date. If the input value is null, the expression result is also null.

The input value can also be an event. In this case the event type of the event must have the start timestamp property name defined and optionally also the end timestamp property name.

The following example EPL statement employs the withTime date-time method. This example returns the current engine time with the time-part set to 1 am:

select current_timestamp.withTime(1, 0, 0, 0) as time1am from MyEvent

As date-time methods can be chained, this EPL is equivalent:

select current_timestamp.set('hour', 1).set('min', 0).set('sec', 0).set('msec', 0) as time1am
from MyEvent

The statement above outputs in field time1am a long-type millisecond-value reflecting 1am on the same date as engine time. Since the input value is provided by the built-in current_timestamp function which returns current engine date as a long-type millisecond value the output is also a long-type millisecond value.

You may apply a date-time method to an event property.

Assume that the RFIDEvent event type has a Date-type property by name timeTaken. The following query rounds each time-taken value down to the nearest minute and outputs a Date-type value in column timeTakenRounded:

select timeTaken.roundFloor('min') as timeTakenRounded from RFIDEvent

You may apply a date-time method to events. This example assumes that the RFIDEvent and WifiEvent event types both have a timestamp property defined. The EPL compares the timestamps of the RFIDEvent and the WifiEvent:

select rfid.after(wifi) as isAfter 
from RFIDEvent.std:lastevent() rfid, WifiEvent.std:lastevent() wifi

For comparing date-time values and considering event duration (event start and end timestamps) we recommend any of the interval algebra methods. You may also compare millisecond values using the between or in ranges and inverted ranges or relational operators (> , <, >=, <=).

From a performance perspective, the date-time method evaluation ensures that for each unique chain of date-time methods only a single calendar objects is copied or created when necessary.

The between date-time method compares the input date-time value to the two date-time values passed in and returns true if the input value falls between the two parameter values.

The synopsis is:

input_val.between(range_start, range_end [, include_start, include_end])

The method takes either 2 or 4 parameters. The first two parameters range_start and range_end are expressions or properties that yield either a long-typed, Date-typed or Calendar-typed range start and end value.

The next two parameters include_start and include_end are optional. If not specified, the range start value and range end value are included in the range i.e. specify a closed range where both endpoints are included. If specified, the expressions must return a boolean-value indicating whether to include the range start value and range end value in the range.

The example below outputs true when the time-taken property value of the RFID event falls between the time-start property value and the time-end property value (closed range includes endpoints):

select timeTaken.between(timeStart, timeEnd) from RFIDEvent

The example below performs the same test as above but does not include endpoints (open range includes neither endpoint):

select timeTaken.between(timeStart, timeEnd, false, false) from RFIDEvent

If the range end value is less then the range start value, the algorithm reverses the range start and end value.

If the input date-time value or any of the parameter values evaluate to null the method returns a null result value.

The get date-time method returns the value of the given date-time value field.

The method takes a single string-constant field name as parameter. Please see Section 5.2.1, “Specifying Time Periods” for a list of recognized keywords (not case-sensitive).

The method returns the numeric value of the field within the date-time value. The value returned adheres to Calendar-class semantics: For example, the value for month starts at zero and has a maximum of 11.

The example below outputs the month value of the time-taken property value of the RFID event:

select timeTaken.get('month') as timeTakenMonth from RFIDEvent

The minus date-time method returns a date-time with the specified duration taken away.

The method has two versions: The first version takes the duration as a long-type millisecond value. The second version takes the duration as a time-period expression, see Section 5.2.1, “Specifying Time Periods”.

The example below demonstrates the time-period parameter to subtract two minutes from the time-taken property value of the RFID event:

select timeTaken.minus(2 minutes) as timeTakenMinus2Min from RFIDEvent

The next example is equivalent but passes a millisecond-value instead:

select timeTaken.minus(2*60*1000) as timeTakenMinus2Min from RFIDEvent

The plus date-time method returns a date-time with the specified duration added.

The method has two versions: The first version takes the duration as a long-type millisecond value. The second version takes the duration as a time-period expression, see Section 5.2.1, “Specifying Time Periods”.

The next example adds two minutes to the time-taken property value of the RFID event:

select timeTaken.plus(2 minutes) as timeTakenPlus2Min from RFIDEvent

The next example is equivalent but passes a millisecond-value instead:

select timeTaken.plus(2*60*1000) as timeTakenPlus2Min from RFIDEvent

The roundCeiling date-time method rounds to the highest whole unit of the date-time field.

The method takes a single string-constant field name as parameter. Please see Section 5.2.1, “Specifying Time Periods” for a list of recognized keywords (not case-sensitive).

The next example rounds-to-ceiling the minutes of the time-taken property value of the RFID event:

select timeTaken.roundCeiling('min') as timeTakenRounded from RFIDEvent

If the input time is 2002-05-30 09:01:23.050, for example, the output is 2002-05-30 09:02:00.000 (example timestamps are in format yyyy-MM-dd HH:mm:ss.SSS).

The roundFloor date-time method rounds to the lowest whole unit of the date-time field.

The method takes a single string-constant field name as parameter. Please see Section 5.2.1, “Specifying Time Periods” for a list of recognized keywords (not case-sensitive).

The next example rounds-to-floor the minutes of the time-taken property value of the RFID event:

select timeTaken.roundFloor('min') as timeTakenRounded from RFIDEvent

If the input time is 2002-05-30 09:01:23.050, for example, the output is 2002-05-30 09:01:00.000 (example timestamps are in format yyyy-MM-dd HH:mm:ss.SSS).

The roundFloor date-time method rounds to the nearest whole unit of the date-time field.

The method takes a single string-constant field name as parameter. Please see Section 5.2.1, “Specifying Time Periods” for a list of recognized keywords (not case-sensitive).

The next example rounds the minutes of the time-taken property value of the RFID event:

select timeTaken.roundHalf('min') as timeTakenRounded from RFIDEvent

The following table provides a few examples of the rounding (example timestamps are in format yyyy-MM-dd HH:mm:ss.SSS):


The set date-time method returns a date-time with the specified field set to the value returned by an expression.

The method takes a string-constant field name and an expression returning an integer-value as parameters. Please see Section 5.2.1, “Specifying Time Periods” for a list of recognized keywords (not case-sensitive).

The method returns the new date-time value with the field set to the provided value. Note that value adheres to Calendar-class semantics: For example, the value for month starts at zero and has a maximum of 11.

The example below outputs the time-taken with the value for month set to April:

select timeTaken.set('month', 3) as timeTakenMonth from RFIDEvent

The withMax date-time method returns a date-time with the field set to the maximum value for the field.

The method takes a string-constant field name as parameter. Please see Section 5.2.1, “Specifying Time Periods” for a list of recognized keywords (not case-sensitive).

The method returns the new date-time value with the specific date field set to the maximum value.

The example below outputs the time-taken property value with the second-part as 59 seconds:

select timeTaken.withMax('sec') as timeTakenMaxSec from RFIDEvent

The withMin date-time method returns a date-time with the field set to the minimum value for the field.

The method takes a string-constant field name as parameter. Please see Section 5.2.1, “Specifying Time Periods” for a list of recognized keywords (not case-sensitive).

The method returns the new date-time value with the specific date field set to the minimum value.

The example below outputs the time-taken property value with the second-part as 0 seconds:

select timeTaken.withMin('sec') as timeTakenMaxSec from RFIDEvent

Interval algebra methods compare start and end timestamps of events or timestamps in general.

When the expression input is only a timestamp value, such as a long-type value or a Date or Calendar object, the start and end timestamp represented by that value are the same timestamp value.

When expression input is an event stream alias, the engine determine the event type for the stream. If the event type declares a start timestamp property name, the engine uses that start timestamp property to determine the start timestamp for the event. If the event type also declares an end timestamp property name, the engine uses that end timestamp property to determine the end timestamp for the event (i.e. an event with duration). If an end timestamp property name is not declared, the start and end timestamp for each event is the same value and the event is considered to have zero duration (i.e. a point-in-time event).

Interval algebra methods all return Boolean-type value. When the input value start timestamp is null, or the end timestamp (if declared for the event type) is null or any of the start timestamp and end timestamp (if declared for the event type) values of the first parameter is null, the result value is null.

The after date-time method returns true if an event happens after another event, or a timestamp is after another timestamp.

The method compares the input value's start timestamp (a.startTimestamp) to the first parameter's end timestamp (b.endTimestamp) to determine whether A happens after B.

If used with one parameter, for example in a.after(b), the method returns true if A starts after B ends.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.after(b)
// Above matches when:
//   a.startTimestamp - b.endTimestamp > 0

If providing two parameters, for example in a.after(b, 5 sec), the method returns true if A starts at least 5 seconds after B ends.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.after(b, 5 sec)
// Above matches when:
//   a.startTimestamp - b.endTimestamp >= 5 seconds

If providing three parameters, for example in a.after(b, 5 sec, 10 sec), the method returns true if A starts at least 5 seconds but no more then 10 seconds after B ends.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.after(b, 5 sec, 10 sec)
// Above matches when:
//   5 seconds <= a.startTimestamp - b.endTimestamp <= 10 seconds

Negative values for the range are allowed. For example in a.after(b, -5 sec, -10 sec), the method returns true if A starts at least 5 seconds but no more then 10 seconds before B ends.

If the range low endpoint is greater than the range high endpoint, the engine automatically reverses them. Thus a.after(b, 10 sec, 5 sec) is the same semantics as a.after(b, 5 sec, 10 sec).

The before date-time method returns true if an event happens before another event, or a timestamp is before another timestamp.

The method compares the input value's end timestamp (a.endTimestamp) and the first parameter's start timestamp (b.startTimestamp) to determine whether A happens before B.

If used with one parameter, for example in a.before(b), the method returns true if A ends before B starts.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.before(b)
// Above matches when:
//   b.startTimestamp - a.endTimestamp > 0

If providing two parameters, for example in a.before(b, 5 sec), the method returns true if A ends at least 5 seconds before B starts.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.before(b, 5 sec)
// Above matches when:
//   b.startTimestamp - a.endTimestamp >= 5 seconds

If providing three parameters, for example in a.before(b, 5 sec, 10 sec), the method returns true if A ends at least 5 seconds but no more then 10 seconds before B starts.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.before(b, 5 sec, 10 sec)
// Above matches when:
//   5 seconds <= b.startTimestamp - a.endTimestamp <= 10 seconds

Negative values for the range are allowed. For example in a.before(b, -5 sec, -10 sec), the method returns true if A starts at least 5 seconds but no more then 10 seconds after B starts.

If the range low endpoint is greater than the range high endpoint, the engine automatically reverses them. Thus a.before(b, 10 sec, 5 sec) is the same semantics as a.before(b, 5 sec, 10 sec).

The coincides date-time method returns true if an event and another event happen at the same time, or two timestamps are the same value.

The method compares the input value's start and end timestamp with the first parameter's start and end timestamp and determines if they equal.

If used with one parameter, for example in a.coincides(b), the method returns true if the start timestamp of A and B are the same and the end timestamps of A and B are also the same.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.coincides(b)
// Above matches when:
//   a.startTimestamp = b.startTimestamp and a.endTimestamp = b.endTimestamp

If providing two parameters, for example in a.coincides(b, 5 sec), the method returns true if the difference between the start timestamps of A and B is equal to or less then 5 seconds and the difference between the end timestamps of A and B is also equal to or less then 5 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.coincides(b, 5 sec)
// Above matches when:
//   abs(a.startTimestamp - b.startTimestamp) <= 5 sec and 
//   abs(a.endTimestamp - b.endTimestamp) <= 5 sec

If providing three parameters, for example in a.coincides(b, 5 sec, 10 sec), the method returns true if the difference between the start timestamps of A and B is equal to or less then 5 seconds and the difference between the end timestamps of A and B is equal to or less then 10 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.coincides(b, 5 sec, 10 sec)
// Above matches when:
//   abs(a.startTimestamp - b.startTimestamp) <= 5 seconds and 
//   abs(a.endTimestamp - b.endTimestamp) <= 10 seconds

A negative value for interval parameters is not allowed. If your interval parameter is itself an expression that returns a negative value the engine logs a warning message and returns null.

The during date-time method returns true if an event happens during the occurrence of another event, or when a timestamps falls within the occurrence of an event..

The method determines whether the input value's start and end timestamp are during the first parameter's start and end timestamp. The symmetrical opposite is Section 12.4.11, “Includes”.

If used with one parameter, for example in a.during(b), the method returns true if the start timestamp of A is after the start timestamp of B and the end timestamp of A is before the end timestamp of B.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.during(b)
// Above matches when:
//   b.startTimestamp < a.startTimestamp <= a.endTimestamp < b.endTimestamp

If providing two parameters, for example in a.during(b, 5 sec), the method returns true if the difference between the start timestamps of A and B is equal to or less then 5 seconds and the difference between the end timestamps of A and B is also equal to or less then 5 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.during(b, 5 sec)
// Above matches when:
//   0 < a.startTimestamp - b.startTimestamp <= 5 sec and 
//   0 < a.endTimestamp - b.endTimestamp <= 5 sec

If providing three parameters, for example in a.during(b, 5 sec, 10 sec), the method returns true if the difference between the start timestamps of A and B and the difference between the end timestamps of A and B is between 5 and 10 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.during(b, 5 sec, 10 sec)
// Above matches when:
//   5 seconds <= a.startTimestamp - b.startTimestamp <= 10 seconds and 
//   5 seconds <= a.endTimestamp - b.endTimestamp <= 10 seconds

If providing five parameters, for example in a.during(b, 5 sec, 10 sec, 20 sec, 30 sec), the method returns true if the difference between the start timestamps of A and B is between 5 seconds and 10 seconds and the difference between the end timestamps of A and B is between 20 seconds and 30 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b
  where a.during(b, 5 sec, 10 sec, 20 sec, 30 sec)
// Above matches when:
//   5 seconds <= a.startTimestamp - b.startTimestamp <= 10 seconds and 
//   20 seconds < a.endTimestamp - b.endTimestamp <= 30 seconds

The finishes date-time method returns true if an event starts after another event starts and the event ends at the same time as the other event.

The method determines whether the input value's start timestamp is after the first parameter's start timestamp and the end timestamp of the input value and the first parameter are the same. The symmetrical opposite is Section 12.4.10, “Finished By”.

If used with one parameter, for example in a.finishes(b), the method returns true if the start timestamp of A is after the start timestamp of B and the end timestamp of A and B are the same.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.finishes(b)
// Above matches when:
//   b.startTimestamp < a.startTimestamp and a.endTimestamp = b.endTimestamp

If providing two parameters, for example in a.finishes(b, 5 sec), the method returns true if the start timestamp of A is after the start timestamp of B and the difference between the end timestamps of A and B is equal to or less then 5 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.finishes(b, 5 sec)
// Above matches when:
//   b.startTimestamp < a.startTimestamp and 
//   abs(a.endTimestamp - b.endTimestamp ) <= 5 seconds

A negative value for interval parameters is not allowed. If your interval parameter is itself an expression that returns a negative value the engine logs a warning message and returns null.

The finishedBy date-time method returns true if an event starts before another event starts and the event ends at the same time as the other event.

The method determines whether the input value's start timestamp happens before the first parameter's start timestamp and the end timestamp of the input value and the first parameter are the same. The symmetrical opposite is Section 12.4.9, “Finishes”.

If used with one parameter, for example in a.finishedBy(b), the method returns true if the start timestamp of A is before the start timestamp of B and the end timestamp of A and B are the same.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.finishedBy(b)
// Above matches when:
//   a.startTimestamp < b.startTimestamp and a.endTimestamp = b.endTimestamp

If providing two parameters, for example in a.finishedBy(b, 5 sec), the method returns true if the start timestamp of A is before the start timestamp of B and the difference between the end timestamps of A and B is equal to or less then 5 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.finishedBy(b, 5 sec)
// Above matches when:
//   a.startTimestamp < b.startTimestamp and 
//   abs(a.endTimestamp - b.endTimestamp ) <= 5 seconds

The includes date-time method returns true if the parameter event happens during the occurrence of the input event, or when a timestamps falls within the occurrence of an event.

The method determines whether the first parameter's start and end timestamp are during the input value's start and end timestamp. The symmetrical opposite is Section 12.4.8, “During”.

If used with one parameter, for example in a.includes(b), the method returns true if the start timestamp of B is after the start timestamp of A and the end timestamp of B is before the end timestamp of A.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.includes(b)
// Above matches when:
//   a.startTimestamp < b.startTimestamp <= b.endTimestamp < a.endTimestamp 

If providing two parameters, for example in a.includes(b, 5 sec), the method returns true if the difference between the start timestamps of A and B is equal to or less then 5 seconds and the difference between the end timestamps of A and B is also equal to or less then 5 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.includes(b, 5 sec)
// Above matches when:
//   0 < b.startTimestamp - a.startTimestamp <= 5 sec and 
//   0 < a.endTimestamp - b.endTimestamp <= 5 sec

If providing three parameters, for example in a.includes(b, 5 sec, 10 sec), the method returns true if the difference between the start timestamps of A and B and the difference between the end timestamps of A and B is between 5 and 10 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.includes(b, 5 sec, 10 sec)
// Above matches when:
//   5 seconds <= a.startTimestamp - b.startTimestamp <= 10 seconds and 
//   5 seconds <= a.endTimestamp - b.endTimestamp <= 10 seconds

If providing five parameters, for example in a.includes(b, 5 sec, 10 sec, 20 sec, 30 sec), the method returns true if the difference between the start timestamps of A and B is between 5 seconds and 10 seconds and the difference between the end timestamps of A and B is between 20 seconds and 30 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b
  where a.includes(b, 5 sec, 10 sec, 20 sec, 30 sec)
// Above matches when:
//   5 seconds <= a.startTimestamp - b.startTimestamp <= 10 seconds and 
//   20 seconds <= a.endTimestamp - b.endTimestamp <= 30 seconds

The overlaps date-time method returns true if the event starts before another event starts and finishes after the other event starts, but before the other event finishes (events have an overlapping period of time).

The method determines whether the input value's start and end timestamp indicate an overlap with the first parameter's start and end timestamp, such that A starts before B starts and A ends after B started but before B ends.

If used with one parameter, for example in a.overlaps(b), the method returns true if the start timestamp of A is before the start timestamp of B and the end timestamp of A and is before the end timestamp of B.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.overlaps(b)
// Above matches when:
//   a.startTimestamp < b.startTimestamp < a.endTimestamp < b.endTimestamp

If providing two parameters, for example in a.overlaps(b, 5 sec), the method returns true if, in addition, the difference between the end timestamp of A and the start timestamp of B is equal to or less then 5 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.overlaps(b, 5 sec)
// Above matches when:
//   a.startTimestamp < b.startTimestamp < a.endTimestamp < b.endTimestamp and 
//   0 <= a.endTimestamp - b.startTimestamp <= 5 seconds

If providing three parameters, for example in a.overlaps(b, 5 sec, 10 sec), the method returns true if, in addition, the difference between the end timestamp of A and the start timestamp of B is between 5 and 10 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.overlaps(b, 5 sec, 10 sec)
// Above matches when:
//   a.startTimestamp < b.startTimestamp < a.endTimestamp < b.endTimestamp and 
//   5 seconds <= a.endTimestamp - b.startTimestamp <= 10 seconds

The overlappedBy date-time method returns true if the parameter event starts before the input event starts and the parameter event finishes after the input event starts, but before the input event finishes (events have an overlapping period of time).

The method determines whether the input value's start and end timestamp indicate an overlap with the first parameter's start and end timestamp, such that B starts before A starts and B ends after A started but before A ends.

If used with one parameter, for example in a.overlappedBy(b), the method returns true if the start timestamp of B is before the start timestamp of A and the end timestamp of B and is before the end timestamp of A.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.overlappedBy(b)
// Above matches when:
//   b.startTimestamp < a.startTimestamp < b.endTimestamp < a.endTimestamp

If providing two parameters, for example in a.overlappedBy(b, 5 sec), the method returns true if, in addition, the difference between the end timestamp of B and the start timestamp of A is equal to or less then 5 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.overlappedBy(b, 5 sec)
// Above matches when:
//   b.startTimestamp < a.startTimestamp < b.endTimestamp < a.endTimestamp and 
//   0 <= b.endTimestamp - a.startTimestamp <= 5 seconds

If providing three parameters, for example in a.overlappedBy(b, 5 sec, 10 sec), the method returns true if, in addition, the difference between the end timestamp of B and the start timestamp of A is between 5 and 10 seconds.

Sample EPL:

select * from A.std:lastevent() as a, B.std:lastevent() as b where a.overlappedBy(b, 5 sec, 10 sec)
// Above matches when:
//   b.startTimestamp < a.startTimestamp < b.endTimestamp < a.endTimestamp and 
//   5 seconds <= b.endTimestamp - a.startTimestamp <= 10 seconds