@@ -269,7 +269,6 @@ public class CouchDBClient {
269
269
270
270
let data = Data ( bytes)
271
271
let decoder = JSONDecoder ( )
272
- decoder. dateDecodingStrategy = . secondsSince1970
273
272
274
273
do {
275
274
let decodedResponse = try decoder. decode ( UpdateDBResponse . self, from: data)
@@ -327,7 +326,6 @@ public class CouchDBClient {
327
326
328
327
let data = Data ( bytes)
329
328
let decoder = JSONDecoder ( )
330
- decoder. dateDecodingStrategy = . secondsSince1970
331
329
332
330
do {
333
331
let decodedResponse = try decoder. decode ( UpdateDBResponse . self, from: data)
@@ -453,7 +451,7 @@ public class CouchDBClient {
453
451
/// - queryItems: Request query items.
454
452
/// - eventLoopGroup: NIO's EventLoopGroup object. New will be created if nil value provided.
455
453
/// - Returns: An object or a struct (of generic type) parsed from JSON.
456
- public func get < T: Codable & CouchDBRepresentable > ( dbName: String , uri: String , queryItems: [ URLQueryItem ] ? = nil , eventLoopGroup: EventLoopGroup ? = nil ) async throws -> T {
454
+ public func get < T: Codable & CouchDBRepresentable > ( dbName: String , uri: String , queryItems: [ URLQueryItem ] ? = nil , dateDecodingStrategy : JSONDecoder . DateDecodingStrategy = . secondsSince1970 , eventLoopGroup: EventLoopGroup ? = nil ) async throws -> T {
457
455
let response = try await get ( dbName: dbName, uri: uri, queryItems: queryItems, eventLoopGroup: eventLoopGroup)
458
456
459
457
if response. status == . unauthorized {
@@ -466,7 +464,7 @@ public class CouchDBClient {
466
464
467
465
let data = Data ( bytes)
468
466
let decoder = JSONDecoder ( )
469
- decoder. dateDecodingStrategy = . secondsSince1970
467
+ decoder. dateDecodingStrategy = dateDecodingStrategy
470
468
471
469
do {
472
470
let doc = try decoder. decode ( T . self, from: data)
@@ -557,7 +555,6 @@ public class CouchDBClient {
557
555
558
556
let data = Data ( bytes)
559
557
let decoder = JSONDecoder ( )
560
- decoder. dateDecodingStrategy = . secondsSince1970
561
558
562
559
do {
563
560
let decodedResponse = try decoder. decode ( CouchUpdateResponse . self, from: data)
@@ -605,12 +602,12 @@ public class CouchDBClient {
605
602
/// - doc: Document object/struct. Should confirm to ``CouchDBRepresentable`` and Codable protocols.
606
603
/// - eventLoopGroup: NIO's EventLoopGroup object. New will be created if nil value provided.
607
604
/// - Returns: Update response.
608
- public func update < T: Codable & CouchDBRepresentable > ( dbName: String , doc: inout T , eventLoopGroup: EventLoopGroup ? = nil ) async throws {
605
+ public func update < T: Codable & CouchDBRepresentable > ( dbName: String , doc: inout T , dateEncodingStrategy : JSONEncoder . DateEncodingStrategy = . secondsSince1970 , eventLoopGroup: EventLoopGroup ? = nil ) async throws {
609
606
guard let id = doc. _id else { throw CouchDBClientError . idMissing }
610
607
guard doc. _rev? . isEmpty == false else { throw CouchDBClientError . revMissing }
611
608
612
609
let encoder = JSONEncoder ( )
613
- encoder. dateEncodingStrategy = . secondsSince1970
610
+ encoder. dateEncodingStrategy = dateEncodingStrategy
614
611
let encodedData = try JSONEncoder ( ) . encode ( doc)
615
612
616
613
let updateResponse = try await update (
@@ -695,7 +692,6 @@ public class CouchDBClient {
695
692
696
693
let data = Data ( bytes)
697
694
let decoder = JSONDecoder ( )
698
- decoder. dateDecodingStrategy = . secondsSince1970
699
695
700
696
do {
701
697
let decodedResponse = try decoder. decode ( CouchUpdateResponse . self, from: data)
@@ -738,8 +734,11 @@ public class CouchDBClient {
738
734
/// - dbName: DB name.
739
735
/// - doc: Document object/struct. Should confirm to ``CouchDBRepresentable`` protocol.
740
736
/// - eventLoopGroup: NIO's EventLoopGroup object. New will be created if nil value provided.
741
- public func insert < T: Codable & CouchDBRepresentable > ( dbName: String , doc: inout T , eventLoopGroup: EventLoopGroup ? = nil ) async throws {
742
- let insertEncodeData = try JSONEncoder ( ) . encode ( doc)
737
+ public func insert < T: Codable & CouchDBRepresentable > ( dbName: String , doc: inout T , dateEncodingStrategy: JSONEncoder . DateEncodingStrategy = . secondsSince1970, eventLoopGroup: EventLoopGroup ? = nil ) async throws {
738
+ let encoder = JSONEncoder ( )
739
+ encoder. dateEncodingStrategy = dateEncodingStrategy
740
+ let insertEncodeData = try encoder. encode ( doc)
741
+
743
742
let insertResponse = try await insert (
744
743
dbName: dbName,
745
744
body: . data( insertEncodeData) ,
0 commit comments