# GROUP\_BY\_TIME

### Description

Converts *vector* to a *grouped vector*, by gouping by timespans, so that we have a list of events per timespan. The timespan either is fixed on the latest event, or can be fixed on another time if specified.

### GROUP\_BY\_TIME(Vector\<Event>, Scalar\<Timespan>)

```java
GROUP_BY_TIME(vector: Vector<Event>, timespan: Scalar<Timespan>): GroupedVector<Time,Event>
```

Groups the events in the given vector in spans defined by timespan, starting from the latest event.

#### Parameters

<table><thead><tr><th width="172">Parameter</th><th>Description</th></tr></thead><tbody><tr><td>vector</td><td>A vector of type Event</td></tr><tr><td>timespan</td><td>A timespan in which the events should be grouped</td></tr></tbody></table>

#### Returns

A GroupedVector of type \<Time, Event>.

### GROUP\_BY\_TIME(Vector\<Event>, Scalar\<Timespan>, Scalar\<Time>)

```java
GROUP_BY_TIME(vector: Vector<Event>, timespan: Scalar<Timespan>, time: Scalar<Time>): GroupedVector<Time,Event>
```

Group the vector in the given timespans starting at the given time.

#### Parameters

<table><thead><tr><th width="172">Parameter</th><th>Description</th></tr></thead><tbody><tr><td>vector</td><td>A vector of type Event</td></tr><tr><td>timespan</td><td>A timespan in which the events should be grouped</td></tr><tr><td>time</td><td> The time form which we want to start grouping.</td></tr></tbody></table>

#### Returns

A GroupedVector of type \<Time, Event>.

### Examples

Group events in 1h spans starting from latest event

```java
GROUP_BY_TIME($GridPowerConsumption, 1h)
```

Group events in 1d spans on full day spans (i.e. 00:00-23:59)

```java
GROUP_BY_TIME($Produced, 1d, lastZeroHour)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.moost.io/platform-manual/rules/rule-language/functions/group_by_time.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
