From 41a935af12a0e0b5f3e50649d5119d0691223445 Mon Sep 17 00:00:00 2001 From: gusty <1261319+gusty@users.noreply.github.com> Date: Sat, 16 Sep 2023 07:59:52 +0200 Subject: [PATCH 1/6] + DateOnly as Monoid and Zero for TimeOnly --- src/FSharpPlus/Control/Monoid.fs | 5 +++++ src/FSharpPlus/Control/Numeric.fs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/FSharpPlus/Control/Monoid.fs b/src/FSharpPlus/Control/Monoid.fs index a91b65849..5603dd2b9 100644 --- a/src/FSharpPlus/Control/Monoid.fs +++ b/src/FSharpPlus/Control/Monoid.fs @@ -26,6 +26,11 @@ 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) + #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 55e2bea8c..6bff1db19 100644 --- a/src/FSharpPlus/Control/Numeric.fs +++ b/src/FSharpPlus/Control/Numeric.fs @@ -99,6 +99,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) @@ -133,6 +137,8 @@ type Zero = inherit Default1 static member Zero (_: System.TimeSpan , _: Zero ) = System.TimeSpan () + static member Zero (_: System.DateOnly , _: Zero ) = System.DateOnly.MinValue + static member Zero (_: System.TimeOnly , _: Zero ) = System.TimeOnly.MinValue static member Zero (_: DmStruct , _: Zero ) = Unchecked.defaultof static member Zero (_: list<'a> , _: Zero ) = [] : list<'a> static member Zero (_: option<'a> , _: Zero ) = None : option<'a> From 06fcfcdd9f380d87c245a1fd0b3f80ebd13df926 Mon Sep 17 00:00:00 2001 From: Gustavo Leon <1261319+gusty@users.noreply.github.com> Date: Fri, 13 Oct 2023 08:40:04 +0200 Subject: [PATCH 2/6] Add missing conditionals --- src/FSharpPlus/Control/Numeric.fs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/FSharpPlus/Control/Numeric.fs b/src/FSharpPlus/Control/Numeric.fs index 6bff1db19..ff9d1aa67 100644 --- a/src/FSharpPlus/Control/Numeric.fs +++ b/src/FSharpPlus/Control/Numeric.fs @@ -137,8 +137,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> @@ -641,4 +643,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 From d3ccce7c9c591630c00b115ba490c7b104b05dab Mon Sep 17 00:00:00 2001 From: gusty <1261319+gusty@users.noreply.github.com> Date: Fri, 13 Oct 2023 09:04:47 +0200 Subject: [PATCH 3/6] + Test --- tests/FSharpPlus.Tests/Monoid.fs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/FSharpPlus.Tests/Monoid.fs b/tests/FSharpPlus.Tests/Monoid.fs index 512bd84f4..cba0df0a2 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 (2, 10, 30) + let t2 = t1 ++ zero + Assert.AreEqual (t1, t2) + #endif \ No newline at end of file From 7f96131dd368708d28d88bd56743b7665f6cb875 Mon Sep 17 00:00:00 2001 From: Gustavo Leon <1261319+gusty@users.noreply.github.com> Date: Fri, 13 Oct 2023 09:43:58 +0200 Subject: [PATCH 4/6] Adapt test --- tests/FSharpPlus.Tests/Monoid.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/FSharpPlus.Tests/Monoid.fs b/tests/FSharpPlus.Tests/Monoid.fs index cba0df0a2..c7359ba6a 100644 --- a/tests/FSharpPlus.Tests/Monoid.fs +++ b/tests/FSharpPlus.Tests/Monoid.fs @@ -83,7 +83,7 @@ module Monoid = let d2 = d1 ++ zero ++ one Assert.AreEqual (DateOnly(2020, 1, 2), d2) - let t1 = TimeOnly (2, 10, 30) - let t2 = t1 ++ zero + let t1 = TimeOnly (0, 0, 0) + let t2 = zero Assert.AreEqual (t1, t2) - #endif \ No newline at end of file + #endif From ee6c4c09a99e9f6f0abbcab4a6d4dea10cc31f32 Mon Sep 17 00:00:00 2001 From: gusty <1261319+gusty@users.noreply.github.com> Date: Sat, 14 Oct 2023 07:21:44 +0200 Subject: [PATCH 5/6] + TimeOnly as Monoid --- src/FSharpPlus/Control/Monoid.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/FSharpPlus/Control/Monoid.fs b/src/FSharpPlus/Control/Monoid.fs index 5603dd2b9..15d84efd5 100644 --- a/src/FSharpPlus/Control/Monoid.fs +++ b/src/FSharpPlus/Control/Monoid.fs @@ -29,6 +29,7 @@ type Plus = #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 From 284b6974765e764f44b6cb350b8bc733bef857d4 Mon Sep 17 00:00:00 2001 From: Oskar Gewalli Date: Sat, 14 Oct 2023 10:08:14 +0300 Subject: [PATCH 6/6] +targetframework net6 --- src/FSharpPlus/FSharpPlus.fsproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FSharpPlus/FSharpPlus.fsproj b/src/FSharpPlus/FSharpPlus.fsproj index c113e81ba..c5f85cd69 100644 --- a/src/FSharpPlus/FSharpPlus.fsproj +++ b/src/FSharpPlus/FSharpPlus.fsproj @@ -26,7 +26,7 @@ $(DefineConstants);FABLE_COMPILER $(DefineConstants);FABLE_COMPILER;FABLE_COMPILER_3 $(DefineConstants);FABLE_COMPILER;FABLE_COMPILER_4 - netstandard2.0;netstandard2.1 + netstandard2.0;netstandard2.1;net6.0