Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit c1872ec

Browse files
adriangodongtarekgh
authored andcommitted
Added UnixEpoch to DateTime and DateTimeOffset (#25235)
* Added UnixEpoch to DateTime and DateTimeOffset. * Added tests * Skip tests for netfx * Move UnixEpoch tests to netcoreapp specific test files
1 parent d4a7694 commit c1872ec

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/System.Runtime/ref/System.Runtime.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ public CLSCompliantAttribute(bool isCompliant) { }
644644
{
645645
public static readonly System.DateTime MaxValue;
646646
public static readonly System.DateTime MinValue;
647+
public static readonly System.DateTime UnixEpoch;
647648
public DateTime(int year, int month, int day) { throw null; }
648649
public DateTime(int year, int month, int day, System.Globalization.Calendar calendar) { throw null; }
649650
public DateTime(int year, int month, int day, int hour, int minute, int second) { throw null; }
@@ -772,6 +773,7 @@ public partial struct DateTimeOffset : System.IComparable, System.IComparable<Sy
772773
{
773774
public static readonly System.DateTimeOffset MaxValue;
774775
public static readonly System.DateTimeOffset MinValue;
776+
public static readonly System.DateTimeOffset UnixEpoch;
775777
public DateTimeOffset(System.DateTime dateTime) { throw null; }
776778
public DateTimeOffset(System.DateTime dateTime, System.TimeSpan offset) { throw null; }
777779
public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, System.Globalization.Calendar calendar, System.TimeSpan offset) { throw null; }

src/System.Runtime/tests/System/DateTimeOffsetTests.netcoreapp.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,11 @@ public static void TryFormat_ToString_EqualResults()
6464
Assert.Equal<char>(expectedString.ToCharArray(), actual.Slice(0, expectedString.Length).ToArray());
6565
Assert.Equal(0, actual[actual.Length - 1]);
6666
}
67+
68+
[Fact]
69+
public static void UnixEpoch()
70+
{
71+
VerifyDateTimeOffset(DateTimeOffset.UnixEpoch, 1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
72+
}
6773
}
6874
}

src/System.Runtime/tests/System/DateTimeTests.netcoreapp.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,11 @@ public static void ParseExact_Span_InvalidInputs_Fail(string input, string forma
8282
Assert.False(DateTime.TryParseExact(input.AsReadOnlySpan(), format, culture, style, out DateTime result));
8383
Assert.False(DateTime.TryParseExact(input.AsReadOnlySpan(), new[] { format }, culture, style, out result));
8484
}
85+
86+
[Fact]
87+
public static void UnixEpoch()
88+
{
89+
VerifyDateTime(DateTime.UnixEpoch, 1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
90+
}
8591
}
8692
}

0 commit comments

Comments
 (0)