Date-Field from CouchbaseServer cannot be parsed with Couchbase.Lite


#1

Hello,

I think there is some bug in the .NET Couchbase.Lite library when parsing dates.

To reproduce this, synchronize a CBL-Database with a full Couchbase server and create the same objects on both endpoints (CBL+CBS).

If you create a date in the CBL-DB with the MutableDocument.SetDate - method, after synchronizing, the date is stored in the following format:

      "date": "2018-05-16T00:00:00.0000000+02:00"

If you create a date directly on the server with the following code, the result will be:

       "date": "2018-03-17T00:00:00+01:00".

To directly access the server, I use this method:

    var document = new Document<dynamic>
    {
        Id = Guid.NewGuid().ToString("N"),
        Content = new SomeObject
        {
            Date = DateTimeOffset.Now
        }
    };

The problem arises when the server-created-objects are synchronized to the CBL-DB.
Any dates created on the server which are parsed with the IDictionaryObject.GetDate - method will always result in DateTimeOffset.MinValue.

A possible workaround for this bug is this:

DateTimeOffset.Parse(result.GetString(i.Key))

I’m using CouchbaseNetClient 2.5.10 and Couchbase.Lite 2.0.0.1


#2

Hi @thomas.maisel - thanks for the report, @borrrden may be able to help you.

PS I formatted your code example to help readability.


#3

Couchbase Lite .NET will parse the datetime using the “o” format for the .NET DateTime object. If that doesn’t parse correctly, then you will end up with the minimum value as a “default” of sorts. It looks like that format is more strict than I realized as shown in this fiddle. The fractional portions are non-optional.