Skip to content

Commit 94941a3

Browse files
committed
Fix Date processing in context
1 parent c74df9e commit 94941a3

File tree

4 files changed

+53
-21
lines changed

4 files changed

+53
-21
lines changed

README.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ the [OpenFeature Swift SDK](https://github.com/open-feature/swift-sdk).
1212
If you manage dependencies through SPM, in the dependencies section of Package.swift add:
1313

1414
```swift
15-
.package(url: "https://github.com/configcat/openfeature-swift.git", from: "0.1.0")
15+
.package(url: "https://github.com/configcat/openfeature-swift", from: "0.1.0")
1616
```
1717

1818
and in the target dependencies section add:
@@ -22,17 +22,8 @@ and in the target dependencies section add:
2222

2323
### Xcode Dependencies
2424

25-
You have two options, both start from File > Add Packages... in the code menu.
26-
27-
First, ensure you have your GitHub account added as an option (+ > Add Source Control Account...). You will need to create a [Personal Access Token](https://github.com/settings/tokens) with the permissions defined in the Xcode interface.
28-
29-
1. Add as a remote repository
30-
* Search for `[email protected]:configcat/openfeature-swift.git` and click "Add Package"
31-
2. Clone the repository locally
32-
* Clone locally using your preferred method
33-
* Use the "Add Local..." button to select the local folder
34-
35-
**Note:** Option 2 is only recommended if you are making changes to the client SDK.
25+
- Open the dependencies dialog from `File` > `Add Package Dependencies...`
26+
- Search for `https://github.com/configcat/openfeature-swift` and click `Add Package`.
3627

3728
## Usage
3829

Sources/ConfigCatOpenFeature/Provider.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,7 @@ extension EvaluationContext {
194194
custom: self.asObjectMap().filter { $1 != nil }.reduce(
195195
into: [String: Any]()
196196
) { (part, arg) in
197-
if let date = arg.value as? Date {
198-
part[arg.key] = date.timeIntervalSince1970
199-
} else {
200-
part[arg.key] = arg.value as Any
201-
}
197+
part[arg.key] = arg.value as Any
202198
}
203199
)
204200
}

Tests/ConfigCatOpenFeatureTests/ProviderTests.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ class ProviderTests: XCTestCase {
5454
}
5555

5656
func testUser() {
57+
let date = parseDate(val: "2025-05-30T10:15:30.00Z")
5758
let context = MutableContext(targetingKey: "[email protected]", structure: MutableStructure(attributes: [
5859
"custom1": Value.string("something"),
5960
"custom2": Value.boolean(true),
6061
"custom3": Value.integer(5),
6162
"custom4": Value.double(1.2),
6263
"custom5": Value.list([Value.integer(1), Value.integer(2)]),
63-
"custom6": Value.date(parseDate(val: "2025-05-30T10:15:30.00Z")),
64+
"custom6": Value.date(date),
6465
]))
6566

6667
let user = context.toUserObject()
@@ -70,7 +71,7 @@ class ProviderTests: XCTestCase {
7071
XCTAssertEqual(5, user.attribute(for: "custom3") as! Int)
7172
XCTAssertEqual(1.2, user.attribute(for: "custom4") as! Double)
7273
XCTAssertEqual([1,2], user.attribute(for: "custom5") as! [Int])
73-
XCTAssertEqual(1748600130, user.attribute(for: "custom6") as! Double)
74+
XCTAssertEqual(date, user.attribute(for: "custom6") as! Date)
7475
}
7576

7677
func testTargeting() {
@@ -95,6 +96,22 @@ class ProviderTests: XCTestCase {
9596
XCTAssertEqual(Reason.targetingMatch.rawValue, customBoolVal.reason)
9697
}
9798

99+
func testDateTargeting() {
100+
let provider = ConfigCatProvider(sdkKey: "localhost") { opts in
101+
opts.flagOverrides = try! BundleResourceDataSource(path: "test_json_complex.json", behaviour: .localOnly)
102+
opts.logLevel = .debug
103+
}
104+
105+
let ctx = MutableContext(targetingKey: "[email protected]", structure: MutableStructure(attributes: [
106+
"Date": Value.date(parseDate(val: "2025-05-30T10:15:30.00Z"))
107+
]))
108+
109+
let boolVal = provider.getBooleanEvaluation(key: "dateTargeting", defaultValue: false, context: ctx)
110+
XCTAssertTrue(boolVal.value)
111+
XCTAssertEqual("date-targeting", boolVal.variant)
112+
XCTAssertEqual(Reason.targetingMatch.rawValue, boolVal.reason)
113+
}
114+
98115
func testErrors() {
99116
let provider = ConfigCatProvider(sdkKey: "localhost") { opts in
100117
opts.flagOverrides = try! BundleResourceDataSource(path: "test_json_complex.json", behaviour: .localOnly)

Tests/ConfigCatOpenFeatureTests/Resources/test_json_complex.json

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"u": {
1818
"a": "Identifier",
1919
"c": 2,
20-
"l": ["@matching.com"]
20+
"l": [
21+
"@matching.com"
22+
]
2123
}
2224
}
2325
],
@@ -30,6 +32,32 @@
3032
}
3133
]
3234
},
35+
"dateTargeting": {
36+
"t": 0,
37+
"r": [
38+
{
39+
"c": [
40+
{
41+
"u": {
42+
"a": "Date",
43+
"c": 18,
44+
"d": 1749996961.619
45+
}
46+
}
47+
],
48+
"s": {
49+
"v": {
50+
"b": true
51+
},
52+
"i": "date-targeting"
53+
}
54+
}
55+
],
56+
"v": {
57+
"b": false
58+
},
59+
"i": "date-default"
60+
},
3361
"enabledFeature": {
3462
"t": 0,
3563
"i": "v-enabled",
@@ -66,4 +94,4 @@
6694
}
6795
}
6896
}
69-
}
97+
}

0 commit comments

Comments
 (0)