Skip to content

Commit

Permalink
Minor syntax & documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Dec 21, 2020
1 parent f741514 commit 5a108ef
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
27 changes: 27 additions & 0 deletions Sources/OTCore/Swift Extensions/DateComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,34 @@ extension DateComponents {

/// OTCore:
/// Parse a date string heuristically in a variety of formats.
///
/// Only produces day, month and year components.
///
/// Acceptable formats include:
///
/// ```
/// 10-21-20 (or 10/21/20)
/// 21-10-20 (or 21/10/20)
///
/// 2020-10-21 (or 2020/10/21)
/// 2020-21-10 (or 2020/21/10)
/// 10-21-2020 (or 10/21/2020)
/// 21-10-2020 (or 21/10/2020)
///
/// 2020-Oct-21 (or 2020/Oct/21)
/// 2020-21-Oct (or 2020/21/Oct)
///
/// Oct 21 2020
/// October 21 2020
/// Oct 21, 2020
/// October 21, 2020
/// 21 Oct 2020
/// 21 October 2020
///
/// 21Oct2020
/// 2020Oct21
///
/// ```
public init?(string: String) {

self.init()
Expand Down
2 changes: 1 addition & 1 deletion Sources/OTCore/Swift Extensions/FloatingPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ extension FloatingPoint {

/// OTCore:
/// Returns both integral part and fractional part.
/// This methos is more computationally efficient than calling `.integral` and .`fraction` properties separately unless you only require one or the other.
/// This method is more computationally efficient than calling `.integral` and .`fraction` properties separately unless you only require one or the other.
///
/// Note: this can result in a non-trivial loss of precision for the fractional part.
public var integralAndFraction: (integral: Self, fraction: Self) {
Expand Down
23 changes: 18 additions & 5 deletions Sources/OTCore/Timespec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@

import Foundation

// CLOCK_MONOTONIC clock that increments monotonically, tracking the time since an arbitrary point, and will continue to increment while the system is asleep.
// Derived from https://stackoverflow.com/a/45068046/2805570

// Apple docs:
//
// CLOCK_MONOTONIC
// clock that increments monotonically, tracking the time since an arbitrary point, and will continue to increment while the system is asleep.
//
// CLOCK_MONOTONIC_RAW clock that increments monotonically, tracking the time since an arbitrary point like CLOCK_MONOTONIC. However, this clock is unaffected by frequency or time adjustments. It should not be compared to other system time sources.
// CLOCK_MONOTONIC_RAW
// clock that increments monotonically, tracking the time since an arbitrary point like CLOCK_MONOTONIC. However, this clock is unaffected by frequency or time adjustments. It should not be compared to other system time sources.
//
// CLOCK_MONOTONIC_RAW_APPROX like CLOCK_MONOTONIC_RAW, but reads a value cached by the system at context switch. This can be read faster, but at a loss of accuracy as it may return values that are milliseconds old.
// CLOCK_MONOTONIC_RAW_APPROX
// like CLOCK_MONOTONIC_RAW, but reads a value cached by the system at context switch. This can be read faster, but at a loss of accuracy as it may return values that are milliseconds old.
//
// CLOCK_UPTIME_RAW clock that increments monotonically, in the same manner as CLOCK_MONOTONIC_RAW, but that does not increment while the system is asleep. The returned value is identical to the result of mach_absolute_time() after the appropriate mach_timebase conversion is applied.
// CLOCK_UPTIME_RAW
// clock that increments monotonically, in the same manner as CLOCK_MONOTONIC_RAW, but that does not increment while the system is asleep. The returned value is identical to the result of mach_absolute_time() after the appropriate mach_timebase conversion is applied.

/// OTCore:
/// Returns high-precision system uptime
///
/// This is preferable to using `mach_absolute_time()` since `mach_absolute_time()` is macOS-only.
Expand All @@ -36,6 +45,7 @@ public func clock_gettime_monotonic_raw() -> timespec {

// MARK: - Timespec operators and comparison

/// OTCore
public func + (lhs: timespec, rhs: timespec) -> timespec {

let nsRaw = rhs.tv_nsec + lhs.tv_nsec
Expand All @@ -48,6 +58,7 @@ public func + (lhs: timespec, rhs: timespec) -> timespec {

}

/// OTCore
public func - (lhs: timespec, rhs: timespec) -> timespec {

let nsRaw = lhs.tv_nsec - rhs.tv_nsec
Expand Down Expand Up @@ -76,6 +87,7 @@ public func - (lhs: timespec, rhs: timespec) -> timespec {

extension timespec: Equatable {

/// OTCore
static public func == (lhs: Self, rhs: Self) -> Bool {

return lhs.tv_sec == rhs.tv_sec &&
Expand All @@ -86,7 +98,8 @@ extension timespec: Equatable {
}

extension timespec: Comparable {


/// OTCore
public static func < (lhs: timespec, rhs: timespec) -> Bool {

if lhs.tv_sec < rhs.tv_sec { return true }
Expand Down

0 comments on commit 5a108ef

Please sign in to comment.