Skip to content

Updating Date writes values back as null  #48

@GZeroCoder

Description

@GZeroCoder

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"));
        }
    }
}
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions