Skip to content

Commit

Permalink
[fix]如果待转换时间未指定时区,则直接返回。在web开发中,url时间参数传递一般不带时区,代码读取得到的时间类型是Unspecifi…
Browse files Browse the repository at this point in the history
…ed,此时如果直接对雪花Id字段进行时间区间查找,不管是转Local还是转UTC都可能出错,因为url里面这个时间,大多数时候就是本地时间,所以这里不应该转换。
  • Loading branch information
nnhy committed Aug 2, 2024
1 parent af745a2 commit 33eb5af
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NewLife.Core/Data/Snowflake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ public virtual Boolean TryParse(Int64 id, out DateTime time, out Int32 workerId,
/// <returns></returns>
public DateTime ConvertKind(DateTime time)
{
// 如果待转换时间未指定时区,则直接返回
if (time.Kind == DateTimeKind.Unspecified) return time;

return StartTimestamp.Kind switch
{
DateTimeKind.Utc => time.ToUniversalTime(),
Expand Down

0 comments on commit 33eb5af

Please sign in to comment.