Couchbase lite 2.0 DB21, supported types

Which data types are supported by Couchbase Lite 2.0? Is DateTime supported?

When I try to save a document containing a DateTime object I’m getting:

System.InvalidCastException : Cannot encode System.DateTime to Fleece!

Thanks.

I had to parse it to DateTimeOffset, something like this ( new DateTimeOffset(DateTime.Parse(“2/9/2018”)).ToString(); ) kind of annoying, but it works…

Which platform are you asking about ?

Android Supports Date
iOS should support NSDate
.Net uses DateTimeOffset

1 Like

Why not just use DateTimeOffset.Parse() directly instead? Or if you have an existing DateTime you can simply construct DateTimeOffset via new DateTimeOffset(dateTimeInstance). DateTime is a lacking type because it only has two settings for how the time information is interpreted (UTC vs “local”, and “local” depends on the time zone of the device executing the program which can cause unexpected behavior for types dealing with expiration). Worst of all, usually the programmer will not define this and the type will end up as “undefined” in which case all we can do is guess about what the real time you wanted to pass in is. DateTimeOffset also stores the offset from UTC as part of the structure so that we can easily serialize to ISO 8601 format and guarantee that the time is nonambiguous.

If you are confused about which types we support, look no further then the API itself. It has type-safe equivalent setters such as SetString() and in this case SetDate(). If you don’t see a type specific setter, then it’s likely not a supported type.

For us the annoyance comes from the fact that some of our documents come from Sql Server via old xml web service and serialization/deserialization in NET does not support DateTimeOffset, and since we use UTC by convention everywhere it’s just an extra parsing step, especially if I recall correctly DateTime worked fine in previous versions… But regardless, it’s not a big deal, we can work with it.

---- Jim Borden wrote ----

[https://sea2.discourse-cdn.com/couchbase/user_avatar/forums.couchbase.com/borrrden/45/540_1.png] borrrdenhttps://forums.couchbase.com/u/borrrden Couchbase
February 10

Why not just use DateTimeOffset.Parse() directly instead? Or if you have an existing DateTime you can simply construct DateTimeOffset via new DateTimeOffset(dateTimeInstance). DateTime is a lacking type because it only has two settings for how the time information is interpreted (UTC vs “local”, and “local” depends on the time zone of the device executing the program which can cause unexpected behavior for types dealing with expiration). Worst of all, usually the programmer will not define this and the type will end up as “undefined” in which case all we can do is guess about what the real time you wanted to pass in is. DateTimeOffset also stores the offset from UTC as part of the structure so that we can easily serialize to ISO 8601 format and guarantee that the time is nonambiguous.

If you are confused about which types we support, look no further then the API itself. It has type-safe equivalent setters such as SetString() and in this case SetDate()http://docs.couchbase.com/mobile/2.0/couchbase-lite-net/db022/html/M_Couchbase_Lite_IMutableArray_SetDate.htm. If you don’t see a type specific setter, then it’s likely not a supported type.