Skip to content

Instantly share code, notes, and snippets.

@bohdanszymanik
Created March 27, 2018 22:20
Show Gist options
  • Save bohdanszymanik/3bcf9887125760cfea8d0c9e99e100d7 to your computer and use it in GitHub Desktop.
Save bohdanszymanik/3bcf9887125760cfea8d0c9e99e100d7 to your computer and use it in GitHub Desktop.
Active pattern date matching
// I like this active pattern stuff
open System.Globalization
let (|ShortDate|_|) s =
match DateTime.TryParseExact(s, "ddMMMyyyy", CultureInfo.InvariantCulture, DateTimeStyles.None) with
| true, d -> Some d
| _ -> None
let (|LongDate|_|) s =
match DateTime.TryParseExact(s, "ddMMMyyyy:HH:mm:ss.fff", CultureInfo.InvariantCulture, DateTimeStyles.None) with
| true, d -> Some d
| _ -> None
let parseDate s =
match s with
| ShortDate d -> Some d
| LongDate d -> Some d
| _ -> None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment