Skip to content

Commit

Permalink
处理docker中跑UT 时区的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hjkl950217 committed Oct 28, 2020
1 parent 6fd0ae9 commit e540a3a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
4 changes: 1 addition & 3 deletions CkTools/Src/CkTools.BaseExtensions/BaseType/IntExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace CkTools.Extensions.BaseType
namespace System
{
public static class IntExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using CkTools.Extensions.BaseType;

namespace System
namespace System
{
public static class TimeZoneInfoExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ public void TryToLocalDateTimeOffsetByMillisecondsTest(string source, string exp

public class ToDateTimeOffsetUTData
{
//todo :弄好偏移字符串后 local的数据处理下时区
//这里使用偏移处理是为了兼容docker环境下跑UT 时区的问题
public static string OffsetStr = TimeZoneInfo.Local.GetOffsetString();

public static int offsetHours = TimeZoneInfo.Local.BaseUtcOffset.Hours.Abs();

public static IEnumerable<object[]> Utc()
{
yield return new object[] { "2020-10-16T11:36:56+08:00", "2020-10-16T03:36:56.0000000+00:00" };
Expand All @@ -139,16 +141,16 @@ public static IEnumerable<object[]> UtcMilliseconds()

public static IEnumerable<object[]> Local()
{
yield return new object[] { "2020-10-16T11:36:56+08:00", $"2020-10-16T11:36:56.0000000{OffsetStr}" };
yield return new object[] { "1602819416", $"2020-10-16T11:36:56.0000000{OffsetStr}" };
yield return new object[] { "0", $"1970-01-01T08:00:00.0000000{OffsetStr}" };
yield return new object[] { "2020-10-16T11:36:56+08:00", $"2020-10-16T{offsetHours + 3:00}:36:56.0000000{OffsetStr}" };
yield return new object[] { "1602819416", $"2020-10-16T{offsetHours + 3:00}:36:56.0000000{OffsetStr}" };
yield return new object[] { "0", $"1970-01-01T{offsetHours:00}:00:00.0000000{OffsetStr}" };
}

public static IEnumerable<object[]> LocalMilliseconds()
{
yield return new object[] { "2020-10-16T11:36:56+08:00", $"2020-10-16T11:36:56.0000000{OffsetStr}" };
yield return new object[] { "1602819416001", $"2020-10-16T11:36:56.0010000{OffsetStr}" };
yield return new object[] { "0", $"1970-01-01T08:00:00.0000000{OffsetStr}" };
yield return new object[] { "2020-10-16T11:36:56+08:00", $"2020-10-16T{offsetHours + 3:00}:36:56.0000000{OffsetStr}" };
yield return new object[] { "1602819416001", $"2020-10-16T{offsetHours + 3:00}:36:56.0010000{OffsetStr}" };
yield return new object[] { "0", $"1970-01-01T{offsetHours:00}:00:00.0000000{OffsetStr}" };
}

public static IEnumerable<object[]> TryUtc()
Expand All @@ -166,13 +168,13 @@ public static IEnumerable<object[]> TryUtcMilliseconds()
public static IEnumerable<object[]> TryLocal()
{
return ToDateTimeOffsetUTData.Local()
.Concat(new object[] { "", $"0001-01-01T08:00:00.0000000{OffsetStr}" }.AsToEnumerable());
.Concat(new object[] { "", $"0001-01-01T{offsetHours:00}:00:00.0000000{OffsetStr}" }.AsToEnumerable());
}

public static IEnumerable<object[]> TryLocalMilliseconds()
{
return ToDateTimeOffsetUTData.LocalMilliseconds()
.Concat(new object[] { "", $"0001-01-01T08:00:00.0000000{OffsetStr}" }.AsToEnumerable());
.Concat(new object[] { "", $"0001-01-01T{offsetHours:00}:00:00.0000000{OffsetStr}" }.AsToEnumerable());
}
}
}

0 comments on commit e540a3a

Please sign in to comment.