Skip to content

Commit

Permalink
feat!: use instant not zoneddatetime
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <toddbaert@gmail.com>
  • Loading branch information
toddbaert committed Sep 9, 2022
1 parent 0152a1e commit 3e62414
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/main/java/dev/openfeature/javasdk/EvaluationContext.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.openfeature.javasdk;

import java.time.ZonedDateTime;
import java.time.Instant;
import java.util.List;

import lombok.Getter;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/openfeature/javasdk/Structure.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/dev/openfeature/javasdk/Value.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.openfeature.javasdk;

import java.time.ZonedDateTime;
import java.time.Instant;
import java.util.List;

import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -54,7 +54,7 @@ public Value(List<Value> value) {
this.innerObject = value;
}

public Value(ZonedDateTime value) {
public Value(Instant value) {
this.innerObject = value;
}

Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -207,13 +207,13 @@ public List<Value> 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;
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/dev/openfeature/javasdk/EvalContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 " +
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -121,14 +121,14 @@ public class EvalContextTest {
.add("Double", (Double)null)
.add("Structure", (Structure)null)
.add("List", (List<Value>)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() {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/dev/openfeature/javasdk/StructureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Value> LIST_VAL = new ArrayList<Value>();
Value VALUE_VAL = new Value();
Expand All @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/dev/openfeature/javasdk/ValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 3e62414

Please sign in to comment.