Skip to content
This repository was archived by the owner on Nov 18, 2018. It is now read-only.

Commit a2b98be

Browse files
committed
got JSONEncodable working
1 parent b96460e commit a2b98be

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Sources/BinaryJSON/JSONEncodable.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extension BSON.Value: JSONEncodable {
7474

7575
case let .RegularExpression(regularExpression): return regularExpression.toJSON()
7676

77-
case let .Date(date): return .Object(["$date": .Number(.Double(date.timeIntervalSince1970))])
77+
case let .Date(date): return .Object(["$date": .Number(.Integer(Int(date.timeIntervalSince1970 * 1000)))])
7878
}
7979
}
8080
}
@@ -114,12 +114,12 @@ extension BSON.Timestamp: JSONEncodable {
114114

115115
private enum JSONKey: String {
116116

117-
case t, i
117+
case t, i, timestamp = "$timestamp"
118118
}
119119

120120
public func toJSON() -> JSON.Value {
121121

122-
return .Object([JSONKey.t.rawValue: .Number(.Integer(Int(time))), JSONKey.i.rawValue: .Number(.Integer(Int(oridinal)))])
122+
return .Object([JSONKey.timestamp.rawValue: .Object([JSONKey.t.rawValue: .Number(.Integer(Int(time))), JSONKey.i.rawValue: .Number(.Integer(Int(oridinal)))])])
123123
}
124124
}
125125

@@ -137,7 +137,7 @@ extension BSON.Binary: JSONEncodable {
137137

138138
guard let base64String = String(UTF8Data: base64EncodedData)
139139
else { fatalError("Could not create string from Base64 data") }
140-
140+
141141
let subtypeHexString = String(format:"%02hhX", subtype.rawValue)
142142

143143
return .Object([JSONKey.binary.rawValue: .String(base64String), JSONKey.type.rawValue: .String(subtypeHexString)])

0 commit comments

Comments
 (0)