Skip to content

Commit

Permalink
Feat(SystemClock): Added PreciseClock implementation to the system cl…
Browse files Browse the repository at this point in the history
…ock class, for the benefit of Java 8 users.
  • Loading branch information
Jay Katariya authored and jaykataria1111 committed Nov 29, 2024
1 parent be2d145 commit cf1ddbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
*/
package org.apache.logging.log4j.core.util;

import java.time.Instant;
import org.apache.logging.log4j.core.time.MutableInstant;
import org.apache.logging.log4j.core.time.PreciseClock;

/**
* Implementation of the {@code Clock} interface that returns the system time.
* @since 2.25
*/
public final class SystemClock implements Clock {
public final class SystemClock implements Clock, PreciseClock {

/**
* Returns the system time.
Expand All @@ -29,4 +34,13 @@ public final class SystemClock implements Clock {
public long currentTimeMillis() {
return System.currentTimeMillis();
}

/**
* {@inheritDoc}
*/
@Override
public void init(final MutableInstant mutableInstant) {
final Instant instant = java.time.Clock.systemUTC().instant();
mutableInstant.initFromEpochSecond(instant.getEpochSecond(), instant.getNano());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Log4j 2 helper classes.
*/
@Export
@Version("2.24.2")
@Version("2.25.0")
package org.apache.logging.log4j.core.util;

import org.osgi.annotation.bundle.Export;
Expand Down

0 comments on commit cf1ddbf

Please sign in to comment.