Akavache icon indicating copy to clipboard operation
Akavache copied to clipboard

[Bug]: `ForcedDateTimeKind` not working

Open markuspalme opened this issue 1 year ago • 4 comments

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 avatar May 28 '24 10:05 markuspalme

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

markuspalme avatar May 28 '24 10:05 markuspalme

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.

markuspalme avatar May 28 '24 10:05 markuspalme

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.

corne-ac avatar Aug 26 '24 10:08 corne-ac

A workaround I found is to set ForcedDateTimeKind on each instance of IBlobCache I'm using in my app.
Thus: BlobCache.LocalMachine.ForcedDateTimeKind = DateTimeKind.Unspecified;

In my particular use case, I had to use DateTimeKind.Local, so this is what I used:

// Somewhere in the OnStartup() block
BlobCache.UserAccount.ForcedDateTimeKind = DateTimeKind.Local;

johnug avatar Jan 16 '25 02:01 johnug