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;
}