LfrlAnvil.Chrono 0.6.1

dotnet add package LfrlAnvil.Chrono --version 0.6.1
                    
NuGet\Install-Package LfrlAnvil.Chrono -Version 0.6.1
                    
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="LfrlAnvil.Chrono" Version="0.6.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LfrlAnvil.Chrono" Version="0.6.1" />
                    
Directory.Packages.props
<PackageReference Include="LfrlAnvil.Chrono" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LfrlAnvil.Chrono --version 0.6.1
                    
#r "nuget: LfrlAnvil.Chrono, 0.6.1"
                    
#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.
#:package LfrlAnvil.Chrono@0.6.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LfrlAnvil.Chrono&version=0.6.1
                    
Install as a Cake Addin
#tool nuget:?package=LfrlAnvil.Chrono&version=0.6.1
                    
Install as a Cake Tool

(root) NuGet Badge

<img src="https://raw.githubusercontent.com/CalionVarduk/LfrlAnvil/main/assets/logo-small.png" alt="logo" height="80"/> LfrlAnvil.Chrono

This project contains functionalities related to date & time, as well as timezones. Most of them work directly on dotnet's DateTime and TimeZoneInfo types.

Documentation

Technical documentation can be found here.

Examples

Following are a few examples of date & time structures:

// creates a new timestamp provider
var timestamps = new TimestampProvider();

// returns the current timestamp, which represents the number of ticks elapsed since unix epoch
var timestamp = timestamps.GetNow();

// target timezone
var timezone = TimeZoneInfo.FindSystemTimeZoneById( ... );

// creates a new zoned date time provider, with the desired timezone
var clock = new ZonedClock( timezone );

// returns the current date & time, in the clock's timezone
var datetime = clock.GetNow();

// adds a duration to datetime
// duration represents elapsed time in ticks
var a = datetime + Duration.FromHours( 2 );

// adds a period to datetime
// period represents elapsed time in calendar-related chronological units, such as years, months etc.
var b = datetime + Period.FromMonths( 1 ).AddWeeks( 2 ).AddMinutes( 420 );

// sets a time of day of datetime to 12:00:00
var c = datetime.SetTimeOfDay( TimeOfDay.Mid );

// extracts a zoned day instance from datetime
// there are also other zoned objects, such as year, month and week
var day = datetime.GetDay();

This project also includes implementations of caches, whose entries have a limited lifetime:

// creates a new timestamp provider
var timestamps = new TimestampProvider();

// timestamp of the creation of cache
var start = timestamps.GetNow();

// creates a new empty cache with 'string' key and 'int' value, with entry lifetime equal to '2 minutes'
var cache = new LifetimeCache<string, int>( startTimestamp: start, lifetime: Duration.FromMinutes( 2 ) );

// adds an entry to the cache, whose lifetime ends at 'start + 2 minutes'
cache.AddOrUpdate( "foo", 42 );

// moves the cache's current timestamp forward by '30 seconds', to 'start + 30 seconds' timestamp
// this means that the 'foo' entry has '1 minute and 30 seconds' left
cache.Move( Duration.FromSeconds( 30 ) );

// gets the value associated with 'foo' key, which should return 42
// this also resets entry's lifetime back to '2 minutes',
// which means that it will now be removed at 'start + 2 minutes and 30 seconds' timestamp
var foo = cache["foo"];

// moves the cache's current timestamp forward by '2 minutes', to 'start + 2 minutes and 30 seconds' timestamp
// this will also remove the 'foo' entry from cache
cache.Move( Duration.FromMinutes( 2 ) );

// checks whether the 'foo' entry exits, should return false
var exists = cache.ContainsKey( "foo" );

There also exists a version of lifetime cache that allows to set each entry's lifetime individually.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on LfrlAnvil.Chrono:

Package Downloads
LfrlAnvil.Identifiers

This project contains a generator of sequential 64-bit identifiers based on a timestamp.

LfrlAnvil.Reactive.Chrono

This project contains a few functionalities related to timers and schedulers.

LfrlAnvil.MessageBroker.Client

This project contains client-side message broker implementation.

LfrlAnvil.MessageBroker.Server

This project contains server-side message broker implementation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.6.1 151 5/18/2026
0.6.0 154 5/16/2026
0.5.1 177 5/18/2026
0.5.0 184 5/16/2026
0.4.0 222 3/14/2026
0.3.0 246 1/7/2025
0.2.1 287 6/16/2024
0.2.0 249 6/16/2024
0.1.1 280 5/29/2024
0.1.0 244 5/26/2024