Created
March 27, 2018 22:20
-
-
Save bohdanszymanik/3bcf9887125760cfea8d0c9e99e100d7 to your computer and use it in GitHub Desktop.
Active pattern date matching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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