         XCTAssertEqual(JSON.string("hello"), JSON.string("hello"))
         XCTAssertEqual(JSON.int(1), JSON.int(1))
         XCTAssertEqual(JSON.double(0.5), JSON.double(0.5))
-        XCTAssertEqual(JSON.date(date), JSON.date(date))
+        XCTAssertEqual(JSON.date(date!), JSON.date(date!))
         XCTAssertEqual(JSON.array([JSON.int(1), JSON.int(2)]),
                        JSON.array([JSON.int(1), JSON.int(2)]))
         XCTAssertEqual(JSON.object(["x": JSON.int(1), "y": JSON.int(2)]),

    func testEquality() {
        // date values
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd"
        let stringDate = "2018-05-30"
        let stringDate2 = "2018-04-25"
        let date = dateFormatter.date(from: stringDate)
        let date2 = dateFormatter.date(from: stringDate2)



    func testEncodeDate() {
        let dateFormatter = DateFormatter()
        dateFormatter.calendar = Calendar(identifier: .iso8601)
        dateFormatter.locale = Locale(identifier: "en_US_POSIX")
        dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
        let stringDate = "2018-05-17T18:45:32.189Z"
        let date = dateFormatter.date(from: stringDate)

        let object: [String: JSON] = ["key": .date(date!)]
        let data = try! JSONEncoder().encode(object)
        let json = String(data: data, encoding: .utf8)!
        let expected = "{\"key\":\"17 May 2018 at 19:45\"}"
        XCTAssertEqual(json.sorted(), expected.sorted())
    }

