Skip to content

Commit 606aaca

Browse files
Merge pull request #53 from klassen-software-solutions/development/v5
Development/v5
2 parents 9bdc96d + f74de10 commit 606aaca

20 files changed

+1112
-128
lines changed

Dependencies/prereqs-licenses.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"generated": {
44
"process": "license-scanner",
55
"project": "KSSCore",
6-
"time": "2020-09-07T14:37:28.101098-06:00"
6+
"time": "2020-09-11T17:45:47.870292-06:00"
77
}
88
}

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PackageDescription
66
let package = Package(
77
name: "KSSCore",
88
platforms: [
9-
.macOS(.v10_11),
9+
.macOS(.v10_12),
1010
.iOS(.v13),
1111
],
1212
products: [
@@ -17,7 +17,7 @@ let package = Package(
1717
targets: [
1818
.target(name: "KSSFoundation", dependencies: []),
1919
.target(name: "KSSTest", dependencies: []),
20-
.testTarget(name: "KSSFoundationTests", dependencies: ["KSSFoundation"]),
20+
.testTarget(name: "KSSFoundationTests", dependencies: ["KSSFoundation", "KSSTest"]),
2121
.testTarget(name: "KSSTestTests", dependencies: ["KSSTest"]),
2222
]
2323
)

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ The modules provided by this package are the following:
1414

1515
[API Documentation](https://www.kss.cc/apis/KSSCore/docs/index.html)
1616

17+
## What Has Changed In Version 5
18+
19+
This was only going to be a minor change bringing us to V4.1, however the logging was becoming
20+
more and more cumbersome due to the limitations is OSX pre 10.12. So we have made 10.12 the
21+
new minimum for this library.
22+
23+
In addition this version includes the following:
24+
25+
* Made the XCTest extension for `expect` more general and removed the older version of the API.
26+
* Added the ability to watch a file and obtain the change notifications. This is a wrapper around the
27+
Apple Core Services, hence is not available on Linux.
28+
* Added a simple version of `os_log` for Linux for internal use only. (So some items that were previously
29+
logged in OSX and silent on Linux, are now logged on Linux as well.)
30+
* Added an additional `duration` version that computes a duration from a given date. This is more
31+
accurate than the previous version, which still exists, which does not require a given date but uses
32+
approximate values for the length of a month and year.
33+
1734
## What Has Changed In Version 4
1835

1936
The primary change from version 3 to 4 is that all the UI related items have been removed

Sources/KSSFoundation/Duration.swift

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,60 @@
66
// Copyright © 2020 Klassen Software Solutions. All rights reserved.
77
//
88

9+
#if canImport(os)
10+
import os
11+
#endif
12+
913
import Foundation
1014

1115

1216
/**
1317
Create a duration of the given units and return it as a `TimeInterval.`
18+
- warning: The resulting time interval will be approximate, using the assumptions described
19+
for the `DurationUnit`.
1420
*/
1521
public func duration(_ count: Double, _ unit: DurationUnit) -> TimeInterval {
1622
return count * unit.rawValue
1723
}
1824

1925

26+
/**
27+
Create a duration of the given units and return it as a `TimeInterval.` This version creates a duration
28+
assuming the given starting time and will take into account the correct calendar information in terms
29+
of days of the month and so on. If the calendar cannot compute an appropriate interval, then `nil` is
30+
returned.
31+
- warning: This uses the user's current calendar for the computation. This may lead to slightly
32+
different results for different calendars. For example, crossing daylight savings time gives answers
33+
that differ by an hour for calendars that take daylight savings into account.
34+
*/
35+
public func duration(_ count: Int, _ unit: DurationUnit, from start: Date = Date()) -> TimeInterval? {
36+
var component = DateComponents()
37+
switch unit {
38+
case .seconds: component.second = count
39+
case .minutes: component.minute = count
40+
case .hours: component.hour = count
41+
case .days: component.day = count
42+
case .weeks: component.day = count * 7
43+
case .months: component.month = count
44+
case .years: component.year = count
45+
}
46+
47+
guard let newDate = Calendar.current.date(byAdding: component, to: start) else {
48+
os_log("warning: could not compute the requested interval, using an approximation")
49+
return nil
50+
}
51+
52+
return newDate.timeIntervalSince(start)
53+
}
54+
2055
/**
2156
Enumeration to specify the unit of a given duration. The raw value of the enumeration is a TimeInterval
2257
that specifies the conversion from this unit into seconds.
2358

2459
- warning:
2560
This conversion is only approximate and does not consider leap years or even the difference between
26-
months. For example, one year will always be considered 365 days and one month will always be considered
27-
30 days. For more accurate durations you will need to use the `Date` and related classes directly.
61+
months. Most of the time this will not matter, but if the more accurate conversion fails, these values will
62+
be used as a fallback mechanism for generating the interval.
2863
*/
2964
public enum DurationUnit: TimeInterval {
3065
/// Conversion of one second to a `TimeInterval`
@@ -38,7 +73,7 @@ public enum DurationUnit: TimeInterval {
3873

3974
/// Conversion of one day to a `TimeInterval`
4075
case days = 86400.0
41-
76+
4277
/// Conversion of one week to a `TimeInterval`
4378
case weeks = 604800.0
4479

Sources/KSSFoundation/FileManagerExtension.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public extension FileManager {
7575
- withPrefix: A prefix that will be used for the directory name. Note that this is just the prefix
7676
of the directory, not the path that leads to the directory.
7777
*/
78-
@available(OSX 10.12, *)
7978
func createTemporaryDirectory(withPrefix prefix: String = "temp_") throws -> URL {
8079
let directoryName = prefix + UUID().uuidString
8180
let url = temporaryDirectory.appendingPathComponent(directoryName, isDirectory: true)

0 commit comments

Comments
 (0)