Skip to content

ISO DateTime serialization produces invalid year for DateTime.MinValue #253

Description

@aliegeni

NetJSON 1.4.5 serializes DateTime.MinValue using a one-digit year instead of the ISO 8601 required four-digit year.

Example:

Input:
DateTime.MinValue

Current output:
"1-01-01T00:00:00.0Z"

Expected output:
"0001-01-01T00:00:00.0Z"

The generated JSON cannot be deserialized by System.Text.Json because "1-01-01T00:00:00.0Z" is not a valid ISO 8601 date representation.

Configuration:

new NetJSONSettings
{
DateFormat = NetJSONDateFormat.ISO,
TimeZoneFormat = NetJSONTimeZoneFormat.Utc
}

This appears to be an ISO formatting bug. Years less than 1000 should be zero-padded to four digits (e.g. 0001, 0099, 0999), as required by ISO 8601 and expected by other JSON serializers.

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