Created
June 20, 2014 10:40
-
-
Save ascjones/557a3de1726a04d433b6 to your computer and use it in GitHub Desktop.
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
[<AutoOpen>] | |
module JsonExtensions = | |
open System | |
open Fleece | |
open Fleece.Operators | |
open FSharpPlus | |
open System.Globalization | |
type FromJSONClass with | |
static member ToJSON(x: TimeSpan) = | |
let s = x.ToString("d\.hh\:mm\:ss", CultureInfo.InvariantCulture) | |
JString s | |
static member FromJSON(_: TimeSpan) = | |
function | |
| JString s -> | |
if s = null | |
then Failure "Expected TimeSpan, got null" | |
else match TimeSpan.TryParseExact(s, "d\.hh\:mm\:ss", CultureInfo.InvariantCulture) with | |
| true,ts -> Success ts | |
| _ -> failwithf "Invalid TimeSpan %s" s | |
| x -> Failure (sprintf "Expected JString, found %A" x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/mausch/a8012001888e1427c2f1