Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement serializer for Offset #10

Closed
Tolyandre opened this issue Jun 1, 2020 · 2 comments
Closed

Implement serializer for Offset #10

Tolyandre opened this issue Jun 1, 2020 · 2 comments

Comments

@Tolyandre
Copy link
Contributor

Hey, I am working on a project that uses this library. The library actually is great. Are there any plans to implement a serializer for Offset?

I checked using this code, it currently produces an empty object:

using System;
using MongoDB.Bson;
using MongoDb.Bson.NodaTime;
using NodaTime;

namespace TestOffset
{
    class Data
    {
        public Offset Offset { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            NodaTimeSerializers.Register();

            var data = new Data
            {
                Offset = Offset.FromHours(4),
            };

            Console.WriteLine(data.ToBsonDocument()); // { "Offset" : { } }
        }
    }
}
@tetious
Copy link
Collaborator

tetious commented Jun 1, 2020

Hi! I'm glad it is working well for you.

Adding support for Offset should be fairly straightforward, as there is a serialization pattern for it in NodaTime.Text. (https://nodatime.org/3.0.x/api/NodaTime.Text.OffsetPattern.html)

We already have a base class that wraps things nicely, and using that might make it Just Work(TM). See DurationSerializer.cs for an example.

I'd happily accept a PR if you want to take a stab at it. :)

@tetious
Copy link
Collaborator

tetious commented Jun 3, 2020

Thanks for the PR and the build fix! This is pushed to nuget as 2.1.0.

@tetious tetious closed this as completed Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants