// 
// Decompiled by Procyon v0.6.0
// 

package io.sentry;

import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import java.util.Date;

public final class SentryNanotimeDate extends SentryDate
{
    @NotNull
    private final Date date;
    private final long nanos;
    
    public SentryNanotimeDate() {
        this(DateUtils.getCurrentDateTime(), System.nanoTime());
    }
    
    public SentryNanotimeDate(@NotNull final Date date, final long nanos) {
        this.date = date;
        this.nanos = nanos;
    }
    
    @Override
    public long diff(@NotNull final SentryDate otherDate) {
        if (otherDate instanceof SentryNanotimeDate) {
            final SentryNanotimeDate otherNanoDate = (SentryNanotimeDate)otherDate;
            return this.nanos - otherNanoDate.nanos;
        }
        return super.diff(otherDate);
    }
    
    @Override
    public long nanoTimestamp() {
        return DateUtils.dateToNanos(this.date);
    }
    
    @Override
    public long laterDateNanosTimestampByDiff(@Nullable final SentryDate otherDate) {
        if (otherDate == null || !(otherDate instanceof SentryNanotimeDate)) {
            return super.laterDateNanosTimestampByDiff(otherDate);
        }
        final SentryNanotimeDate otherNanoDate = (SentryNanotimeDate)otherDate;
        if (this.compareTo(otherDate) < 0) {
            return this.nanotimeDiff(this, otherNanoDate);
        }
        return this.nanotimeDiff(otherNanoDate, this);
    }
    
    @Override
    public int compareTo(@NotNull final SentryDate otherDate) {
        if (!(otherDate instanceof SentryNanotimeDate)) {
            return super.compareTo(otherDate);
        }
        final SentryNanotimeDate otherNanoDate = (SentryNanotimeDate)otherDate;
        final long thisDateMillis = this.date.getTime();
        final long otherDateMillis = otherNanoDate.date.getTime();
        if (thisDateMillis == otherDateMillis) {
            return Long.valueOf(this.nanos).compareTo(otherNanoDate.nanos);
        }
        return Long.valueOf(thisDateMillis).compareTo(otherDateMillis);
    }
    
    private long nanotimeDiff(@NotNull final SentryNanotimeDate earlierDate, @NotNull final SentryNanotimeDate laterDate) {
        final long nanoDiff = laterDate.nanos - earlierDate.nanos;
        return earlierDate.nanoTimestamp() + nanoDiff;
    }
}
