时间格式验证增加测试
continuous-integration/drone/push Build is passing Details

Test_IRC_Net8
hang 2026-01-21 10:23:30 +08:00
parent 9b90ded79f
commit 1aa1189ae8
1 changed files with 9 additions and 16 deletions

View File

@ -71,32 +71,25 @@ namespace IRaCIS.Core.API
DateTime dateTime;
if (reader.ValueType == typeof(DateTime) || reader.ValueType == typeof(DateTime?))
// 2. 检查目标类型是否可空
bool isNullable = objectType == typeof(DateTime?);
var canConvert = DateTime.TryParse(reader.Value?.ToString(), out dateTime);
if (isNullable == false && canConvert == false)
{
DateTime? nullableDateTime = reader.Value as DateTime?;
if (nullableDateTime != null && nullableDateTime.HasValue)
{
dateTime = nullableDateTime.Value;
}
else
{
return null;
}
throw new JsonSerializationException($"Could not convert string to DateTime: {reader.Value} Path {reader.Path}");
}
else
{
if (DateTime.TryParse((string)reader.Value, out dateTime) == false)
if (canConvert == false)
{
//throw new JsonSerializationException($"Could not convert string to DateTime: {reader.Value} Path {reader.Path}");
return null;
}
}
// 将客户端时间转换为服务器时区的时间
var serverZoneTime = TimeZoneInfo.ConvertTime(dateTime, _clientTimeZone, TimeZoneInfo.Local);