Skip to content

feat(DateTimePicker): add ParseDateTimeResolve parmeter - #8302

Merged
ArgoZhang merged 9 commits into
mainfrom
feat-date
Aug 6, 2026
Merged

feat(DateTimePicker): add ParseDateTimeResolve parmeter#8302
ArgoZhang merged 9 commits into
mainfrom
feat-date

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Aug 6, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #8301

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Introduce customizable date/time parsing for DateTimePicker, with support for both per-component and global configuration, and improve handling of DateTime and DateTimeOffset values.

New Features:

  • Add ParseDateTimeResolve and ParseDateTimeOffsetResolve parameters to DateTimePicker for custom parsing of input values.
  • Add DateTimeSettings to BootstrapBlazorOptions to provide global configuration for date and time parsing behavior.

Enhancements:

  • Update DateTimePicker parsing logic to respect generic value type and use either DateTime or DateTimeOffset parsing paths accordingly.
  • Inject options into DateTimePicker to allow fallback to globally configured date/time parsing when component-level resolvers are not provided.

Tests:

  • Add unit tests covering nullable DateTime and DateTimeOffset parsing, custom resolver parameters, and precedence between component-level and global parsing configuration.

@bb-auto bb-auto Bot added the enhancement New feature or request label Aug 6, 2026
@bb-auto bb-auto Bot added this to the v10.9.0 milestone Aug 6, 2026
@sourcery-ai

sourcery-ai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds customizable DateTime/DateTimeOffset parsing for DateTimePicker, including component-level parameters and global options, and updates unit tests to cover nullable and offset scenarios and the new resolution priority behavior.

Sequence diagram for DateTimePicker parsing resolution priority

sequenceDiagram
    participant DateTimePicker
    participant BootstrapBlazorOptions
    participant DateTimeSettings
    participant DateTimeHelper

    DateTimePicker->>DateTimePicker: TryParseValueFromString(value, out result, out validationErrorMessage)
    alt ValueType == typeof(DateTime)
        DateTimePicker->>DateTimePicker: TryParseDateTime(value, out val)
        DateTimePicker->>BootstrapBlazorOptions: Options.CurrentValue
        BootstrapBlazorOptions-->>DateTimePicker: options
        DateTimePicker->>DateTimeSettings: options.DateTimeSettings.ParseDateTimeResolve
        alt ParseDateTimeResolve parameter or global option exists
            DateTimePicker-->>DateTimePicker: resolve(value)
        else no custom resolver
            DateTimePicker->>DateTimeHelper: TryToDateTime(value, out d)
            DateTimeHelper-->>DateTimePicker: ret, d
        end
    else ValueType != typeof(DateTime)
        DateTimePicker->>DateTimePicker: TryParseDateTimeOffset(value, out val)
        DateTimePicker->>BootstrapBlazorOptions: Options.CurrentValue
        BootstrapBlazorOptions-->>DateTimePicker: options
        DateTimePicker->>DateTimeSettings: options.DateTimeSettings.ParseDateTimeOffsetResolve
        alt ParseDateTimeOffsetResolve parameter or global option exists
            DateTimePicker-->>DateTimePicker: resolve(value)
        else no custom resolver
            DateTimePicker->>DateTimeHelper: ToDateTimeOffset(value)
            DateTimeHelper-->>DateTimePicker: v
        end
    end
    DateTimePicker-->>DateTimePicker: result = (TValue)val
Loading

File-Level Changes

Change Details Files
Introduce per-component delegates to override DateTime and DateTimeOffset parsing in DateTimePicker, with support for global defaults via options.
  • Add ParseDateTimeResolve and ParseDateTimeOffsetResolve parameters to DateTimePicker with documentation comments
  • Inject IOptionsMonitor into DateTimePicker to access global DateTimeSettings
  • Refactor TryParseValueFromString to dispatch to new TryParseDateTime/TryParseDateTimeOffset helpers based on generic value type
  • Implement TryParseDateTime to use component or global resolve delegate, falling back to DateTimeHelper.TryToDateTime
  • Implement TryParseDateTimeOffset to use component or global resolve delegate, falling back to DateTimeHelper.ToDateTimeOffset
src/BootstrapBlazor/Components/DateTimePicker/DateTimePicker.razor.cs
Add global configuration for DateTime parsing behavior that can be used by DateTimePicker when per-component overrides are not provided.
  • Introduce DateTimeSettings options class with delegates for DateTime and DateTimeOffset parsing
  • Expose DateTimeSettings as a new property on BootstrapBlazorOptions with default instance initialization
src/BootstrapBlazor/Options/DateTimeSettings.cs
src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs
Extend unit tests for DateTimePicker to validate new parsing behavior and type-specific handling for nullable DateTime and DateTimeOffset.
  • Add tests ensuring nullable DateTime and nullable DateTimeOffset follow generic type parsing branches and keep value on invalid input
  • Add tests verifying ParseDateTimeResolve and ParseDateTimeOffsetResolve parameters override built-in parsing and are preferred over global options
  • Add tests verifying global DateTimeSettings options affect parsing when component parameters are not set
  • Register options infrastructure in tests via Microsoft.Extensions.Options
test/UnitTest/Components/DateTimePickerTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#8301 Add a ParseDateTimeResolve parameter to the DateTimePicker component that allows consumers to provide a custom DateTime parsing function and ensure it is used in value parsing.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Auto approved by bb-auto

@ArgoZhang
ArgoZhang enabled auto-merge (squash) August 6, 2026 09:20

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In TryParseValueFromString you assume anything that's not DateTime should go through the DateTimeOffset path; consider explicitly checking for DateTimeOffset and falling back to the original parsing logic (or throwing) for unsupported TValue types to avoid silent misparsing if new value types are introduced.
  • Both TryParseDateTime and TryParseDateTimeOffset assign sentinel values (DateTime.MinValue / DateTimeOffset.MinValue) on failure even though the caller ignores val when ret is false; you can simplify by setting val = default! on failure to make the intent clearer and avoid misleading values.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `TryParseValueFromString` you assume anything that's not `DateTime` should go through the `DateTimeOffset` path; consider explicitly checking for `DateTimeOffset` and falling back to the original parsing logic (or throwing) for unsupported `TValue` types to avoid silent misparsing if new value types are introduced.
- Both `TryParseDateTime` and `TryParseDateTimeOffset` assign sentinel values (`DateTime.MinValue` / `DateTimeOffset.MinValue`) on failure even though the caller ignores `val` when `ret` is false; you can simplify by setting `val = default!` on failure to make the intent clearer and avoid misleading values.

## Individual Comments

### Comment 1
<location path="src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs" line_range="193-198" />
<code_context>
+    /// <para lang="en">Gets or sets the <see cref="DateTimeSettings"/> configuration instance</para>
+    /// <para>v<version>10.9.1</version></para>
+    /// </summary>
+    public DateTimeSettings DateTimeSettings { get; set; } = new();
+
     BootstrapBlazorOptions IOptions<BootstrapBlazorOptions>.Value => this;
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider making `DateTimeSettings` non-nullable or read-only to reflect its required nature.

Because `DateTimeSettings` is consumed without null checks and initialized with `new()`, allowing it to be set to `null` breaks the intended invariant and can lead to null-reference issues. Making the property non-nullable and either removing the public setter or enforcing a non-null check in the setter would keep the type and usage consistent and prevent these latent bugs.

```suggestion
    /// <summary>
    /// <para lang="zh">获得 <see cref="DateTimeSettings"/> 配置实例</para>
    /// <para lang="en">Gets the <see cref="DateTimeSettings"/> configuration instance</para>
    /// <para>v<version>10.9.1</version></para>
    /// </summary>
    public DateTimeSettings DateTimeSettings { get; } = new();
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/BootstrapBlazor/Options/BootstrapBlazorOptions.cs
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9af5aa3) to head (6403d1f).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8302   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          770       771    +1     
  Lines        34509     34537   +28     
=========================================
+ Hits         34509     34537   +28     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ArgoZhang
ArgoZhang merged commit 4e7bc4c into main Aug 6, 2026
7 checks passed
@ArgoZhang
ArgoZhang deleted the feat-date branch August 6, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(DateTimePicker): add ParseDateTimeResolve parmeter

1 participant