Skip to content

Commit

Permalink
Store an Instant in FakeFileTimeSource instead of a FileTime.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 575869851
  • Loading branch information
kluever authored and Jimfs Team committed Oct 23, 2023
1 parent fcec619 commit 62e0c6a
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,32 @@
final class FakeFileTimeSource implements FileTimeSource {

private final Random random = new Random(System.currentTimeMillis());
private FileTime now;
private Instant now;

FakeFileTimeSource() {
randomize();
}

@CanIgnoreReturnValue
FakeFileTimeSource randomize() {
Instant randomNow =
now =
Instant.ofEpochSecond(
random
.longs(Instant.MIN.getEpochSecond(), Instant.MAX.getEpochSecond())
.findAny()
.getAsLong(),
random.nextInt(1_000_000_000));
this.now = FileTime.from(randomNow);
return this;
}

@CanIgnoreReturnValue
FakeFileTimeSource advance(Duration duration) {
this.now = FileTime.from(now.toInstant().plus(duration));
this.now = now.plus(duration);
return this;
}

@Override
public FileTime now() {
return now;
return FileTime.from(now);
}
}

0 comments on commit 62e0c6a

Please sign in to comment.