-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Assume that the Unspecified datetime is user's local time zone.
#24049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
AbpDateTimeModelBinder to align with the current TZUnspecified datetime is user's local time zone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements timezone-aware datetime handling for unspecified DateTime values by treating them as being in the user's local timezone and converting them to UTC. This closes issue #24048.
Key Changes
- Created a new base class
AbpDateTimeConverterBase<T>to consolidate common datetime conversion logic for System.Text.Json converters - Updated datetime converters (both System.Text.Json and Newtonsoft.Json) to detect unspecified DateTimeKind values and convert them from the user's timezone to UTC
- Enhanced
AbpDateTimeModelBinderto apply the same timezone conversion logic for model binding scenarios - Added comprehensive test coverage for the new timezone-aware datetime handling
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
ModelBindingController_Tests.cs |
Added three new test methods to verify timezone-aware datetime handling for simple, nullable, and complex type scenarios |
ModelBindingController.cs |
Added four new controller action methods that return both the DateTimeKind and the formatted datetime value for testing purposes |
AbpNullableDateTimeConverter.cs |
Refactored to inherit from the new AbpDateTimeConverterBase<DateTime?> class |
AbpDateTimeConverterBase.cs |
New abstract base class that consolidates datetime reading, writing, and timezone-aware normalization logic |
AbpDateTimeConverter.cs |
Refactored to inherit from the new AbpDateTimeConverterBase<DateTime> class |
AbpDateTimeConverter.cs (Newtonsoft) |
Added timezone conversion logic in the Normalize method to handle unspecified datetime values |
AbpDateTimeModelBinderProvider.cs |
Updated to inject ICurrentTimezoneProvider and ITimezoneProvider dependencies |
AbpDateTimeModelBinder.cs |
Added timezone conversion logic for unspecified datetime values before normalization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...bp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController_Tests.cs
Outdated
Show resolved
Hide resolved
...bp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController_Tests.cs
Outdated
Show resolved
Hide resolved
...bp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController_Tests.cs
Outdated
Show resolved
Hide resolved
...bp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController_Tests.cs
Outdated
Show resolved
Hide resolved
....Json.SystemTextJson/Volo/Abp/Json/SystemTextJson/JsonConverters/AbpDateTimeConverterBase.cs
Outdated
Show resolved
Hide resolved
...k/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpDateTimeModelBinder.cs
Show resolved
Hide resolved
...Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController.cs
Outdated
Show resolved
Hide resolved
....Json.SystemTextJson/Volo/Abp/Json/SystemTextJson/JsonConverters/AbpDateTimeConverterBase.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Json.Newtonsoft/Volo/Abp/Json/Newtonsoft/AbpDateTimeConverter.cs
Outdated
Show resolved
Hide resolved
...bp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ModelBinding/ModelBindingController_Tests.cs
Outdated
Show resolved
Hide resolved
…adjustments in model binding and JSON converters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Close #24048