Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
This repository was archived by the owner on May 15, 2024. It is now read-only.

Preferences needs overloads for DateTime #192

@jonathanpeppers

Description

@jonathanpeppers

Description

I ported usage of Xam.Plugin.Settings to Xamarin.Essentials.Preferences in the Evolve 2016 app.

For the most part, the new Preferences class is exactly backwards compatible when loading existing data stored (good job!).

However, we are missing an overload for DateTime, for example I had to do:

public DateTime LastFavoriteTime
{
    get { return new DateTime(Preferences.Get(LastFavoriteTimeKey, DateTime.UtcNow.Ticks)); }
    set { Preferences.Set(LastFavoriteTimeKey, value.Ticks); }
}

It might not be clear for a developer to use a long, I first attempted string and got the following on Android:

Java.Lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String

It might also be worth writing some tests that change the data types and see what the current behavior is?

Steps to Reproduce

  1. Port an app from using Xam.Plugin.Settings to Xamarin.Essentials.Preferences, with existing saved settings
  2. Try to Get/Set DateTime values

Expected Behavior

There should be an overload for DateTime.

Actual Behavior

Code to convert to/from a long is required.

Basic Information

  • Version with issue: 0.0.1.79-preview

Reproduction Link

Commit here.

Metadata

Metadata

Assignees

Labels

proposalProposed feature or enhancement.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions