@@ -259,13 +259,18 @@ extension VAPID.Configuration {
259
259
case unknown
260
260
}
261
261
262
+ /// A duration in seconds used to express when VAPID tokens will expire.
262
263
public struct Duration : Hashable , Comparable , Codable , ExpressibleByIntegerLiteral , AdditiveArithmetic , Sendable {
264
+ /// The number of seconds represented by this duration.
263
265
public let seconds : Int
264
266
267
+ /// Initialize a duration with a number of seconds.
268
+ @inlinable
265
269
public init ( seconds: Int ) {
266
270
self . seconds = seconds
267
271
}
268
272
273
+ @inlinable
269
274
public static func < ( lhs: Self , rhs: Self ) -> Bool {
270
275
lhs. seconds < rhs. seconds
271
276
}
@@ -280,37 +285,49 @@ extension VAPID.Configuration {
280
285
try container. encode ( self . seconds)
281
286
}
282
287
288
+ @inlinable
283
289
public init ( integerLiteral value: Int ) {
284
290
self . seconds = value
285
291
}
286
292
293
+ @inlinable
287
294
public static func - ( lhs: Self , rhs: Self ) -> Self {
288
295
Self ( seconds: lhs. seconds - rhs. seconds)
289
296
}
290
297
298
+ @inlinable
291
299
public static func + ( lhs: Self , rhs: Self ) -> Self {
292
300
Self ( seconds: lhs. seconds + rhs. seconds)
293
301
}
294
302
303
+ /// Make a duration with a number of seconds.
304
+ @inlinable
295
305
public static func seconds( _ seconds: Int ) -> Self {
296
306
Self ( seconds: seconds)
297
307
}
298
308
309
+ /// Make a duration with a number of minutes.
310
+ @inlinable
299
311
public static func minutes( _ minutes: Int ) -> Self {
300
- Self ( seconds: minutes*60)
312
+ . seconds( minutes*60)
301
313
}
302
314
315
+ /// Make a duration with a number of hours.
316
+ @inlinable
303
317
public static func hours( _ hours: Int ) -> Self {
304
- Self ( seconds : hours*60 *60)
318
+ . minutes ( hours*60)
305
319
}
306
320
321
+ /// Make a duration with a number of days.
322
+ @inlinable
307
323
public static func days( _ days: Int ) -> Self {
308
- Self ( seconds : days*24*60*60 )
324
+ . hours ( days*24)
309
325
}
310
326
}
311
327
}
312
328
313
329
extension Date {
330
+ /// Helper to add a duration to a date.
314
331
func adding( _ duration: VAPID . Configuration . Duration ) -> Self {
315
332
addingTimeInterval ( TimeInterval ( duration. seconds) )
316
333
}
0 commit comments