DateTimeOffset in EmbeddedObjects not written to database correctly

I’m loading a set of new records into a Realm database, which all is working as it should, except for the DateTimeOffset datatype property in an EmbeddedObject in the RealmObject (the property member in the RealmObject is a List).

Below is the classes I’m using to load and write to the Realm. I was chasing my tail and reading lots of documentation about the DateTimeOffset and how Realm stores it and thinking I misunderstood or overlooked something until I tested it by adding a DateTimeOffset to the RealmObject itself and seeing it worked fine.

But, where I’m loading and storing in the EmbeddedIObject DateTimeOffset the incorrect value “0001-01-01T00:00:00.000+00:00” is always what ends up in the Realm database no matter what it might be set to by my code.

I added a DateTimeObject as a test to the RealmObject and it is working as expected, only the behavior in the List of EmbeddedObject(s) is storing the incorrect value.

I’m not sure if the problem is related to it being an EmbeddedObject kept as a List in the RealmObject or just a problem with the EmbeddedObject handing DateTimeOffsets.

public class Event_Date : EmbeddedObject
{
[MapTo(“start_date”)]
public DateTimeOffset Start_Date { get; set; }

    [MapTo("end_date")]
    public DateTimeOffset End_Date { get; set; }

}

public class A : RealmObject
{
    [PrimaryKey]
    [MapTo("_id")]
    public ObjectId Id { get; set; } = ObjectId.GenerateNewId();

    [MapTo(Constants.Partition)]
    [Required]
    public string Partition { get; set; } = Constants.Partition;

    [MapTo("name")]
    public string Name { get; set; }

    [MapTo("event_dates")]
    public IList<Event_Date> Event_Dates { get; }

    [MapTo("test_date")]
    public DateTimeOffset now { get; set; } = DateTimeOffset.Now;

}

of course, after putting this here, at a meeting 2 hours later, I find the problem is on my end, with a missing underscore typo that propagated via the person building the JSON file I was loading. the missing underscore for the DateTimeOffset field was used to copy/paste/edit new records incorrectly and here we are now, problem found! Consider this not an issue, just stupid.

We’re glad you found the issue.

You could consider marking this thread as resolved, thank you.

Have a good day.

Andrea

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.