package j$.time;

import androidx.media3.common.C;
import androidx.media3.common.PlaybackException;
import j$.time.format.DateTimeFormatter;
import java.io.DataOutput;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serializable;

/* JADX INFO: loaded from: classes2.dex */
public final class Instant implements j$.time.temporal.m, j$.time.temporal.o, Comparable<Instant>, Serializable {
    public static final Instant EPOCH = new Instant(0, 0);
    private static final long serialVersionUID = -665713676816604388L;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final long f19103a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final int f19104b;

    public static Instant now() {
        a.f19126b.getClass();
        return J(System.currentTimeMillis());
    }

    static {
        ofEpochSecond(-31557014167219200L, 0L);
        ofEpochSecond(31556889864403199L, 999999999L);
    }

    public static Instant ofEpochSecond(long j4) {
        return r(j4, 0);
    }

    public static Instant ofEpochSecond(long j4, long j6) {
        return r(Math.addExact(j4, Math.floorDiv(j6, C.NANOS_PER_SECOND)), (int) Math.floorMod(j6, C.NANOS_PER_SECOND));
    }

    public static Instant J(long j4) {
        long j6 = 1000;
        return r(Math.floorDiv(j4, j6), ((int) Math.floorMod(j4, j6)) * PlaybackException.CUSTOM_ERROR_CODE_BASE);
    }

    public static Instant B(j$.time.temporal.n nVar) {
        if (nVar instanceof Instant) {
            return (Instant) nVar;
        }
        try {
            return ofEpochSecond(nVar.g(j$.time.temporal.a.INSTANT_SECONDS), nVar.j(j$.time.temporal.a.NANO_OF_SECOND));
        } catch (c e6) {
            throw new c("Unable to obtain Instant from TemporalAccessor: " + nVar + " of type " + nVar.getClass().getName(), e6);
        }
    }

    public static Instant parse(CharSequence charSequence) {
        return (Instant) DateTimeFormatter.f19199f.e(charSequence, new g(0));
    }

    private static Instant r(long j4, int i6) {
        if ((((long) i6) | j4) == 0) {
            return EPOCH;
        }
        if (j4 < -31557014167219200L || j4 > 31556889864403199L) {
            throw new c("Instant exceeds minimum or maximum instant");
        }
        return new Instant(j4, i6);
    }

    private Instant(long j4, int i6) {
        this.f19103a = j4;
        this.f19104b = i6;
    }

    @Override // j$.time.temporal.n
    public final boolean f(j$.time.temporal.s sVar) {
        return sVar instanceof j$.time.temporal.a ? sVar == j$.time.temporal.a.INSTANT_SECONDS || sVar == j$.time.temporal.a.NANO_OF_SECOND || sVar == j$.time.temporal.a.MICRO_OF_SECOND || sVar == j$.time.temporal.a.MILLI_OF_SECOND : sVar != null && sVar.Y(this);
    }

    @Override // j$.time.temporal.n
    public final int j(j$.time.temporal.s sVar) {
        if (!(sVar instanceof j$.time.temporal.a)) {
            return super.l(sVar).a(sVar.r(this), sVar);
        }
        int i6 = h.f19297a[((j$.time.temporal.a) sVar).ordinal()];
        int i7 = this.f19104b;
        if (i6 == 1) {
            return i7;
        }
        if (i6 == 2) {
            return i7 / 1000;
        }
        if (i6 == 3) {
            return i7 / PlaybackException.CUSTOM_ERROR_CODE_BASE;
        }
        if (i6 == 4) {
            j$.time.temporal.a.INSTANT_SECONDS.b0(this.f19103a);
        }
        throw new j$.time.temporal.w(d.a("Unsupported field: ", sVar));
    }

    @Override // j$.time.temporal.n
    public final long g(j$.time.temporal.s sVar) {
        int i6;
        if (!(sVar instanceof j$.time.temporal.a)) {
            return sVar.r(this);
        }
        int i7 = h.f19297a[((j$.time.temporal.a) sVar).ordinal()];
        int i8 = this.f19104b;
        if (i7 == 1) {
            return i8;
        }
        if (i7 == 2) {
            i6 = i8 / 1000;
        } else {
            if (i7 != 3) {
                if (i7 == 4) {
                    return this.f19103a;
                }
                throw new j$.time.temporal.w(d.a("Unsupported field: ", sVar));
            }
            i6 = i8 / PlaybackException.CUSTOM_ERROR_CODE_BASE;
        }
        return i6;
    }

    public long getEpochSecond() {
        return this.f19103a;
    }

    public int getNano() {
        return this.f19104b;
    }

    @Override // j$.time.temporal.m
    /* JADX INFO: renamed from: h */
    public final j$.time.temporal.m m(LocalDate localDate) {
        return (Instant) localDate.e(this);
    }

    @Override // j$.time.temporal.m
    public final j$.time.temporal.m a(long j4, j$.time.temporal.s sVar) {
        if (!(sVar instanceof j$.time.temporal.a)) {
            return (Instant) sVar.p(this, j4);
        }
        j$.time.temporal.a aVar = (j$.time.temporal.a) sVar;
        aVar.c0(j4);
        int i6 = h.f19297a[aVar.ordinal()];
        int i7 = this.f19104b;
        long j6 = this.f19103a;
        if (i6 != 1) {
            if (i6 == 2) {
                int i8 = ((int) j4) * 1000;
                if (i8 != i7) {
                    return r(j6, i8);
                }
            } else if (i6 == 3) {
                int i9 = ((int) j4) * PlaybackException.CUSTOM_ERROR_CODE_BASE;
                if (i9 != i7) {
                    return r(j6, i9);
                }
            } else {
                if (i6 != 4) {
                    throw new j$.time.temporal.w(d.a("Unsupported field: ", sVar));
                }
                if (j4 != j6) {
                    return r(j4, i7);
                }
            }
        } else if (j4 != i7) {
            return r(j6, (int) j4);
        }
        return this;
    }

    @Override // j$.time.temporal.m
    /* JADX INFO: renamed from: V, reason: merged with bridge method [inline-methods] */
    public final Instant b(long j4, j$.time.temporal.v vVar) {
        if (!(vVar instanceof j$.time.temporal.b)) {
            return (Instant) vVar.p(this, j4);
        }
        switch (h.f19298b[((j$.time.temporal.b) vVar).ordinal()]) {
            case 1:
                return U(0L, j4);
            case 2:
                return U(j4 / 1000000, (j4 % 1000000) * 1000);
            case 3:
                return U(j4 / 1000, (j4 % 1000) * 1000000);
            case 4:
                return U(j4, 0L);
            case 5:
                return U(Math.multiplyExact(j4, 60), 0L);
            case 6:
                return U(Math.multiplyExact(j4, 3600), 0L);
            case 7:
                return U(Math.multiplyExact(j4, 43200), 0L);
            case 8:
                return U(Math.multiplyExact(j4, 86400), 0L);
            default:
                throw new j$.time.temporal.w("Unsupported unit: " + vVar);
        }
    }

    private Instant U(long j4, long j6) {
        if ((j4 | j6) == 0) {
            return this;
        }
        return ofEpochSecond(Math.addExact(Math.addExact(this.f19103a, j4), j6 / C.NANOS_PER_SECOND), ((long) this.f19104b) + (j6 % C.NANOS_PER_SECOND));
    }

    @Override // j$.time.temporal.m
    public final j$.time.temporal.m c(long j4, j$.time.temporal.v vVar) {
        return j4 == Long.MIN_VALUE ? b(Long.MAX_VALUE, vVar).b(1L, vVar) : b(-j4, vVar);
    }

    @Override // j$.time.temporal.n
    public final Object d(j$.time.temporal.u uVar) {
        if (uVar == j$.time.temporal.t.e()) {
            return j$.time.temporal.b.NANOS;
        }
        if (uVar == j$.time.temporal.t.a() || uVar == j$.time.temporal.t.g() || uVar == j$.time.temporal.t.f() || uVar == j$.time.temporal.t.d() || uVar == j$.time.temporal.t.b() || uVar == j$.time.temporal.t.c()) {
            return null;
        }
        return uVar.l(this);
    }

    @Override // j$.time.temporal.o
    public final j$.time.temporal.m e(j$.time.temporal.m mVar) {
        return mVar.a(this.f19103a, j$.time.temporal.a.INSTANT_SECONDS).a(this.f19104b, j$.time.temporal.a.NANO_OF_SECOND);
    }

    public OffsetDateTime atOffset(ZoneOffset zoneOffset) {
        return OffsetDateTime.B(this, zoneOffset);
    }

    public ZonedDateTime atZone(ZoneId zoneId) {
        return ZonedDateTime.B(this, zoneId);
    }

    public final long Y() {
        long j4 = this.f19103a;
        return (j4 >= 0 || this.f19104b <= 0) ? Math.addExact(Math.multiplyExact(j4, 1000), r5 / PlaybackException.CUSTOM_ERROR_CODE_BASE) : Math.addExact(Math.multiplyExact(j4 + 1, 1000), (r5 / PlaybackException.CUSTOM_ERROR_CODE_BASE) - 1000);
    }

    @Override // java.lang.Comparable
    public int compareTo(Instant instant) {
        int iCompare = Long.compare(this.f19103a, instant.f19103a);
        return iCompare != 0 ? iCompare : this.f19104b - instant.f19104b;
    }

    public boolean isAfter(Instant instant) {
        return compareTo(instant) > 0;
    }

    public boolean isBefore(Instant instant) {
        return compareTo(instant) < 0;
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof Instant) {
            Instant instant = (Instant) obj;
            if (this.f19103a == instant.f19103a && this.f19104b == instant.f19104b) {
                return true;
            }
        }
        return false;
    }

    public final int hashCode() {
        long j4 = this.f19103a;
        return (this.f19104b * 51) + ((int) (j4 ^ (j4 >>> 32)));
    }

    public String toString() {
        return DateTimeFormatter.f19199f.a(this);
    }

    private Object writeReplace() {
        return new t((byte) 2, this);
    }

    private void readObject(ObjectInputStream objectInputStream) throws InvalidObjectException {
        throw new InvalidObjectException("Deserialization via serialization delegate");
    }

    final void b0(DataOutput dataOutput) {
        dataOutput.writeLong(this.f19103a);
        dataOutput.writeInt(this.f19104b);
    }
}
