diff --git a/src/FSharpPlus/Control/Monoid.fs b/src/FSharpPlus/Control/Monoid.fs index 521ccda51..04c1163a5 100644 --- a/src/FSharpPlus/Control/Monoid.fs +++ b/src/FSharpPlus/Control/Monoid.fs @@ -25,6 +25,12 @@ type Plus = static member ``+`` (x: array<_> , y , []_mthd: Plus ) = Array.append x y static member ``+`` (() , () , []_mthd: Plus ) = () static member ``+`` (x: bool , y: bool , []_mthd: Plus ) = x <> y + + #if NET6_0_OR_GREATER + static member ``+`` (x: DateOnly , y: DateOnly , []_mthd: Plus ) = DateOnly.FromDayNumber (x.DayNumber + y.DayNumber) + static member ``+`` (x: TimeOnly , y: TimeOnly , []_mthd: Plus ) = (x.Ticks + y.Ticks) % 864000000000L |> TimeOnly + #endif + static member ``+`` (x: Set<_> , y , []_mthd: Plus ) = Set.union x y #if !FABLE_COMPILER diff --git a/src/FSharpPlus/Control/Numeric.fs b/src/FSharpPlus/Control/Numeric.fs index fead29930..c12dde05f 100644 --- a/src/FSharpPlus/Control/Numeric.fs +++ b/src/FSharpPlus/Control/Numeric.fs @@ -100,6 +100,10 @@ type FromInt32 = static member FromInt32 (_: uint64 , _: FromInt32) = fun (x: int32) -> uint64 x static member FromInt32 (_: float32 , _: FromInt32) = fun (x: int32) -> float32 x static member FromInt32 (_: decimal , _: FromInt32) = fun (x: int32) -> decimal x + + #if NET6_0_OR_GREATER + static member FromInt32 (_: System.DateOnly , _: FromInt32) = fun (x: int32) -> System.DateOnly.FromDayNumber x + #endif static member inline Invoke (x: int32) : 'Num = let inline call_2 (a: ^a, b: ^b) = ((^a or ^b) : (static member FromInt32 : _*_ -> _) b, a) @@ -134,6 +138,10 @@ type Zero = inherit Default1 static member Zero (_: System.TimeSpan , _: Zero ) = System.TimeSpan () + #if NET6_0_OR_GREATER + static member Zero (_: System.DateOnly , _: Zero ) = System.DateOnly.MinValue + static member Zero (_: System.TimeOnly , _: Zero ) = System.TimeOnly.MinValue + #endif static member Zero (_: DmStruct , _: Zero ) = Unchecked.defaultof static member Zero (_: list<'a> , _: Zero ) = [] : list<'a> static member Zero (_: option<'a> , _: Zero ) = None : option<'a> @@ -637,4 +645,4 @@ type MaxValue = static member inline MaxValue (_: 'a*'b*'c*'d*'e*'f , _: MaxValue) = (MaxValue.Invoke (), MaxValue.Invoke (), MaxValue.Invoke (), MaxValue.Invoke (), MaxValue.Invoke (), MaxValue.Invoke ()) static member inline MaxValue (_: 'a*'b*'c*'d*'e*'f*'g, _: MaxValue) = (MaxValue.Invoke (), MaxValue.Invoke (), MaxValue.Invoke (), MaxValue.Invoke (), MaxValue.Invoke (), MaxValue.Invoke (), MaxValue.Invoke ()) -#endif \ No newline at end of file +#endif diff --git a/tests/FSharpPlus.Tests/Monoid.fs b/tests/FSharpPlus.Tests/Monoid.fs index 512bd84f4..c7359ba6a 100644 --- a/tests/FSharpPlus.Tests/Monoid.fs +++ b/tests/FSharpPlus.Tests/Monoid.fs @@ -74,4 +74,16 @@ module Monoid = let! y = struct ("Ten", 10) return y - x } Assert.AreEqual (str, "FourTen") - Assert.AreEqual (num, 6) \ No newline at end of file + Assert.AreEqual (num, 6) + + #if NET6_0_OR_GREATER + [] + let testDateAndTimes = + let d1 = DateOnly(2020, 1, 1) + let d2 = d1 ++ zero ++ one + Assert.AreEqual (DateOnly(2020, 1, 2), d2) + + let t1 = TimeOnly (0, 0, 0) + let t2 = zero + Assert.AreEqual (t1, t2) + #endif