001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.core.time;
018
019import org.apache.logging.log4j.core.util.Clock;
020import org.apache.logging.log4j.util.StringBuilderFormattable;
021
022/**
023 * Models a point in time, suitable for event timestamps.
024 * <p>
025 * Provides methods for obtaining high precision time information similar to the
026 * <a href="https://docs.oracle.com/javase/9/docs/api/java/time/Instant.html">Instant</a> class introduced in Java 8,
027 * while also supporting the legacy millisecond precision API.
028 * </p><p>
029 * Depending on the platform, time sources ({@link Clock} implementations) may produce high precision or millisecond
030 * precision time values. At the same time, some time value consumers (for example timestamp formatters) may only be
031 * able to consume time values of millisecond precision, while some others may require a high precision time value.
032 * </p><p>
033 * This class bridges these two time APIs.
034 * </p>
035 * @since 2.11
036 */
037public interface Instant extends StringBuilderFormattable {
038    /**
039     * Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z.
040     * <p>
041     * The epoch second count is a simple incrementing count of seconds where second 0 is 1970-01-01T00:00:00Z.
042     * The nanosecond part of the day is returned by {@link #getNanoOfSecond()}.
043     * </p>
044     * @return the seconds from the epoch of 1970-01-01T00:00:00Z
045     */
046    long getEpochSecond();
047
048    /**
049     * Gets the number of nanoseconds, later along the time-line, from the start of the second.
050     * <p>
051     * The nanosecond-of-second value measures the total number of nanoseconds from the second returned by {@link #getEpochSecond()}.
052     * </p>
053     * @return the nanoseconds within the second, always positive, never exceeds {@code 999,999,999}
054     */
055    int getNanoOfSecond();
056
057    /**
058     * Gets the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z.
059     * <p>
060     * The epoch millisecond count is a simple incrementing count of milliseconds where millisecond 0 is 1970-01-01T00:00:00Z.
061     * The nanosecond part of the day is returned by {@link #getNanoOfMillisecond()}.
062     * </p>
063     * @return the milliseconds from the epoch of 1970-01-01T00:00:00Z
064     */
065    long getEpochMillisecond();
066
067    /**
068     * Gets the number of nanoseconds, later along the time-line, from the start of the millisecond.
069     * <p>
070     * The nanosecond-of-millisecond value measures the total number of nanoseconds from the millisecond returned by {@link #getEpochMillisecond()}.
071     * </p>
072     * @return the nanoseconds within the millisecond, always positive, never exceeds {@code 999,999}
073     */
074    int getNanoOfMillisecond();
075}