Skip to content

Commit 466c14e

Browse files
Added documentation to VAPID durations
1 parent b719dba commit 466c14e

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Sources/WebPush/VAPID/VAPIDConfiguration.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,18 @@ extension VAPID.Configuration {
259259
case unknown
260260
}
261261

262+
/// A duration in seconds used to express when VAPID tokens will expire.
262263
public struct Duration: Hashable, Comparable, Codable, ExpressibleByIntegerLiteral, AdditiveArithmetic, Sendable {
264+
/// The number of seconds represented by this duration.
263265
public let seconds: Int
264266

267+
/// Initialize a duration with a number of seconds.
268+
@inlinable
265269
public init(seconds: Int) {
266270
self.seconds = seconds
267271
}
268272

273+
@inlinable
269274
public static func < (lhs: Self, rhs: Self) -> Bool {
270275
lhs.seconds < rhs.seconds
271276
}
@@ -280,37 +285,49 @@ extension VAPID.Configuration {
280285
try container.encode(self.seconds)
281286
}
282287

288+
@inlinable
283289
public init(integerLiteral value: Int) {
284290
self.seconds = value
285291
}
286292

293+
@inlinable
287294
public static func - (lhs: Self, rhs: Self) -> Self {
288295
Self(seconds: lhs.seconds - rhs.seconds)
289296
}
290297

298+
@inlinable
291299
public static func + (lhs: Self, rhs: Self) -> Self {
292300
Self(seconds: lhs.seconds + rhs.seconds)
293301
}
294302

303+
/// Make a duration with a number of seconds.
304+
@inlinable
295305
public static func seconds(_ seconds: Int) -> Self {
296306
Self(seconds: seconds)
297307
}
298308

309+
/// Make a duration with a number of minutes.
310+
@inlinable
299311
public static func minutes(_ minutes: Int) -> Self {
300-
Self(seconds: minutes*60)
312+
.seconds(minutes*60)
301313
}
302314

315+
/// Make a duration with a number of hours.
316+
@inlinable
303317
public static func hours(_ hours: Int) -> Self {
304-
Self(seconds: hours*60*60)
318+
.minutes(hours*60)
305319
}
306320

321+
/// Make a duration with a number of days.
322+
@inlinable
307323
public static func days(_ days: Int) -> Self {
308-
Self(seconds: days*24*60*60)
324+
.hours(days*24)
309325
}
310326
}
311327
}
312328

313329
extension Date {
330+
/// Helper to add a duration to a date.
314331
func adding(_ duration: VAPID.Configuration.Duration) -> Self {
315332
addingTimeInterval(TimeInterval(duration.seconds))
316333
}

0 commit comments

Comments
 (0)