File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -218,3 +218,23 @@ extension DateInterval : _ObjectTypeBridgeable {
218
218
return result!
219
219
}
220
220
}
221
+
222
+ extension DateInterval : Codable {
223
+ enum CodingKeys : String , CodingKey {
224
+ case start
225
+ case duration
226
+ }
227
+
228
+ public init ( from decoder: Decoder ) throws {
229
+ let container = try decoder. container ( keyedBy: CodingKeys . self)
230
+ let start = try container. decode ( Date . self, forKey: . start)
231
+ let duration = try container. decode ( TimeInterval . self, forKey: . duration)
232
+ self . init ( start: start, duration: duration)
233
+ }
234
+
235
+ public func encode( to encoder: Encoder ) throws {
236
+ var container = encoder. container ( keyedBy: CodingKeys . self)
237
+ try container. encode ( self . start, forKey: . start)
238
+ try container. encode ( self . duration, forKey: . duration)
239
+ }
240
+ }
You can’t perform that action at this time.
0 commit comments