# RunTimeSeriesBucketing

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.runtimeseriesbucketing/
> Summary: RunTimeSeriesBucketing: The shared pure logic for time-series bucket computation. Both InMemoryRunStore and PostgresRunStore use this type, so the bucket limit and rounding rules never.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

The shared pure logic for time-series bucket computation. Both
`InMemoryRunStore` and `PostgresRunStore` use this type, so the
bucket limit and rounding rules never diverge between the two stores.

```csharp
public static class RunTimeSeriesBucketing
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.runtimeseriesbucketing/">RunTimeSeriesBucketing</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Fields

### <a id="Tracon_RunTimeSeriesBucketing_MaxBuckets"></a> MaxBuckets

The maximum number of buckets a query may produce.

```csharp
public const int MaxBuckets = 500
```

#### Field Value

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

## Methods

### <a id="Tracon_RunTimeSeriesBucketing_StepFor_Tracon_TimeSeriesBucket_"></a> StepFor\(TimeSeriesBucket\)

Returns a bucket's width.

```csharp
public static TimeSpan StepFor(TimeSeriesBucket bucket)
```

#### Parameters

`bucket` [TimeSeriesBucket](/api/tracon.timeseriesbucket/)

#### Returns

 [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan)

### <a id="Tracon_RunTimeSeriesBucketing_Truncate_System_DateTimeOffset_Tracon_TimeSeriesBucket_"></a> Truncate\(DateTimeOffset, TimeSeriesBucket\)

Rounds a timestamp down to the bucket boundary (UTC).

```csharp
public static DateTimeOffset Truncate(DateTimeOffset value, TimeSeriesBucket bucket)
```

#### Parameters

`value` [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

`bucket` [TimeSeriesBucket](/api/tracon.timeseriesbucket/)

#### Returns

 [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

### <a id="Tracon_RunTimeSeriesBucketing_Validate_System_DateTimeOffset_System_DateTimeOffset_Tracon_TimeSeriesBucket_"></a> Validate\(DateTimeOffset, DateTimeOffset, TimeSeriesBucket\)

Validates that the requested range and bucket width does not exceed [RunTimeSeriesBucketing.MaxBuckets](/api/tracon.runtimeseriesbucketing/#Tracon_RunTimeSeriesBucketing_MaxBuckets).

```csharp
public static void Validate(DateTimeOffset from, DateTimeOffset to, TimeSeriesBucket bucket)
```

#### Parameters

`from` [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

`to` [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

`bucket` [TimeSeriesBucket](/api/tracon.timeseriesbucket/)

#### Exceptions

 [TraconException](/api/tracon.traconexception/)

The range exceeds the maximum number of buckets.
