Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,35 @@
public async Task BindModelAsync(ModelBindingContext bindingContext)
{
await _dateTimeModelBinder.BindModelAsync(bindingContext);
if (bindingContext.Result.IsModelSet && bindingContext.Result.Model is DateTime dateTime)

if (!bindingContext.Result.IsModelSet || bindingContext.Result.Model is not DateTime dateTime)
{
bindingContext.Result = ModelBindingResult.Success(_clock.Normalize(dateTime));
return;
}

// If the DateTime has no timezone info (most cases from input)
if (dateTime.Kind == DateTimeKind.Unspecified)
{
// Try to get user's timezone
var userTz = _currentTimezoneProvider.TimeZone;

Check failure on line 33 in framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpDateTimeModelBinder.cs

View workflow job for this annotation

GitHub Actions / build-test

The name '_currentTimezoneProvider' does not exist in the current context

Check failure on line 33 in framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpDateTimeModelBinder.cs

View workflow job for this annotation

GitHub Actions / build-test

The name '_currentTimezoneProvider' does not exist in the current context
if (!userTz.IsNullOrWhiteSpace())
{
try
{
var tzInfo = _timezoneProvider.GetTimeZoneInfo(userTz);

Check failure on line 38 in framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpDateTimeModelBinder.cs

View workflow job for this annotation

GitHub Actions / build-test

The name '_timezoneProvider' does not exist in the current context

Check failure on line 38 in framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ModelBinding/AbpDateTimeModelBinder.cs

View workflow job for this annotation

GitHub Actions / build-test

The name '_timezoneProvider' does not exist in the current context
// Treat the input as user's local time and convert to UTC
var utc = TimeZoneInfo.ConvertTimeToUtc(dateTime, tzInfo);
bindingContext.Result = ModelBindingResult.Success(utc);
return;
}
catch
{
// fallback to default clock normalization if invalid TZ
}
}
}

// fallback: original behavior
bindingContext.Result = ModelBindingResult.Success(_clock.Normalize(dateTime));
}
}
Loading