Skip to content

Commit a5045b9

Browse files
committed
docs(README): update to mention Point Free Dependencies wrapper
1 parent b7379ed commit a5045b9

File tree

1 file changed

+60
-11
lines changed

1 file changed

+60
-11
lines changed

README.md

+60-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
⏰🇬🇧 Recognize British English time and try converting it to `Date`
66

7+
This package contains two libraries that converts a British spoken time like `"It's sevent o'clock."` to an optional `Date` from **epoch** where you can easily extract hour and minute `DateComponents` if you want.
8+
9+
* `SwiftToTen` The main library and has a static function with this signature: `live(time: String, calendar: Calendar) -> Date?` where you simply providing a time like in the example above, see examples below
10+
* `SwiftToTenDependency` A wrapper around the library above facilitating the integration with [Point-Free Dependencies](https://github.com/pointfreeco/swift-dependencies) library or a project made with The Composable Architecture (TCA).
11+
712
## Usage
813

914
```swift
@@ -16,44 +21,85 @@ calendar.timeZone = TimeZone(secondsFromGMT: 0) ?? calendar.timeZone
1621
var recognizedTime: Date?
1722

1823
// Classic time with HH:mm format
19-
recognizedTime = SwiftToTen.recognizeTime(in: "It's 12:34", calendar: calendar)
24+
recognizedTime = SwiftToTen.live(time: "It's 12:34", calendar: calendar)
2025
print(recognizedTime) // Optional(1970-01-01 12:34:00 +0000)
2126

2227
// In the afternoon HH:mm pm format
23-
recognizedTime = SwiftToTen.recognizeTime(in: "It's 1:37 pm", calendar: calendar)
28+
recognizedTime = SwiftToTen.live(time: "It's 1:37 pm", calendar: calendar)
2429
print(recognizedTime) // Optional(1970-01-01 13:37:00 +0000)
2530

2631
// With o'clock format
27-
recognizedTime = SwiftToTen.recognizeTime(in: "It's 7 o'clock", calendar: calendar)
32+
recognizedTime = SwiftToTen.live(time: "It's 7 o'clock", calendar: calendar)
2833
print(recognizedTime) // Optional(1970-01-01 07:00:00 +0000)
2934

3035
// With o'clock format in the afternoon
31-
recognizedTime = SwiftToTen.recognizeTime(in: "It's 2 o'clock in the afternoon", calendar: calendar)
36+
recognizedTime = SwiftToTen.live(time: "It's 2 o'clock in the afternoon", calendar: calendar)
3237
print(recognizedTime) // Optional(1970-01-01 14:00:00 +0000)
3338

3439
// Midnight, ... to Midnight and ... past Midnight
35-
recognizedTime = SwiftToTen.recognizeTime(in: "It's midnight", calendar: calendar)
40+
recognizedTime = SwiftToTen.live(time: "It's midnight", calendar: calendar)
3641
print(recognizedTime) // Optional(1970-01-01 00:00:00 +0000)
3742

38-
recognizedTime = SwiftToTen.recognizeTime(in: "It's quarter to midnight", calendar: calendar)
43+
recognizedTime = SwiftToTen.live(time: "It's quarter to midnight", calendar: calendar)
3944
print(recognizedTime) // Optional(1970-01-01 23:45:00 +0000)
4045

41-
recognizedTime = SwiftToTen.recognizeTime(in: "It's 10 past midnight", calendar: calendar)
46+
recognizedTime = SwiftToTen.live(time: "It's 10 past midnight", calendar: calendar)
4247
print(recognizedTime) // Optional(1970-01-01 00:10:00 +0000)
4348

4449
// If the string doesn't contain a recognizable time, it returns `nil`
45-
recognizedTime = SwiftToTen.recognizeTime(in: "It's show time!", calendar: calendar)
50+
recognizedTime = SwiftToTen.live(time: "It's show time!", calendar: calendar)
4651
print(recognizedTime) // nil
4752
```
4853

54+
## [Point-Free Dependencies](https://github.com/pointfreeco/swift-dependencies) usage
55+
56+
Add `@Dependency(\.recognizeTime) var recognizeTime` in your `Reducer`, you will have access to all functions mentioned above.
57+
58+
### Example
59+
60+
```swift
61+
import ComposableArchitecture
62+
import Foundation
63+
import SwiftToTenDependency
64+
65+
public struct BritishTime: ReducerProtocol {
66+
public struct State: Equatable {
67+
public var date: Date?
68+
69+
public init(date: Date? = nil) {
70+
self.date = date
71+
}
72+
}
73+
74+
public enum Action: Equatable {
75+
case utteranceChanged(String)
76+
}
77+
78+
@Dependency(\.calendar) var calendar
79+
@Dependency(\.recognizeTime) var recognizeTime
80+
81+
public init() {}
82+
83+
public var body: some ReducerProtocol<State, Action> {
84+
Reduce { state, action in
85+
switch action {
86+
case let .utteranceChanged(utterance):
87+
state.date = recognizeTime(time: utterance, calendar: calendar)
88+
return .none
89+
}
90+
}
91+
}
92+
```
93+
4994
## Installation
5095

5196
### Xcode
5297

5398
You can add SwiftToTen to an Xcode project by adding it as a package dependency.
5499

55100
1. From the **File** menu, select **Swift Packages Add Package Dependency...**
56-
2. Enter "https://github.com/renaudjenny/swift-to-ten" into the package repository URL test field
101+
2. Enter "https://github.com/renaudjenny/swift-to-ten" into the package repository URL text field
102+
3. Select one of the library that you are interested in. See [above](#swifttoten)
57103

58104
### As package dependency
59105

@@ -63,13 +109,16 @@ Edit your `Package.swift` to add this library.
63109
let package = Package(
64110
...
65111
dependencies: [
66-
.package(url: "https://github.com/renaudjenny/swift-to-ten", from: "1.1.0"),
112+
.package(url: "https://github.com/renaudjenny/swift-to-ten", from: "1.2.0"),
67113
...
68114
],
69115
targets: [
70116
.target(
71117
name: "<Your project name>",
72-
dependencies: [.product(name: "SwiftToTen", package: "swift-to-ten")]
118+
dependencies: [
119+
.product(name: "SwiftToTen", package: "swift-to-ten"), // <-- Basic version
120+
.product(name: "SwiftToTenDependency", package: "swift-to-ten"), // <-- Point-Free Dependencies library wrapper
121+
]
73122
),
74123
...
75124
]

0 commit comments

Comments
 (0)