Portable.System.DateTimeOnly 9.0.0

Build Codacy Grade Codacy Coverage PVS-Studio Sponsors

Logo Portable.System.DateTimeOnly

The .NET 6 introduced two new data types System.DateOnly and System.TimeOnly that can be used in various scenarios. If you want to use the same types in the .NET versions below to .NET 6 you can use this library in form of the NuGet package. You can also use it in your own NuGet package if you want to provide an API that uses these types and make it compatible with all currently supported .NET versions at the same time.

String Parsing Performance

The original version of this package used the simplified string parsing approach - it just reuses the default System.DateTime parsing logic as is. It works well in most use cases but parsing behavior was not matched 100% to the .NET 6 System.DateOnly and System.TimeOnly data types. Their raise the System.FormatException exception in case if the input string contains the time part for the System.DateOnly or the date part in the case of System.TimeOnly types.

Unfortunately, this behavior in .NET 6 implementation depends heavily on an internal parser that provides a lot more information about parsing results than a public version of parsing API. Porting this parser required porting a lot of culture-specific code and looks unpractical for such a simple package. So another approach selected for solving this issue - double parsing using System.DateTime.TryParseExact method with proper formatting strings.

This approach, of course, has an obvious disadvantage - in some cases, we have to parse the same string twice. If performance is critical for you and you are OK with the incorrect parsing results in some rare cases you can restore the original behavior using the application context switch named Portable.System.DateTimeOnly.UseFastParsingLogic. Check the FastStrictParsingLogicTests for more examples for this issue.

The System.Text.Json Support

You can use helper NuGet package Portable.System.DateTimeOnly.Json with the System.Text.Json for enabling cross-framework JSON serialization of System.DateOnly and System.TimeOnly data types in your code.

Contributors

Thanks a lot for all contributors. See the full list of project supporters in the CONTRIBUTORS file.

SAST Tools

This project uses PVS-Studio - static analyzer for C, C++, C#, and Java code.

Showing the top 20 packages that depend on Portable.System.DateTimeOnly.

Packages Downloads
Ical.Net
The most popular iCalendar (RFC 5545) class library for .NET.
1

- The `System.DateOnly` and `System.TimeOnly` source codes have been updated to the latest .NET 9.0 sources (with required adjustments).

.NET Framework 4.6.2

.NET 6.0

  • No dependencies.

.NET Standard 2.0

.NET Standard 2.1

  • No dependencies.

Version Downloads Last updated
9.0.0 1 03/04/2025
9.0.0-beta1 1 03/04/2025
8.0.2 1 03/04/2025
8.0.1 1 03/04/2025
8.0.0 1 03/04/2025
7.0.1 1 03/04/2025
7.0.0 1 03/04/2025
6.0.3 1 03/04/2025
6.0.2 1 03/04/2025
6.0.1 1 03/04/2025
6.0.0 1 03/04/2025