Skip to content

Commit

Permalink
fix Timestamp instant lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
DivineThreepwood committed Apr 1, 2024
1 parent 2ae4157 commit 2c6954c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import java.util.concurrent.TimeUnit
object TimestampProcessor {
const val SET: String = "set"
const val TIMESTAMP_NAME: String = "Timestamp"
const val TIME_NAME: String = "Time"

@JvmField
val TIMESTAMP_FIELD_NAME: String = TIMESTAMP_NAME.lowercase()
val TIME_FIELD_NAME: String = TIME_NAME.lowercase()

@JvmStatic
val currentTimestamp: TimestampType.Timestamp
Expand Down Expand Up @@ -303,5 +301,5 @@ object TimestampProcessor {

val <M : TimestampOrBuilder> M.instant: Instant?
get() = tryOrNull {
Instant.ofEpochMilli(TimestampProcessor.getTimestamp(this, TimeUnit.MILLISECONDS))
Instant.ofEpochMilli(time.div(1000))
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
Expand All @@ -31,6 +31,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
Expand All @@ -44,7 +45,7 @@ public abstract class Timeout {
/**
* Using Long.MAX_VALUE as infinity timeout is not practical because in any calculations using this timeout like adding +1 causes a value overrun.
* Therefore, this constant is introduced to use a infinity timeout which represents in fact 3170 years which should covers at least some human generations ;)
*
* <p>
* The unit of the {@code INFINITY_TIMEOUT} is in milliseconds.
*/
public static final long INFINITY_TIMEOUT = TimedProcessable.INFINITY_TIMEOUT;
Expand Down Expand Up @@ -81,6 +82,15 @@ public Timeout(final long defaultWaitTime) {
this.defaultWaitTime = defaultWaitTime;
}

/**
* Constructor creates a new Timeout instance. The default timeout can be configured via the given {@code defaultWaitTime} argument.
*
* @param defaultWaitTime the default timeout.
*/
public Timeout(final Duration defaultWaitTime) {
this.defaultWaitTime = defaultWaitTime.toMillis();
}

/**
* Returns the currently configured time to wait until the timeout is reached after start.
*
Expand Down Expand Up @@ -244,7 +254,7 @@ private void internal_start(final long waitTime, final TimeUnit timeUnit) throws
} catch (InterruptedException ex) {
// just finish task on interruption
} catch (Exception ex) {
if(!ExceptionProcessor.isCausedBySystemShutdown(ex)) {
if (!ExceptionProcessor.isCausedBySystemShutdown(ex)) {
ExceptionPrinter.printHistory(new CouldNotPerformException("Error during timeout handling!", ex), logger, LogLevel.WARN);
}
}
Expand Down

0 comments on commit 2c6954c

Please sign in to comment.