From 3e6241422266825f267043e4acd116803c4939b0 Mon Sep 17 00:00:00 2001 From: Todd Baert Date: Fri, 9 Sep 2022 10:46:00 -0400 Subject: [PATCH] feat!: use instant not zoneddatetime Signed-off-by: Todd Baert --- .../javasdk/EvaluationContext.java | 6 +++--- .../dev/openfeature/javasdk/Structure.java | 4 ++-- .../java/dev/openfeature/javasdk/Value.java | 20 +++++++++---------- .../openfeature/javasdk/EvalContextTest.java | 12 +++++------ .../openfeature/javasdk/StructureTest.java | 6 +++--- .../dev/openfeature/javasdk/ValueTest.java | 8 ++++---- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/dev/openfeature/javasdk/EvaluationContext.java b/src/main/java/dev/openfeature/javasdk/EvaluationContext.java index fe9740b8f..f7f11aded 100644 --- a/src/main/java/dev/openfeature/javasdk/EvaluationContext.java +++ b/src/main/java/dev/openfeature/javasdk/EvaluationContext.java @@ -1,6 +1,6 @@ package dev.openfeature.javasdk; -import java.time.ZonedDateTime; +import java.time.Instant; import java.util.List; import lombok.Getter; @@ -76,7 +76,7 @@ public EvaluationContext add(String key, Double value) { return this; } - public EvaluationContext add(String key, ZonedDateTime value) { + public EvaluationContext add(String key, Instant value) { this.structure.add(key, value); return this; } @@ -123,7 +123,7 @@ public Structure add(String ignoredKey, Structure ignoredValue) { return null; } - public Structure add(String ignoredKey, ZonedDateTime ignoredValue) { + public Structure add(String ignoredKey, Instant ignoredValue) { return null; } } diff --git a/src/main/java/dev/openfeature/javasdk/Structure.java b/src/main/java/dev/openfeature/javasdk/Structure.java index 062750fb8..38ff2f890 100644 --- a/src/main/java/dev/openfeature/javasdk/Structure.java +++ b/src/main/java/dev/openfeature/javasdk/Structure.java @@ -1,6 +1,6 @@ package dev.openfeature.javasdk; -import java.time.ZonedDateTime; +import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -73,7 +73,7 @@ public Structure add(String key, Double value) { * @param value date-time value * @return Structure */ - public Structure add(String key, ZonedDateTime value) { + public Structure add(String key, Instant value) { attributes.put(key, new Value(value)); return this; } diff --git a/src/main/java/dev/openfeature/javasdk/Value.java b/src/main/java/dev/openfeature/javasdk/Value.java index a01ee10ab..88ada5e29 100644 --- a/src/main/java/dev/openfeature/javasdk/Value.java +++ b/src/main/java/dev/openfeature/javasdk/Value.java @@ -1,6 +1,6 @@ package dev.openfeature.javasdk; -import java.time.ZonedDateTime; +import java.time.Instant; import java.util.List; import lombok.EqualsAndHashCode; @@ -54,7 +54,7 @@ public Value(List value) { this.innerObject = value; } - public Value(ZonedDateTime value) { + public Value(Instant value) { this.innerObject = value; } @@ -113,12 +113,12 @@ public boolean isList() { } /** - * Check if this Value represents a ZonedDateTime. + * Check if this Value represents an Instant. * * @return boolean */ - public boolean isZonedDateTime() { - return this.innerObject instanceof ZonedDateTime; + public boolean isInstant() { + return this.innerObject instanceof Instant; } /** @@ -207,13 +207,13 @@ public List asList() { } /** - * Retrieve the underlying ZonedDateTime value, or null. + * Retrieve the underlying Instant value, or null. * - * @return ZonedDateTime + * @return Instant */ - public ZonedDateTime asZonedDateTime() { - if (this.isZonedDateTime()) { - return (ZonedDateTime)this.innerObject; + public Instant asInstant() { + if (this.isInstant()) { + return (Instant)this.innerObject; } return null; } diff --git a/src/test/java/dev/openfeature/javasdk/EvalContextTest.java b/src/test/java/dev/openfeature/javasdk/EvalContextTest.java index 681a7e09c..29506919e 100644 --- a/src/test/java/dev/openfeature/javasdk/EvalContextTest.java +++ b/src/test/java/dev/openfeature/javasdk/EvalContextTest.java @@ -2,7 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import java.time.ZonedDateTime; +import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -34,9 +34,9 @@ public class EvalContextTest { ec.add("int", 4); assertEquals(4, ec.getValue("int").asInteger()); - ZonedDateTime dt = ZonedDateTime.now(); + Instant dt = Instant.now(); ec.add("dt", dt); - assertEquals(dt, ec.getValue("dt").asZonedDateTime()); + assertEquals(dt, ec.getValue("dt").asInstant()); } @Specification(number="3.1.2", text="The evaluation context MUST support the inclusion of " + @@ -72,7 +72,7 @@ public class EvalContextTest { ec.add("int", 4); ec.add("int2", 2); - ZonedDateTime dt = ZonedDateTime.now(); + Instant dt = Instant.now(); ec.add("dt", dt); ec.add("obj", new Structure().add("val1", 1).add("val2", "2")); @@ -121,14 +121,14 @@ public class EvalContextTest { .add("Double", (Double)null) .add("Structure", (Structure)null) .add("List", (List)null) - .add("ZonedDateTime", (ZonedDateTime)null); + .add("Instant", (Instant)null); assertEquals(6, ec.asMap().size()); assertEquals(null, ec.getValue("Boolean").asBoolean()); assertEquals(null, ec.getValue("String").asString()); assertEquals(null, ec.getValue("Double").asDouble()); assertEquals(null, ec.getValue("Structure").asStructure()); assertEquals(null, ec.getValue("List").asList()); - assertEquals(null, ec.getValue("ZonedDateTime").asString()); + assertEquals(null, ec.getValue("Instant").asString()); } @Test void merge_targeting_key() { diff --git a/src/test/java/dev/openfeature/javasdk/StructureTest.java b/src/test/java/dev/openfeature/javasdk/StructureTest.java index 0232bc793..eccb23c30 100644 --- a/src/test/java/dev/openfeature/javasdk/StructureTest.java +++ b/src/test/java/dev/openfeature/javasdk/StructureTest.java @@ -4,7 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.time.ZonedDateTime; +import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -44,7 +44,7 @@ public class StructureTest { String STRING_VAL = "val"; int INT_VAL = 13; double DOUBLE_VAL = .5; - ZonedDateTime DATE_VAL = ZonedDateTime.now(); + Instant DATE_VAL = Instant.now(); Structure STRUCT_VAL = new Structure(); List LIST_VAL = new ArrayList(); Value VALUE_VAL = new Value(); @@ -63,7 +63,7 @@ public class StructureTest { assertEquals(STRING_VAL, structure.getValue(STRING_KEY).asString()); assertEquals(INT_VAL, structure.getValue(INT_KEY).asInteger()); assertEquals(DOUBLE_VAL, structure.getValue(DOUBLE_KEY).asDouble()); - assertEquals(DATE_VAL, structure.getValue(DATE_KEY).asZonedDateTime()); + assertEquals(DATE_VAL, structure.getValue(DATE_KEY).asInstant()); assertEquals(STRUCT_VAL, structure.getValue(STRUCT_KEY).asStructure()); assertEquals(LIST_VAL, structure.getValue(LIST_KEY).asList()); assertTrue(structure.getValue(VALUE_KEY).isNull()); diff --git a/src/test/java/dev/openfeature/javasdk/ValueTest.java b/src/test/java/dev/openfeature/javasdk/ValueTest.java index 401c67695..f53825e75 100644 --- a/src/test/java/dev/openfeature/javasdk/ValueTest.java +++ b/src/test/java/dev/openfeature/javasdk/ValueTest.java @@ -3,7 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.time.ZonedDateTime; +import java.time.Instant; import java.util.ArrayList; import java.util.List; @@ -50,10 +50,10 @@ public class ValueTest { } @Test public void dateShouldContainDate() { - ZonedDateTime innerValue = ZonedDateTime.now(); + Instant innerValue = Instant.now(); Value value = new Value(innerValue); - assertTrue(value.isZonedDateTime()); - assertEquals(innerValue, value.asZonedDateTime()); + assertTrue(value.isInstant()); + assertEquals(innerValue, value.asInstant()); } @Test public void structureShouldContainStructure() {