diff --git a/src/Snap.Hutao/Snap.Hutao.Test/IncomingFeature/SpiralAbyssScheduleIdTest.cs b/src/Snap.Hutao/Snap.Hutao.Test/IncomingFeature/SpiralAbyssScheduleIdTest.cs new file mode 100644 index 00000000..31d30681 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao.Test/IncomingFeature/SpiralAbyssScheduleIdTest.cs @@ -0,0 +1,42 @@ +using System; + +namespace Snap.Hutao.Test.IncomingFeature; + +[TestClass] +public class SpiralAbyssScheduleIdTest +{ + private static readonly TimeSpan Utc8 = new(8, 0, 0); + + [TestMethod] + public void Test() + { + Console.WriteLine($"当前第 {GetForDateTimeOffset(DateTimeOffset.Now)} 期"); + + DateTimeOffset dateTimeOffset = new(2020, 7, 1, 4, 0, 0, Utc8); + Console.WriteLine($"2020-07-01 04:00:00 为第 {GetForDateTimeOffset(dateTimeOffset)} 期"); + } + public static int GetForDateTimeOffset(DateTimeOffset dateTimeOffset) + { + // Force time in UTC+08 + dateTimeOffset = dateTimeOffset.ToOffset(Utc8); + + ((int year, int mouth, int day), (int hour, _), _) = dateTimeOffset; + + // 2020-07-01 04:00:00 为第 1 期 + int periodNum = (((year - 2020) * 12) + (mouth - 6)) * 2; + + // 上半月:1-15 日, 以及 16 日 00:00-04:00 + if (day < 16 || (day == 16 && hour < 4)) + { + periodNum--; + } + + // 上个月:1 日 00:00-04:00 + if (day is 1 && hour < 4) + { + periodNum--; + } + + return periodNum; + } +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao.Test/RuntimeBehavior/UnsafeRuntimeBehaviorTest.cs b/src/Snap.Hutao/Snap.Hutao.Test/RuntimeBehavior/UnsafeRuntimeBehaviorTest.cs index d876b35b..b2b4ed03 100644 --- a/src/Snap.Hutao/Snap.Hutao.Test/RuntimeBehavior/UnsafeRuntimeBehaviorTest.cs +++ b/src/Snap.Hutao/Snap.Hutao.Test/RuntimeBehavior/UnsafeRuntimeBehaviorTest.cs @@ -1,10 +1,15 @@ -namespace Snap.Hutao.Test.RuntimeBehavior; +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace Snap.Hutao.Test.RuntimeBehavior; [TestClass] public sealed class UnsafeRuntimeBehaviorTest { [TestMethod] - public unsafe void UInt32AllSetIs() + public unsafe void UInt32AllSetIsUInt32MaxValue() { byte[] bytes = #if NET8_0_OR_GREATER @@ -18,23 +23,28 @@ public sealed class UnsafeRuntimeBehaviorTest Assert.AreEqual(uint.MaxValue, *(uint*)pBytes); } } -} -[TestClass] -public sealed class NewModifierRuntimeBehaviorTest -{ - private interface IBase + [TestMethod] + public unsafe void ReadOnlyStructCanBeModifiedInCtor() { - int GetValue(); + TestStruct testStruct = new([4444, 7878, 5656, 1212]); + + Assert.AreEqual(4444, testStruct.Value1); + Assert.AreEqual(7878, testStruct.Value2); + Assert.AreEqual(5656, testStruct.Value3); + Assert.AreEqual(1212, testStruct.Value4); } - private interface IBaseImpl : IBase + private readonly struct TestStruct { - new int GetValue(); - } + public readonly int Value1; + public readonly int Value2; + public readonly int Value3; + public readonly int Value4; - private sealed class Impl : IBaseImpl - { - public int GetValue() => 1; + public TestStruct(List list) + { + CollectionsMarshal.AsSpan(list).CopyTo(MemoryMarshal.CreateSpan(ref Unsafe.As(ref this), 4)); + } } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao.Test/Snap.Hutao.Test.csproj b/src/Snap.Hutao/Snap.Hutao.Test/Snap.Hutao.Test.csproj index 6dc31b33..b9f4d0b3 100644 --- a/src/Snap.Hutao/Snap.Hutao.Test/Snap.Hutao.Test.csproj +++ b/src/Snap.Hutao/Snap.Hutao.Test/Snap.Hutao.Test.csproj @@ -1,7 +1,7 @@ - net7.0;net8.0 + net8.0 disable enable false