IntelligentPlant.Relativity.AspNetCore 2.0.0

dotnet add package IntelligentPlant.Relativity.AspNetCore --version 2.0.0                
NuGet\Install-Package IntelligentPlant.Relativity.AspNetCore -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IntelligentPlant.Relativity.AspNetCore" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IntelligentPlant.Relativity.AspNetCore --version 2.0.0                
#r "nuget: IntelligentPlant.Relativity.AspNetCore, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install IntelligentPlant.Relativity.AspNetCore as a Cake Addin
#addin nuget:?package=IntelligentPlant.Relativity.AspNetCore&version=2.0.0

// Install IntelligentPlant.Relativity.AspNetCore as a Cake Tool
#tool nuget:?package=IntelligentPlant.Relativity.AspNetCore&version=2.0.0                

IntelligentPlant.Relativity.AspNetCore

This package provides ASP.NET Core middleware for setting RelativityParser.Current for an HTTP request. This allows timestamps and durations to be parsed anywhere in the request using RelativityParser.Current.

Getting Started

Registering Time Zone Providers

The middleware uses time zone providers (derived from TimeZoneProvider) to determine the time zone to use when configuring the Relativity parser for the request. Use the extension methods defined in RelativityBuilderExtensions to register time zone providers for the middleware:

services.AddRelativity()
    // Set time zone using 'tz' query string parameter
    .AddQueryStringTimeZoneProvider()
    // Set time zone using 'X-TimeZone' request header
    .AddRequestHeaderTimeZoneProvider();

The middleware will use the first time zone provider that returns a valid time zone. If no time zone provider returns a valid time zone, UTC will be used. The order of precedence for the time zone providers from most-specific to least-specific is as follows:

  • Custom time zone providers, in registration order
  • Query string
  • Cookie
  • Request header
  • User claim

Registering the Middleware

To register the middleware, use the UseRelativity() extension method for the IApplicationBuilder class:

app.UseRelativity();

If you are using request localization, you should register the middleware after the request localization middleware to ensure that the culture for the request is set before the Relativity parser is configured:

app.UseRequestLocalization();
app.UseRelativity();

Using the Parser

You can access the parser for the current request using RelativityParser.Current. For example:

var dt = RelativityParser.Current.ConvertToUtcDateTime("DAY+6H");
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 77 10/22/2024
2.0.0-pre.13 50 10/21/2024
2.0.0-pre.12 54 10/21/2024
2.0.0-pre.11 67 3/1/2024
2.0.0-pre.10 58 2/29/2024
2.0.0-pre.9 54 2/29/2024
2.0.0-pre.8 52 2/29/2024
2.0.0-pre.7 66 2/29/2024
2.0.0-pre.4 51 2/29/2024
2.0.0-pre.3 54 2/28/2024