iluvadev / PocketBaseClient

C# client to interact with a particular PocketBase application: an ORM mapped to your PocketBase server. [This project is in active development. The things described below could change]
MIT License
43 stars 8 forks source link

Updating Date writes values back as null #48

Open GZeroCoder opened 1 month ago

GZeroCoder commented 1 month ago

Using the generated code to write back records and update records to a table called "Game" containing a "Date (UTC)" column. The values are always written back as null value.

Using following code

game = pb.Data.GamesCollection.Filter(....).FirstOrDefault();
var datetime = DateTime.Now;
game.Date = datetime;
game.Save();

The Date column value for the specific record will be null.

The bug is detected in following file: sdk/pocketbase-csharp-sdk/Json/DateTimeConverter.cs

...
public class DateTimeConverter : JsonConverter<DateTime?>
{
....
    public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options)
    {
        if (value is null)
        {
            writer.WriteNullValue();
        }
        else
        {
            /// => is the current code : writer.WriteStringValue(value?.ToString());
            /// Must be replaced by 
            writer.WriteStringValue(value?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"));
        }
    }
}
...