reactiveui / Akavache

An asynchronous, persistent key-value store created for writing desktop and mobile applications, based on SQLite3. Akavache is great for both storing important data as well as cached local data that expires.
https://evolve.xamarin.com/session/56e2044afd00c0253cae33a3
MIT License
2.44k stars 288 forks source link

[Bug]: `ForcedDateTimeKind` not working #933

Open markuspalme opened 4 months ago

markuspalme commented 4 months ago

Describe the bug 🐞

When reading back a DateTimewith kind Unspecified and ForcedDateTimeKind = DateTimeKind.Unspecified, the resulting date has kind Utc and has has been converted to UTC which is unexpected.

Step to reproduce

Run this code:

using Akavache;
using System.Reactive.Linq;

BlobCache.ForcedDateTimeKind = DateTimeKind.Unspecified;
BlobCache.ApplicationName = "myapp";
BlobCache.EnsureInitialized();

var testDate = new DateTime(2024, 10, 10, 10, 10, 0, 0, DateTimeKind.Unspecified);

await BlobCache.LocalMachine.InsertObject("test", testDate);

var readBack = await BlobCache.LocalMachine.GetObject<DateTime>("test");

Console.WriteLine(testDate.ToLongTimeString() + ", " + testDate.Kind);
Console.WriteLine(readBack.ToLongTimeString() + ", " + readBack.Kind);

Reproduction repository

https://github.com/reactiveui/ReactiveUI

Expected behavior

The date that is read from the cache should be the same (same value and kind) as the one that is inserted.

Screenshots 🖼️

image

IDE

No response

Operating system

MacOS, iOS

Version

10.0.1

Device

No response

ReactiveUI Version

No response

Additional information ℹ️

No response

markuspalme commented 4 months ago

Verified the behaviour on MacOS and iOS (net8-ios TFM).

markuspalme commented 4 months ago

Maybe this has the same cause as #787.

I could work on a fix, but would like to have confirmation that the current behavior is indeed not the expected one first.

corne-ac commented 1 month ago

Currently having this issue, we get a json from an API, convert into an object, and store that in this dataservice. The received date is ex 10:36:40, and the second time we get the data, it gets retrieved from the BlobCache, it gets returned as 08:36:40. Tried all the various ForcedDateTimeKind settings.