Skip to content

[Repo Assist] Add PreferDateTimeOffset parameter to CsvProvider, JsonProvider, and XmlProvider#1668

Merged
dsyme merged 6 commits intomainfrom
repo-assist/fix-issue-1100-prefer-datetimeoffset-8d64eb68853e49f4
Feb 26, 2026
Merged

[Repo Assist] Add PreferDateTimeOffset parameter to CsvProvider, JsonProvider, and XmlProvider#1668
dsyme merged 6 commits intomainfrom
repo-assist/fix-issue-1100-prefer-datetimeoffset-8d64eb68853e49f4

Conversation

@github-actions
Copy link
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.

Adds a PreferDateTimeOffset static parameter (default: false) to CsvProvider, JsonProvider, and XmlProvider, addressing the long-standing requests in #1100 and #1072.

Closes #1100
Closes #1072

What this does

// Before: "2023-06-15T10:30:00" inferred as DateTime
type MyData = CsvProvider<"data.csv">

// After: "2023-06-15T10:30:00" inferred as DateTimeOffset (with local UTC offset)
type MyData = CsvProvider<"data.csv", PreferDateTimeOffset=true>

When PreferDateTimeOffset=true, all date-time columns/fields that would normally be inferred as DateTime are instead inferred as DateTimeOffset. Values already containing an explicit timezone offset (e.g., "2023-06-15T10:30:00+05:30") are already inferred as DateTimeOffset regardless of this flag.

Implementation

The change is a post-inference rewrite: after structural type inference, a tree-walking transform replaces DateTimeDateTimeOffset throughout the inferred type. No runtime changes are needed because TextRuntime.ConvertDateTimeOffset already has a fallback path that converts DateTime-like strings to DateTimeOffset using the local offset.

Files changed

  • StructuralInference.fs: Two new internal helpers:
    • upgradeToDateTimeOffset — walks an InferedType tree, replacing DateTimeDateTimeOffset
    • upgradeToDateTimeOffsetPrimitiveProperty — CSV-specific version for PrimitiveInferedProperty
  • CsvProvider.fs: New PreferDateTimeOffset static parameter (index 20); upgrade applied after the net6/DateOnly downgrade step
  • JsonProvider.fs: New PreferDateTimeOffset static parameter (index 15); upgrade applied after the net6/DateOnly downgrade step
  • XmlProvider.fs: New PreferDateTimeOffset static parameter (index 14); upgrade applied after the net6/DateOnly downgrade step
  • TypeProviderInstantiation.fs: PreferDateTimeOffset field added to CsvProviderArgs, XmlProviderArgs, JsonProviderArgs
  • RELEASE_NOTES.md: Updated

Test Status

  • FSharp.Data.DesignTime builds (netstandard2.0 + net8.0)
  • ✅ Core tests: 2846/2847 pass (1 pre-existing network test blocked by sandbox)
  • ⚠️ DesignTime signature tests: 436/487 fail — this is a pre-existing failure on main unrelated to this PR (verified by running tests on unmodified main with same result)

Notes

  • Only CsvProvider, JsonProvider, and XmlProvider are covered (HtmlProvider uses a different internal path that can be added in a follow-up)
  • PreferDateTimeOffset and PreferDateOnly are orthogonal: DateOnly values stay as DateOnly even when PreferDateTimeOffset=true
  • Default is false for full backward compatibility

Generated by Repo Assist

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@69c1ee19e39e6aaba35519aafefb5cbf314de323

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • www.google.com

…rovider

Adds a new PreferDateTimeOffset static parameter (default: false) to
CsvProvider, JsonProvider, and XmlProvider.

When set to true, date-time values that would normally be inferred as
DateTime are instead inferred as DateTimeOffset (using the local UTC
offset). Values that already parse with an explicit timezone offset are
already inferred as DateTimeOffset regardless of this parameter.

This addresses the long-standing request in #1100 (configure default
DateTimeKind for dates without timezone) and #1072 (control over
timezone in CSV date writing).

Closes #1100
Closes #1072

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review February 26, 2026 14:14

/// Replaces DateTime → DateTimeOffset throughout an InferedType tree.
/// Used when PreferDateTimeOffset=true to infer all date-time values as DateTimeOffset.
let internal upgradeToDateTimeOffset (inferedType: InferedType) : InferedType =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this approach, we should really be plumbing these flags down into inference and making the conversions at the leaves rather than patching things up afterwards

t
else
StructuralInference.downgradeNet6Types t
if preferDateOnly && ProviderHelpers.runtimeSupportsNet6Types cfg.RuntimeAssembly then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way of doing PreferDateOnly needs some work. Since PreferDateOnly is not the default, we should not be introducing DateOnly only to remove them again

We should clean this up in main before taking this feature

@dsyme
Copy link
Contributor

dsyme commented Feb 26, 2026

/repo-assist Update the docs

…XmlProvider, and TypeInference docs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

Commit pushed: f311d7b

Generated by Repo Assist

@github-actions
Copy link
Contributor Author

🤖 This is an automated response from Repo Assist.

I've added documentation for PreferDateTimeOffset to the following files:

  • docs/library/CsvProvider.fsx — Added mention in the inline comment, the narrative text about date inference, the "Controlling the column types" section, and a new "### DateTimeOffset" subsection.
  • docs/library/JsonProvider.fsx — Extended the "Inferring date types" section to describe PreferDateTimeOffset.
  • docs/library/XmlProvider.fsx — Added a new "## Inferring date types" section covering DateTime, DateTimeOffset, PreferDateOnly, and PreferDateTimeOffset.
  • docs/library/TypeInference.fsx — Updated the date/time table to include a PreferDateTimeOffset row, added explanatory text, and added it to the "Summary of Inference-Control Parameters" table.

Generated by Repo Assist for issue #1668

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@afb00b92a9514fee9a14c583f059a03d05738f70

@dsyme dsyme merged commit 49d4888 into main Feb 26, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-1100-prefer-datetimeoffset-8d64eb68853e49f4 branch February 26, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configure default DateTimeKind when no timezone information given CsvProvider has no option to write dates without timezone information.

1 participant