Skip to content

Commit

Permalink
Use match instead of try
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty committed Oct 3, 2023
1 parent b036b9d commit fbd0072
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/FSharpPlus/Control/Converter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ type Parse =

#if !FABLE_COMPILER
static member Parse (_: DateTime , _: Parse) = fun (x:string) ->
try DateTime.ParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffZ"; "yyyy-MM-ddTHH:mm:ssZ"|], null, DateTimeStyles.RoundtripKind)
with _ -> DateTime.Parse (x, CultureInfo.InvariantCulture)
match DateTime.TryParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffZ"; "yyyy-MM-ddTHH:mm:ssZ"|], null, DateTimeStyles.RoundtripKind) with
| true, x -> x
| _ -> DateTime.Parse (x, CultureInfo.InvariantCulture)

static member Parse (_: DateTimeOffset, _: Parse) = fun (x:string) ->
try DateTimeOffset.ParseExact (x, [|"yyyy-MM-ddTHH:mm:ss.fffK"; "yyyy-MM-ddTHH:mm:ssK"|], null, DateTimeStyles.AssumeUniversal)
Expand Down Expand Up @@ -210,7 +211,7 @@ type Parse with

type TryParse with

static member inline TryParse (_: 'R, _: Default4) : string -> 'R option = fun (value: string) ->
static member inline TryParse (_: 'R, _: Default4) : string -> 'R option = fun (value: string) ->
try Parse.InvokeOnInstance value |> Some
with _ -> None // todo, maybe match on invalidArg only

Expand Down

0 comments on commit fbd0072

Please sign in to comment.