# Time concepts and operators

## Time elements

### Instant

All queries through the system have an Instant used as the **Reference Time**, usually the Time Machine instant.

### Rhythm

Defined by an Origin Instant and a Period used to build the Interval occurrences of the Rhythm.

Origin Instant is usually EPOCH (1970-01-01 00:00:00), but can be different for example to define business days.

### Interval

An interval can be obtained through different means:

- From a
**Rhythm**, selecting the occurence that intersect the Reference Time. - From a
**Time Range**, defining a period relative to the Reference Time. - From an
**Entity or Member Lifecycle**that directly corresponds to an Interval.

By default intervals are inclusive of their first Instant I1 and exclusive of the last Instant I2 of their definition : [I1, I2)

## Time calculations

### Time Shift

A Time Shift uses an Instant and computes another Instant using a Period (X minutes, X hours, X days, etc.)

### Time Range

A Time Range uses an Instant and computes an Interval using a Period (X minutes, X hours, X days, etc.)

### Time Join

A Time Join is a join condition between two intervals, one being usually a dimension representing time and the other being a data to project on that time dimension.

The output can either :

- directly used to project the data selected with the Time Join for display or as input for a computing,
- used to project another data relative to this Time Join Result, therefore used as a dimension retaining time information from the two sources of the Time Join.

It is applied between two Intervals INT1 corresponding to the Data and INT2 corresponding to the Dimension.

In the special case when INT2 is an Instant, then the only valid Time Join is INTERSECT.

**Time Join table:**

INTERSECT |
INT1 intersects INT2. |
---|---|

BEGIN_DURING |
INT1 begins during INT2. |

END_DURING |
INT1 ends during INT2. |

CURRENT_AT_BEGIN |
INT1 exists at beginning of INT2. |

CURRENT_AT_END |
INT1 exists at end of INT2. |

INCLUDED_IN |
INT1 is included into INT2. |

OVERLAPS |
INT1 includes INT2. |

### Time Interest

A Time Interest is used to extract Instants or Intervals from Time Join Results that contain composite time information from the two sources of the Time Join.

The Time Join has been applied between a Interval INT1 (Data) and another Interval INT2 (Dimension).

If INT2 is an instant, then only Time Interests marked with (*) are valid.

**Time Interest table:**

AT_DATA_CREATION (*) |
Instant at beginning of INT1. |
---|---|

AT_DATA_DELETION (*) |
Instant at end of INT1. |

AT_DIMENSION_BEGIN (*) |
Instant at beginning of INT2. |

AT_DIMENSION_END |
Instant at end of INT2. |

AT_YOUNGEST_DATA_IN_DIMENSION |
First Instant where INT1 and INT2 intersect. |

AT_OLDEST_DATA_IN_DIMENSION |
Last Instant where INT1 and INT2 intersect. |

INTERSECTION |
Interval that is the intersection of INT1 and INT2. |

DATA_INTERVAL (*) |
Equivalent to the interval INT1. |

DIMENSION_INTERVAL |
Equivalent to the interval INT2. |

DATA_INTERVAL_UNTIL_DIMENSION |
Equivalent to the interval between the instant defined by AT_DATA_CREATION and the instant defined by AT_OLDEST_DATA_IN_DIMENSION |

## Slides on time operators