Skip to content

Commit 00b74c5

Browse files
jkebingerclaude
andauthored
Add support for 'reforge.current-time' property key (#153)
This change adds compatibility for the 'reforge.current-time' property key alongside the existing 'prefab.current-time' key. Both keys now provide the same current timestamp functionality for SDK compatibility. Changes: - Added REFORGE_CURRENT_TIME_KEY constant in ConfigRuleEvaluator - Updated prop() method to handle both time property keys - Added comprehensive test cases for both time key variants 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent a40390c commit 00b74c5

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

client/src/main/java/cloud/prefab/client/internal/ConfigRuleEvaluator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
public class ConfigRuleEvaluator {
3333

3434
public static final String CURRENT_TIME_KEY = "prefab.current-time";
35+
public static final String REFORGE_CURRENT_TIME_KEY = "reforge.current-time";
3536
private static final Logger LOG = LoggerFactory.getLogger(ConfigRuleEvaluator.class);
3637

3738
private final ConfigStore configStore;
@@ -242,7 +243,7 @@ private Optional<Prefab.ConfigValue> prop(
242243
}
243244
}
244245
//TODO: move this current time injection into a ContextResolver class?
245-
if (CURRENT_TIME_KEY.equals(key)) {
246+
if (CURRENT_TIME_KEY.equals(key) || REFORGE_CURRENT_TIME_KEY.equals(key)) {
246247
return Optional.of(
247248
Prefab.ConfigValue.newBuilder().setInt(System.currentTimeMillis()).build()
248249
);

client/src/test/java/cloud/prefab/client/internal/ConfigRuleEvaluatorTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,57 @@ public void testTimeAfterRange() {
583583
assertThat(eval.isMatch()).isFalse();
584584
}
585585

586+
@Test
587+
public void testReforgeTimeInRange() {
588+
// note this relies on ConfigRuleEvaluator on-demand adding the current time for reforge.current-time
589+
final Prefab.Criterion intRangeCriterion = Prefab.Criterion
590+
.newBuilder()
591+
.setPropertyName(ConfigRuleEvaluator.REFORGE_CURRENT_TIME_KEY)
592+
.setValueToMatch(
593+
Prefab.ConfigValue.newBuilder().setIntRange(Prefab.IntRange.newBuilder().build())
594+
)
595+
.setOperator(Prefab.Criterion.CriterionOperator.IN_INT_RANGE)
596+
.build();
597+
598+
final EvaluatedCriterion positiveEval = evaluator
599+
.evaluateCriterionMatch(intRangeCriterion, LookupContext.EMPTY)
600+
.stream()
601+
.findFirst()
602+
.get();
603+
604+
assertThat(positiveEval.isMatch()).isTrue();
605+
}
606+
607+
@Test
608+
public void testReforgeTimeAfterRange() {
609+
// note this relies on ConfigRuleEvaluator on-demand adding the current time for reforge.current-time
610+
long currentTime = System.currentTimeMillis();
611+
612+
final Prefab.Criterion intRangeCriterion = Prefab.Criterion
613+
.newBuilder()
614+
.setPropertyName(ConfigRuleEvaluator.REFORGE_CURRENT_TIME_KEY)
615+
.setValueToMatch(
616+
Prefab.ConfigValue
617+
.newBuilder()
618+
.setIntRange(
619+
Prefab.IntRange
620+
.newBuilder()
621+
.setEnd(currentTime - TimeUnit.MINUTES.toMillis(2))
622+
.build()
623+
)
624+
)
625+
.setOperator(Prefab.Criterion.CriterionOperator.IN_INT_RANGE)
626+
.build();
627+
628+
final EvaluatedCriterion eval = evaluator
629+
.evaluateCriterionMatch(intRangeCriterion, LookupContext.EMPTY)
630+
.stream()
631+
.findFirst()
632+
.get();
633+
634+
assertThat(eval.isMatch()).isFalse();
635+
}
636+
586637
public static Stream<Arguments> comparisonArguments() {
587638
return Stream.of(
588639
Arguments.of(

0 commit comments

Comments
 (0)