File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed
main/java/dev/sigstore/trustroot
test/java/dev/sigstore/trustroot Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -27,14 +27,15 @@ public abstract class ValidFor {
27
27
28
28
public abstract Optional <Instant > getEnd ();
29
29
30
+ /** Check if an instant of time is contained within the validity range including the endpoints. */
30
31
public boolean contains (Instant instant ) {
31
- if (! getStart () .isBefore (instant )) {
32
+ if (instant .isBefore (getStart () )) {
32
33
return false ;
33
34
}
34
- if (getEnd ().isEmpty () || getEnd (). get (). isAfter ( instant ) ) {
35
+ if (getEnd ().isEmpty ()) {
35
36
return true ;
36
37
}
37
- return false ;
38
+ return ! instant . isAfter ( getEnd (). get ()) ;
38
39
}
39
40
40
41
public static ValidFor from (TimeRange proto ) {
Original file line number Diff line number Diff line change @@ -31,11 +31,11 @@ public void contains_withStartAndEnd() {
31
31
Assertions .assertTrue (range .contains (Instant .now ()));
32
32
33
33
Assertions .assertTrue (range .contains (start .plus (10 , ChronoUnit .SECONDS )));
34
- Assertions .assertFalse (range .contains (start ));
34
+ Assertions .assertTrue (range .contains (start ));
35
35
Assertions .assertFalse (range .contains (start .minus (10 , ChronoUnit .SECONDS )));
36
36
37
37
Assertions .assertTrue (range .contains (end .minus (10 , ChronoUnit .SECONDS )));
38
- Assertions .assertFalse (range .contains (end ));
38
+ Assertions .assertTrue (range .contains (end ));
39
39
Assertions .assertFalse (range .contains (end .plus (10 , ChronoUnit .SECONDS )));
40
40
}
41
41
@@ -47,7 +47,7 @@ public void contains_withNoEnd() {
47
47
Assertions .assertTrue (range .contains (Instant .now ().plus (10 , ChronoUnit .SECONDS )));
48
48
49
49
Assertions .assertTrue (range .contains (start .plus (10 , ChronoUnit .SECONDS )));
50
- Assertions .assertFalse (range .contains (start ));
50
+ Assertions .assertTrue (range .contains (start ));
51
51
Assertions .assertFalse (range .contains (start .minus (10 , ChronoUnit .SECONDS )));
52
52
}
53
53
}
You can’t perform that action at this time.
0 commit comments