Skip to content

Commit

Permalink
Revert "Corrected Outputting of date string"
Browse files Browse the repository at this point in the history
This reverts commit 2e465a4.
  • Loading branch information
forki committed Nov 30, 2012
1 parent 911a25e commit 96b5eee
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 63 deletions.
7 changes: 2 additions & 5 deletions src/FSharpx.Core/JSON.fs
Expand Up @@ -96,11 +96,8 @@ type Text(text:string) =
type Date(date:DateTime) =
let mutable v = date

let escape s =
s|> replace "\"" "\\\""

member this.Value with get() = v and set (value) = v <- value
override this.ToString() = sprintf "\"%s\"" (v.ToString("o"))
override this.ToString() = sprintf "\"%s\"" (v.ToString())

override this.Equals other =
match other with
Expand All @@ -109,7 +106,7 @@ type Date(date:DateTime) =

interface IDocument
interface Infrastucture with
member this.Serialize sb = sb.AppendFormat("\"{0}\"", (escape <| v.ToString("o")))
member this.Serialize sb = sb.Append(v.ToString(System.Globalization.CultureInfo.InvariantCulture))
member this.ToXml() = v :> obj


Expand Down
76 changes: 34 additions & 42 deletions tests/FSharpx.Tests/JSON.Serialization.Tests.fs
@@ -1,42 +1,34 @@
module FSharpx.Tests.JSON.SerializationTests

open NUnit.Framework
open FSharpx.JSON
open FSharpx.JSON.DocumentExtensions
open FsUnit

[<Test>]
let ``Can serialize empty document``() =
JObject.New().ToString()
|> should equal "{}"

[<Test>]
let ``Can serialize document with single property``() =
JObject
.New()
.AddTextProperty("firstName","John")
.ToString()
|> should equal "{\"firstName\":\"John\"}"

[<Test>]
let ``Can serialize document with booleans``() =
JObject
.New()
.AddBoolProperty("aa",true)
.AddBoolProperty("bb",false)
.ToString()
|> should equal "{\"aa\":true,\"bb\":false}"

[<Test>]
let ``Can serialize document with array, null and number``() =
let text = "{\"items\":[{\"id\":\"Open\"},null,{\"id\":25}]}"
let json = parse text
json.ToString() |> should equal text

[<Test>]
let ``Can serialise document with dates``() =
JObject
.New()
.AddDateProperty("dd", new System.DateTime(1997, 2, 15, 0, 0, 0, System.DateTimeKind.Utc))
.ToString()
|> should equal "{\"dd\":\"1997-02-15T00:00:00.0000000Z\"}"
module FSharpx.Tests.JSON.SerializationTests

open NUnit.Framework
open FSharpx.JSON
open FSharpx.JSON.DocumentExtensions
open FsUnit

[<Test>]
let ``Can serialize empty document``() =
JObject.New().ToString()
|> should equal "{}"

[<Test>]
let ``Can serialize document with single property``() =
JObject
.New()
.AddTextProperty("firstName","John")
.ToString()
|> should equal "{\"firstName\":\"John\"}"

[<Test>]
let ``Can serialize document with booleans``() =
JObject
.New()
.AddBoolProperty("aa",true)
.AddBoolProperty("bb",false)
.ToString()
|> should equal "{\"aa\":true,\"bb\":false}"

[<Test>]
let ``Can serialize document with array, null and number``() =
let text = "{\"items\":[{\"id\":\"Open\"},null,{\"id\":25}]}"
let json = parse text
json.ToString() |> should equal text
16 changes: 0 additions & 16 deletions tests/FSharpx.TypeProviders.Documents.Tests/JSON.Dates.Tests.fs
Expand Up @@ -27,19 +27,3 @@ let ``Can parse UTC dates``() =
let ``Can parse ISO 8601 dates in the correct culture``() =
let dates = new DateJSON()
dates.Root.NoTimeZone |> should equal (new DateTime(1997, 7, 16, 19, 20, 30, 00, System.DateTimeKind.Local))

type singleDate = StructuredJSON<Schema="""{ "anniversary" : "1990-01-01" }""">

[<Test>]
let ``Set a Date``() =
let dates = new singleDate()
dates.Root.Anniversary <- new DateTime(2012, 1, 29, 12, 30, 00, DateTimeKind.Utc)
dates.ToString() |> should equal """{"anniversary":"2012-01-29T12:30:00.0000000Z"}"""

[<Test>]
let ``Round Trip a Date``() =
let dates = new singleDate()
dates.Root.Anniversary <- new DateTime(2012, 1, 29, 12, 30, 00, DateTimeKind.Utc)
dates.ToString() |> should equal """{"anniversary":"2012-01-29T12:30:00.0000000Z"}"""
let dates2 = singleDate(documentContent=(dates.ToString()))
dates2.Root.Anniversary |> should equal (new DateTime(2012, 1, 29, 12, 30, 00, DateTimeKind.Utc))

0 comments on commit 96b5eee

Please sign in to comment.