Skip to content

The search box in the website knows all the secrets—try it!

For any queries, join our Discord Channel to reach us faster.

JasperFx Logo

JasperFx provides formal support for Marten and other JasperFx libraries. Please check our Support Plans for more details.

Noda Time Support

Noda Time is an alternative date and time API for .NET. It was written by Jon Skeet to solve many flaws of original .NET api. Since version 4.0 Npgsql supports and suggests it as recommended way of working with Date and Time.

See more in:

Setup

Marten provides Marten.NodaTime plugin. That provides necessary setup.

Install it through the Nuget package.

powershell
PM> Install-Package Marten.NodaTime

Then call UseNodaTime() method in your DocumentStore setup:

cs
var store = DocumentStore.For(_ =>
{
    _.Connection(ConnectionSource.ConnectionString);

    // sets up NodaTime handling
    _.UseNodaTime();
});

snippet source | anchor

By default it also sets up the JsonNetSerializer or SystemTextJsonSerializer options (see more details in NodaTime documentation).

If you're using custom Json serializer or you'd like to maintain fully its configuration then you can set disable default configuration by setting shouldConfigureJsonSerializer parameter to false. By changing this setting you need to configure NodaTime Json serialization by yourself.

cs
var store = DocumentStore.For(_ =>
{
    _.Connection(ConnectionSource.ConnectionString);

    _.Serializer<CustomJsonSerializer>();

    // sets up NodaTime handling
    _.UseNodaTime(shouldConfigureJsonSerializer: false);
});

snippet source | anchor

WARNING

By using NodaTime plugin - you're opting out of DateTime type handling. Using DateTime in your Document will end up getting NotSupportedException exception.

If you customize the Marten default serialization using UseDefaultSerialization(...), call UseNodaTime() only after UseDefaultSerialization(...) to ensure proper configuration of NodaTime serialization.

Released under the MIT License.