A Swift model for relative points in time. The API is based on the Dispatch library, but there are additional methods and operations added with some customized behavior for special values.
A few server side projects and some other Swift packages needed a representation of points in time. The projects also manipulated time (such as subtracting two points in time to find the relative difference). Instead of copying the code around between projects, this common Swift package is being used now as a dependency.
Add this package to your Package.swift
dependencies
and target's dependencies
:
import PackageDescription
let package = Package(
name: "Example",
dependencies: [
.package(
url: "https://github.com/bluk/TimePoint",
from: "0.9.0"
),
],
targets: [
.target(
name: "YourProject",
dependencies: ["TimePoint"]
)
]
)
import TimePoint
let firstPointInTime = TimePoint.now()
// Do some computation
let secondPointInTime = TimePoint.now()
let difference = secondPointInTime - firstPointInTime
While practically all of the functionality can be added as extensions to existing types, there are several other libraries that already added public extensions which cause conflicts. So instead of adding more potential code conflicts to a type that is owned by Apple, another type is necessary.