Soenneker.Extensions.DateTimeOffsets.Hours 11.0.190

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Extensions.DateTimeOffsets.Hours --version 11.0.190
                    
NuGet\Install-Package Soenneker.Extensions.DateTimeOffsets.Hours -Version 11.0.190
                    
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="Soenneker.Extensions.DateTimeOffsets.Hours" Version="11.0.190" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Extensions.DateTimeOffsets.Hours" Version="11.0.190" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Extensions.DateTimeOffsets.Hours" />
                    
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 Soenneker.Extensions.DateTimeOffsets.Hours --version 11.0.190
                    
#r "nuget: Soenneker.Extensions.DateTimeOffsets.Hours, 11.0.190"
                    
#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 Soenneker.Extensions.DateTimeOffsets.Hours@11.0.190
                    
#: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=Soenneker.Extensions.DateTimeOffsets.Hours&version=11.0.190
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Extensions.DateTimeOffsets.Hours&version=11.0.190
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Extensions.DateTimeOffsets.Hours

Provides fixed-offset hour boundaries, local-hour formatting, and hour-of-day conversion between UTC and named time zones.

Installation

dotnet add package Soenneker.Extensions.DateTimeOffsets.Hours

Hour boundaries

using Soenneker.Extensions.DateTimeOffsets.Hours;

DateTimeOffset value = new(2026, 8, 29, 16, 42, 30, TimeSpan.FromHours(-4));

DateTimeOffset start = value.ToStartOfHour();
DateTimeOffset end = value.ToEndOfHour();
DateTimeOffset previousStart = value.ToStartOfPreviousHour();
DateTimeOffset nextEnd = value.ToEndOfNextHour();
Method Result for 16:42:30
ToStartOfHour() 16:00:00
ToEndOfHour() One tick before 17:00:00
ToStartOfPreviousHour() 15:00:00
ToEndOfPreviousHour() One tick before 16:00:00
ToStartOfNextHour() 17:00:00
ToEndOfNextHour() One tick before 18:00:00

These methods preserve the stored offset and use fixed elapsed hours. They do not consult a named time zone or reinterpret repeated/skipped local clock hours.

Format an hour

string storedClock = value.ToHourFormat();

TimeZoneInfo eastern = TimeZoneInfo.FindSystemTimeZoneById("America/New_York");
string easternClock = value.ToTzHourFormat(eastern);
string easternHour = value.ToTzHourFormatWithTrim(eastern);

All three methods use h:mm tt with the current culture. ToHourFormat() formats the stored clock fields. ToTzHourFormat() first converts the instant to the target zone. ToTzHourFormatWithTrim() also resets local minutes and seconds to zero.

Convert a UTC hour to local time

DateTimeOffset reference = new(2026, 8, 29, 12, 0, 0, TimeSpan.Zero);

int localHour = reference.ToTzHoursFromUtc(utcHour: 18, eastern);
string localClock = reference.ToTzHourFormatFromUtc(utcHour: 18, eastern);

Both methods combine utcHour with the UTC date of reference, then convert that instant to the target zone. The integer method returns only 0–23; it discards the local date and minutes. The formatted method preserves fractional-hour offsets such as 5:30 AM.

Convert a local hour to UTC

int utcHour = reference.ToUtcHoursFromTz(tzHour: 9, eastern);

ToUtcHoursFromTz() chooses the local date in eastern that contains reference, interprets tzHour on that date, and returns only the UTC hour from 0 through 23.

If the local wall time is invalid, it advances minute-by-minute to the first valid minute. If it is ambiguous, it selects the earlier UTC instant. The returned integer does not include UTC date rollover or minutes; use a full-instant API when those details matter.

Hour arguments must be from 0 through 23.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Extensions.DateTimeOffsets.Hours:

Package Downloads
Soenneker.Extensions.DateTimeOffsets.Suite

A collection of all of the helpful DateTimeOffset extension methods

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.193 0 12/2/2026
11.0.192 0 12/2/2026
11.0.190 43 12/2/2026
11.0.189 77 12/1/2026
11.0.188 55 12/1/2026
11.0.187 60 12/1/2026
11.0.186 66 12/1/2026
11.0.185 60 12/1/2026
11.0.184 68 11/30/2026
11.0.183 91 11/30/2026
11.0.182 264 11/19/2026
11.0.180 104 11/18/2026
11.0.178 115 11/18/2026
11.0.177 107 11/18/2026
11.0.176 166 11/15/2026
11.0.175 184 11/15/2026
11.0.173 226 11/11/2026
11.0.172 124 11/11/2026
11.0.171 123 11/11/2026
Loading failed

Updated Soenneker.Extensions.DateTimeOffsets to 11.0.220