             
         case let .RegularExpression(regularExpression): return regularExpression.toJSON()
             
-        case let .Date(date): return .Object(["$date": .Number(.Double(date.timeIntervalSince1970))])
+        case let .Date(date): return .Object(["$date": .Number(.Integer(Int(date.timeIntervalSince1970 * 1000)))])
         }
     }
 }

    
    private enum JSONKey: String {
        
        case t, i
    }
    
    public func toJSON() -> JSON.Value {
        
        return .Object([JSONKey.t.rawValue: .Number(.Integer(Int(time))), JSONKey.i.rawValue: .Number(.Integer(Int(oridinal)))])
    }
}


        
        guard let base64String = String(UTF8Data: base64EncodedData)
            else { fatalError("Could not create string from Base64 data") }
        
        let subtypeHexString = String(format:"%02hhX", subtype.rawValue)
        
        return .Object([JSONKey.binary.rawValue: .String(base64String), JSONKey.type.rawValue: .String(subtypeHexString)])
