Skip to content

Commit 3e62414

Browse files
committed
feat!: use instant not zoneddatetime
Signed-off-by: Todd Baert <[email protected]>
1 parent 0152a1e commit 3e62414

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

src/main/java/dev/openfeature/javasdk/EvaluationContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dev.openfeature.javasdk;
22

3-
import java.time.ZonedDateTime;
3+
import java.time.Instant;
44
import java.util.List;
55

66
import lombok.Getter;
@@ -76,7 +76,7 @@ public EvaluationContext add(String key, Double value) {
7676
return this;
7777
}
7878

79-
public EvaluationContext add(String key, ZonedDateTime value) {
79+
public EvaluationContext add(String key, Instant value) {
8080
this.structure.add(key, value);
8181
return this;
8282
}
@@ -123,7 +123,7 @@ public Structure add(String ignoredKey, Structure ignoredValue) {
123123
return null;
124124
}
125125

126-
public Structure add(String ignoredKey, ZonedDateTime ignoredValue) {
126+
public Structure add(String ignoredKey, Instant ignoredValue) {
127127
return null;
128128
}
129129
}

src/main/java/dev/openfeature/javasdk/Structure.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dev.openfeature.javasdk;
22

3-
import java.time.ZonedDateTime;
3+
import java.time.Instant;
44
import java.util.HashMap;
55
import java.util.List;
66
import java.util.Map;
@@ -73,7 +73,7 @@ public Structure add(String key, Double value) {
7373
* @param value date-time value
7474
* @return Structure
7575
*/
76-
public Structure add(String key, ZonedDateTime value) {
76+
public Structure add(String key, Instant value) {
7777
attributes.put(key, new Value(value));
7878
return this;
7979
}

src/main/java/dev/openfeature/javasdk/Value.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dev.openfeature.javasdk;
22

3-
import java.time.ZonedDateTime;
3+
import java.time.Instant;
44
import java.util.List;
55

66
import lombok.EqualsAndHashCode;
@@ -54,7 +54,7 @@ public Value(List<Value> value) {
5454
this.innerObject = value;
5555
}
5656

57-
public Value(ZonedDateTime value) {
57+
public Value(Instant value) {
5858
this.innerObject = value;
5959
}
6060

@@ -113,12 +113,12 @@ public boolean isList() {
113113
}
114114

115115
/**
116-
* Check if this Value represents a ZonedDateTime.
116+
* Check if this Value represents an Instant.
117117
*
118118
* @return boolean
119119
*/
120-
public boolean isZonedDateTime() {
121-
return this.innerObject instanceof ZonedDateTime;
120+
public boolean isInstant() {
121+
return this.innerObject instanceof Instant;
122122
}
123123

124124
/**
@@ -207,13 +207,13 @@ public List<Value> asList() {
207207
}
208208

209209
/**
210-
* Retrieve the underlying ZonedDateTime value, or null.
210+
* Retrieve the underlying Instant value, or null.
211211
*
212-
* @return ZonedDateTime
212+
* @return Instant
213213
*/
214-
public ZonedDateTime asZonedDateTime() {
215-
if (this.isZonedDateTime()) {
216-
return (ZonedDateTime)this.innerObject;
214+
public Instant asInstant() {
215+
if (this.isInstant()) {
216+
return (Instant)this.innerObject;
217217
}
218218
return null;
219219
}

src/test/java/dev/openfeature/javasdk/EvalContextTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

5-
import java.time.ZonedDateTime;
5+
import java.time.Instant;
66
import java.util.ArrayList;
77
import java.util.List;
88
import java.util.Map;
@@ -34,9 +34,9 @@ public class EvalContextTest {
3434
ec.add("int", 4);
3535
assertEquals(4, ec.getValue("int").asInteger());
3636

37-
ZonedDateTime dt = ZonedDateTime.now();
37+
Instant dt = Instant.now();
3838
ec.add("dt", dt);
39-
assertEquals(dt, ec.getValue("dt").asZonedDateTime());
39+
assertEquals(dt, ec.getValue("dt").asInstant());
4040
}
4141

4242
@Specification(number="3.1.2", text="The evaluation context MUST support the inclusion of " +
@@ -72,7 +72,7 @@ public class EvalContextTest {
7272
ec.add("int", 4);
7373
ec.add("int2", 2);
7474

75-
ZonedDateTime dt = ZonedDateTime.now();
75+
Instant dt = Instant.now();
7676
ec.add("dt", dt);
7777

7878
ec.add("obj", new Structure().add("val1", 1).add("val2", "2"));
@@ -121,14 +121,14 @@ public class EvalContextTest {
121121
.add("Double", (Double)null)
122122
.add("Structure", (Structure)null)
123123
.add("List", (List<Value>)null)
124-
.add("ZonedDateTime", (ZonedDateTime)null);
124+
.add("Instant", (Instant)null);
125125
assertEquals(6, ec.asMap().size());
126126
assertEquals(null, ec.getValue("Boolean").asBoolean());
127127
assertEquals(null, ec.getValue("String").asString());
128128
assertEquals(null, ec.getValue("Double").asDouble());
129129
assertEquals(null, ec.getValue("Structure").asStructure());
130130
assertEquals(null, ec.getValue("List").asList());
131-
assertEquals(null, ec.getValue("ZonedDateTime").asString());
131+
assertEquals(null, ec.getValue("Instant").asString());
132132
}
133133

134134
@Test void merge_targeting_key() {

src/test/java/dev/openfeature/javasdk/StructureTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import static org.junit.jupiter.api.Assertions.assertNotSame;
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66

7-
import java.time.ZonedDateTime;
7+
import java.time.Instant;
88
import java.util.ArrayList;
99
import java.util.HashMap;
1010
import java.util.List;
@@ -44,7 +44,7 @@ public class StructureTest {
4444
String STRING_VAL = "val";
4545
int INT_VAL = 13;
4646
double DOUBLE_VAL = .5;
47-
ZonedDateTime DATE_VAL = ZonedDateTime.now();
47+
Instant DATE_VAL = Instant.now();
4848
Structure STRUCT_VAL = new Structure();
4949
List<Value> LIST_VAL = new ArrayList<Value>();
5050
Value VALUE_VAL = new Value();
@@ -63,7 +63,7 @@ public class StructureTest {
6363
assertEquals(STRING_VAL, structure.getValue(STRING_KEY).asString());
6464
assertEquals(INT_VAL, structure.getValue(INT_KEY).asInteger());
6565
assertEquals(DOUBLE_VAL, structure.getValue(DOUBLE_KEY).asDouble());
66-
assertEquals(DATE_VAL, structure.getValue(DATE_KEY).asZonedDateTime());
66+
assertEquals(DATE_VAL, structure.getValue(DATE_KEY).asInstant());
6767
assertEquals(STRUCT_VAL, structure.getValue(STRUCT_KEY).asStructure());
6868
assertEquals(LIST_VAL, structure.getValue(LIST_KEY).asList());
6969
assertTrue(structure.getValue(VALUE_KEY).isNull());

src/test/java/dev/openfeature/javasdk/ValueTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertTrue;
55

6-
import java.time.ZonedDateTime;
6+
import java.time.Instant;
77
import java.util.ArrayList;
88
import java.util.List;
99

@@ -50,10 +50,10 @@ public class ValueTest {
5050
}
5151

5252
@Test public void dateShouldContainDate() {
53-
ZonedDateTime innerValue = ZonedDateTime.now();
53+
Instant innerValue = Instant.now();
5454
Value value = new Value(innerValue);
55-
assertTrue(value.isZonedDateTime());
56-
assertEquals(innerValue, value.asZonedDateTime());
55+
assertTrue(value.isInstant());
56+
assertEquals(innerValue, value.asInstant());
5757
}
5858

5959
@Test public void structureShouldContainStructure() {

0 commit comments

Comments
 (0)