package j$.time;

import androidx.media3.common.C;
import j$.time.chrono.ChronoLocalDate;
import j$.time.chrono.InterfaceC2285d;
import j$.time.format.DateTimeFormatter;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Objects;

/* JADX INFO: loaded from: classes2.dex */
public final class LocalDate implements j$.time.temporal.m, j$.time.temporal.o, ChronoLocalDate, Serializable {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final LocalDate f19105d = h0(-999999999, 1, 1);

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final LocalDate f19106e = h0(999999999, 12, 31);
    private static final long serialVersionUID = 2942565459149668126L;

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final short f19109c;

    static {
        h0(1970, 1, 1);
    }

    public static LocalDate now() {
        return g0(b.c());
    }

    public static LocalDate now(ZoneId zoneId) {
        a aVar;
        Objects.requireNonNull(zoneId, "zone");
        if (zoneId == ZoneOffset.UTC) {
            aVar = a.f19126b;
        } else {
            aVar = new a(zoneId);
        }
        return g0(aVar);
    }

    public static LocalDate g0(b bVar) {
        Objects.requireNonNull(bVar, "clock");
        return ofInstant(Instant.J(System.currentTimeMillis()), bVar.a());
    }

    public static LocalDate i0(int i6, n nVar, int i7) {
        j$.time.temporal.a.YEAR.c0(i6);
        j$.time.temporal.a.DAY_OF_MONTH.c0(i7);
        return B(i6, nVar.p(), i7);
    }

    public static LocalDate h0(int i6, int i7, int i8) {
        j$.time.temporal.a.YEAR.c0(i6);
        j$.time.temporal.a.MONTH_OF_YEAR.c0(i7);
        j$.time.temporal.a.DAY_OF_MONTH.c0(i8);
        return B(i6, i7, i8);
    }

    public static LocalDate k0(int i6, int i7) {
        long j4 = i6;
        j$.time.temporal.a.YEAR.c0(j4);
        j$.time.temporal.a.DAY_OF_YEAR.c0(i7);
        boolean zD = j$.time.chrono.r.f19171d.D(j4);
        if (i7 == 366 && !zD) {
            throw new c("Invalid date 'DayOfYear 366' as '" + i6 + "' is not a leap year");
        }
        n nVarU = n.U(((i7 - 1) / 31) + 1);
        if (i7 > (nVarU.B(zD) + nVarU.r(zD)) - 1) {
            nVarU = nVarU.V();
        }
        return new LocalDate(i6, nVarU.p(), (i7 - nVarU.r(zD)) + 1);
    }

    public static LocalDate ofInstant(Instant instant, ZoneId zoneId) {
        Objects.requireNonNull(instant, "instant");
        Objects.requireNonNull(zoneId, "zone");
        return j0(Math.floorDiv(instant.getEpochSecond() + ((long) zoneId.r().d(instant).c0()), 86400));
    }

    public static LocalDate j0(long j4) {
        long j6;
        j$.time.temporal.a.EPOCH_DAY.c0(j4);
        long j7 = 719468 + j4;
        if (j7 < 0) {
            long j8 = ((j4 + 719469) / 146097) - 1;
            j6 = j8 * 400;
            j7 += (-j8) * 146097;
        } else {
            j6 = 0;
        }
        long j9 = ((j7 * 400) + 591) / 146097;
        long j10 = j7 - ((j9 / 400) + (((j9 / 4) + (j9 * 365)) - (j9 / 100)));
        if (j10 < 0) {
            j9--;
            j10 = j7 - ((j9 / 400) + (((j9 / 4) + (365 * j9)) - (j9 / 100)));
        }
        int i6 = (int) j10;
        int i7 = ((i6 * 5) + 2) / 153;
        return new LocalDate(j$.time.temporal.a.YEAR.b0(j9 + j6 + ((long) (i7 / 10))), ((i7 + 2) % 12) + 1, (i6 - (((i7 * 306) + 5) / 10)) + 1);
    }

    public static LocalDate J(j$.time.temporal.n nVar) {
        Objects.requireNonNull(nVar, "temporal");
        LocalDate localDate = (LocalDate) nVar.d(j$.time.temporal.t.b());
        if (localDate != null) {
            return localDate;
        }
        throw new c("Unable to obtain LocalDate from TemporalAccessor: " + nVar + " of type " + nVar.getClass().getName());
    }

    public static LocalDate parse(CharSequence charSequence) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE;
        Objects.requireNonNull(dateTimeFormatter, "formatter");
        return (LocalDate) dateTimeFormatter.e(charSequence, new g(1));
    }

    private static LocalDate B(int i6, int i7, int i8) {
        int i9 = 28;
        if (i8 > 28) {
            if (i7 != 2) {
                i9 = (i7 == 4 || i7 == 6 || i7 == 9 || i7 == 11) ? 30 : 31;
            } else if (j$.time.chrono.r.f19171d.D(i6)) {
                i9 = 29;
            }
            if (i8 > i9) {
                if (i8 == 29) {
                    throw new c("Invalid date 'February 29' as '" + i6 + "' is not a leap year");
                }
                throw new c("Invalid date '" + n.U(i7).name() + " " + i8 + "'");
            }
        }
        return new LocalDate(i6, i7, i8);
    }

    private static LocalDate q0(int i6, int i7, int i8) {
        if (i7 == 2) {
            i8 = Math.min(i8, j$.time.chrono.r.f19171d.D((long) i6) ? 29 : 28);
        } else if (i7 == 4 || i7 == 6 || i7 == 9 || i7 == 11) {
            i8 = Math.min(i8, 30);
        }
        return new LocalDate(i6, i7, i8);
    }

    private LocalDate(int i6, int i7, int i8) {
        this.f19107a = i6;
        this.f19108b = (short) i7;
        this.f19109c = (short) i8;
    }

    @Override // j$.time.temporal.n
    public final j$.time.temporal.x l(j$.time.temporal.s sVar) {
        if (!(sVar instanceof j$.time.temporal.a)) {
            return sVar.J(this);
        }
        j$.time.temporal.a aVar = (j$.time.temporal.a) sVar;
        if (!aVar.V()) {
            throw new j$.time.temporal.w(d.a("Unsupported field: ", sVar));
        }
        int i6 = i.f19299a[aVar.ordinal()];
        if (i6 == 1) {
            return j$.time.temporal.x.j(1L, e0());
        }
        if (i6 == 2) {
            return j$.time.temporal.x.j(1L, K());
        }
        if (i6 != 3) {
            return i6 != 4 ? ((j$.time.temporal.a) sVar).B() : this.f19107a <= 0 ? j$.time.temporal.x.j(1L, C.NANOS_PER_SECOND) : j$.time.temporal.x.j(1L, 999999999L);
        }
        return j$.time.temporal.x.j(1L, (n.U(this.f19108b) != n.FEBRUARY || O()) ? 5L : 4L);
    }

    @Override // j$.time.temporal.n
    public final int j(j$.time.temporal.s sVar) {
        if (sVar instanceof j$.time.temporal.a) {
            return U(sVar);
        }
        return super.j(sVar);
    }

    @Override // j$.time.temporal.n
    public final long g(j$.time.temporal.s sVar) {
        if (sVar instanceof j$.time.temporal.a) {
            if (sVar == j$.time.temporal.a.EPOCH_DAY) {
                return toEpochDay();
            }
            if (sVar != j$.time.temporal.a.PROLEPTIC_MONTH) {
                return U(sVar);
            }
            return ((((long) this.f19107a) * 12) + ((long) this.f19108b)) - 1;
        }
        return sVar.r(this);
    }

    private int U(j$.time.temporal.s sVar) {
        int i6;
        int i7 = i.f19299a[((j$.time.temporal.a) sVar).ordinal()];
        short s6 = this.f19109c;
        int i8 = this.f19107a;
        switch (i7) {
            case 1:
                return s6;
            case 2:
                return Y();
            case 3:
                i6 = (s6 - 1) / 7;
                break;
            case 4:
                return i8 >= 1 ? i8 : 1 - i8;
            case 5:
                return V().p();
            case 6:
                i6 = (s6 - 1) % 7;
                break;
            case 7:
                return ((Y() - 1) % 7) + 1;
            case 8:
                throw new j$.time.temporal.w("Invalid field 'EpochDay' for get() method, use getLong() instead");
            case 9:
                return ((Y() - 1) / 7) + 1;
            case 10:
                return this.f19108b;
            case 11:
                throw new j$.time.temporal.w("Invalid field 'ProlepticMonth' for get() method, use getLong() instead");
            case 12:
                return i8;
            case 13:
                return i8 >= 1 ? 1 : 0;
            default:
                throw new j$.time.temporal.w(d.a("Unsupported field: ", sVar));
        }
        return i6 + 1;
    }

    @Override // j$.time.chrono.ChronoLocalDate
    public final j$.time.chrono.k i() {
        return j$.time.chrono.r.f19171d;
    }

    @Override // j$.time.chrono.ChronoLocalDate
    public final j$.time.chrono.l u() {
        return this.f19107a >= 1 ? j$.time.chrono.s.CE : j$.time.chrono.s.BCE;
    }

    public final int c0() {
        return this.f19107a;
    }

    public final int b0() {
        return this.f19108b;
    }

    public final int Y() {
        return (n.U(this.f19108b).r(O()) + this.f19109c) - 1;
    }

    public final e V() {
        return e.r(((int) Math.floorMod(toEpochDay() + 3, 7)) + 1);
    }

    @Override // j$.time.chrono.ChronoLocalDate
    public final boolean O() {
        return j$.time.chrono.r.f19171d.D(this.f19107a);
    }

    public final int e0() {
        short s6 = this.f19108b;
        return s6 != 2 ? (s6 == 4 || s6 == 6 || s6 == 9 || s6 == 11) ? 30 : 31 : O() ? 29 : 28;
    }

    @Override // j$.time.chrono.ChronoLocalDate
    public final int K() {
        return O() ? 366 : 365;
    }

    @Override // j$.time.chrono.ChronoLocalDate
    /* JADX INFO: renamed from: s0, reason: merged with bridge method [inline-methods] and merged with bridge method [inline-methods] */
    public final LocalDate m(j$.time.temporal.o oVar) {
        if (oVar instanceof LocalDate) {
            return (LocalDate) oVar;
        }
        return (LocalDate) oVar.e(this);
    }

    @Override // j$.time.temporal.m
    /* JADX INFO: renamed from: r0, reason: merged with bridge method [inline-methods] */
    public final LocalDate a(long j4, j$.time.temporal.s sVar) {
        if (!(sVar instanceof j$.time.temporal.a)) {
            return (LocalDate) sVar.p(this, j4);
        }
        j$.time.temporal.a aVar = (j$.time.temporal.a) sVar;
        aVar.c0(j4);
        int i6 = i.f19299a[aVar.ordinal()];
        short s6 = this.f19109c;
        short s7 = this.f19108b;
        int i7 = this.f19107a;
        switch (i6) {
            case 1:
                int i8 = (int) j4;
                if (s6 != i8) {
                    return h0(i7, s7, i8);
                }
                return this;
            case 2:
                return t0((int) j4);
            case 3:
                return o0(j4 - g(j$.time.temporal.a.ALIGNED_WEEK_OF_MONTH));
            case 4:
                if (i7 < 1) {
                    j4 = 1 - j4;
                }
                return u0((int) j4);
            case 5:
                return m0(j4 - ((long) V().p()));
            case 6:
                return m0(j4 - g(j$.time.temporal.a.ALIGNED_DAY_OF_WEEK_IN_MONTH));
            case 7:
                return m0(j4 - g(j$.time.temporal.a.ALIGNED_DAY_OF_WEEK_IN_YEAR));
            case 8:
                return j0(j4);
            case 9:
                return o0(j4 - g(j$.time.temporal.a.ALIGNED_WEEK_OF_YEAR));
            case 10:
                int i9 = (int) j4;
                if (s7 != i9) {
                    j$.time.temporal.a.MONTH_OF_YEAR.c0(i9);
                    return q0(i7, i9, s6);
                }
                return this;
            case 11:
                return n0(j4 - (((((long) i7) * 12) + ((long) s7)) - 1));
            case 12:
                return u0((int) j4);
            case 13:
                if (g(j$.time.temporal.a.ERA) != j4) {
                    return u0(1 - i7);
                }
                return this;
            default:
                throw new j$.time.temporal.w(d.a("Unsupported field: ", sVar));
        }
    }

    public final LocalDate u0(int i6) {
        if (this.f19107a == i6) {
            return this;
        }
        j$.time.temporal.a.YEAR.c0(i6);
        return q0(i6, this.f19108b, this.f19109c);
    }

    public final LocalDate t0(int i6) {
        return Y() == i6 ? this : k0(this.f19107a, i6);
    }

    @Override // j$.time.chrono.ChronoLocalDate
    public final ChronoLocalDate N(j$.time.temporal.r rVar) {
        if (rVar instanceof s) {
            return n0(((s) rVar).d()).m0(r4.a());
        }
        Objects.requireNonNull(rVar, "amountToAdd");
        return (LocalDate) rVar.p(this);
    }

    @Override // j$.time.temporal.m
    /* JADX INFO: renamed from: l0, reason: merged with bridge method [inline-methods] */
    public final LocalDate b(long j4, j$.time.temporal.v vVar) {
        if (!(vVar instanceof j$.time.temporal.b)) {
            return (LocalDate) vVar.p(this, j4);
        }
        switch (i.f19300b[((j$.time.temporal.b) vVar).ordinal()]) {
            case 1:
                return m0(j4);
            case 2:
                return o0(j4);
            case 3:
                return n0(j4);
            case 4:
                return p0(j4);
            case 5:
                return p0(Math.multiplyExact(j4, 10));
            case 6:
                return p0(Math.multiplyExact(j4, 100));
            case 7:
                return p0(Math.multiplyExact(j4, 1000));
            case 8:
                j$.time.temporal.a aVar = j$.time.temporal.a.ERA;
                return a(Math.addExact(g(aVar), j4), aVar);
            default:
                throw new j$.time.temporal.w("Unsupported unit: " + vVar);
        }
    }

    public final LocalDate p0(long j4) {
        return j4 == 0 ? this : q0(j$.time.temporal.a.YEAR.b0(((long) this.f19107a) + j4), this.f19108b, this.f19109c);
    }

    public final LocalDate n0(long j4) {
        if (j4 == 0) {
            return this;
        }
        long j6 = (((long) this.f19107a) * 12) + ((long) (this.f19108b - 1)) + j4;
        long j7 = 12;
        return q0(j$.time.temporal.a.YEAR.b0(Math.floorDiv(j6, j7)), ((int) Math.floorMod(j6, j7)) + 1, this.f19109c);
    }

    public final LocalDate o0(long j4) {
        return m0(Math.multiplyExact(j4, 7));
    }

    public final LocalDate m0(long j4) {
        if (j4 == 0) {
            return this;
        }
        long j6 = ((long) this.f19109c) + j4;
        if (j6 > 0) {
            short s6 = this.f19108b;
            int i6 = this.f19107a;
            if (j6 <= 28) {
                return new LocalDate(i6, s6, (int) j6);
            }
            if (j6 <= 59) {
                long jE0 = e0();
                if (j6 <= jE0) {
                    return new LocalDate(i6, s6, (int) j6);
                }
                if (s6 < 12) {
                    return new LocalDate(i6, s6 + 1, (int) (j6 - jE0));
                }
                int i7 = i6 + 1;
                j$.time.temporal.a.YEAR.c0(i7);
                return new LocalDate(i7, 1, (int) (j6 - jE0));
            }
        }
        return j0(Math.addExact(toEpochDay(), j4));
    }

    @Override // j$.time.temporal.m
    /* JADX INFO: renamed from: f0, reason: merged with bridge method [inline-methods] */
    public final LocalDate c(long j4, j$.time.temporal.b bVar) {
        return j4 == Long.MIN_VALUE ? b(Long.MAX_VALUE, bVar).b(1L, bVar) : b(-j4, bVar);
    }

    public LocalDate minusDays(long j4) {
        return j4 == Long.MIN_VALUE ? m0(Long.MAX_VALUE).m0(1L) : m0(-j4);
    }

    @Override // j$.time.temporal.n
    public final Object d(j$.time.temporal.u uVar) {
        return uVar == j$.time.temporal.t.b() ? this : super.d(uVar);
    }

    public String format(DateTimeFormatter dateTimeFormatter) {
        Objects.requireNonNull(dateTimeFormatter, "formatter");
        return dateTimeFormatter.a(this);
    }

    @Override // j$.time.chrono.ChronoLocalDate
    public final InterfaceC2285d L(l lVar) {
        return LocalDateTime.c0(this, lVar);
    }

    public ZonedDateTime atStartOfDay(ZoneId zoneId) {
        j$.time.zone.b bVarF;
        Objects.requireNonNull(zoneId, "zone");
        LocalDateTime localDateTimeC0 = LocalDateTime.c0(this, l.f19306g);
        if (!(zoneId instanceof ZoneOffset) && (bVarF = zoneId.r().f(localDateTimeC0)) != null && bVarF.Y()) {
            localDateTimeC0 = bVarF.p();
        }
        return ZonedDateTime.J(localDateTimeC0, zoneId, null);
    }

    @Override // j$.time.chrono.ChronoLocalDate
    public long toEpochDay() {
        long j4 = this.f19107a;
        long j6 = this.f19108b;
        long j7 = 365 * j4;
        long j8 = (((367 * j6) - 362) / 12) + (j4 >= 0 ? ((j4 + 399) / 400) + (((3 + j4) / 4) - ((99 + j4) / 100)) + j7 : j7 - ((j4 / (-400)) + ((j4 / (-4)) - (j4 / (-100))))) + ((long) (this.f19109c - 1));
        if (j6 > 2) {
            j8 = !O() ? j8 - 2 : j8 - 1;
        }
        return j8 - 719528;
    }

    @Override // j$.time.chrono.ChronoLocalDate, java.lang.Comparable
    /* JADX INFO: renamed from: X, reason: merged with bridge method [inline-methods] */
    public final int compareTo(ChronoLocalDate chronoLocalDate) {
        if (chronoLocalDate instanceof LocalDate) {
            return r((LocalDate) chronoLocalDate);
        }
        return super.compareTo(chronoLocalDate);
    }

    final int r(LocalDate localDate) {
        int i6 = this.f19107a - localDate.f19107a;
        if (i6 != 0) {
            return i6;
        }
        int i7 = this.f19108b - localDate.f19108b;
        return i7 == 0 ? this.f19109c - localDate.f19109c : i7;
    }

    public boolean isAfter(ChronoLocalDate chronoLocalDate) {
        return chronoLocalDate instanceof LocalDate ? r((LocalDate) chronoLocalDate) > 0 : toEpochDay() > chronoLocalDate.toEpochDay();
    }

    public final boolean d0(LocalDate localDate) {
        return localDate != null ? r(localDate) < 0 : toEpochDay() < localDate.toEpochDay();
    }

    @Override // j$.time.chrono.ChronoLocalDate
    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        return (obj instanceof LocalDate) && r((LocalDate) obj) == 0;
    }

    @Override // j$.time.chrono.ChronoLocalDate
    public final int hashCode() {
        int i6 = this.f19107a;
        return (((i6 << 11) + (this.f19108b << 6)) + this.f19109c) ^ (i6 & (-2048));
    }

    @Override // j$.time.chrono.ChronoLocalDate
    public String toString() {
        int i6 = this.f19107a;
        int iAbs = Math.abs(i6);
        StringBuilder sb = new StringBuilder(10);
        if (iAbs >= 1000) {
            if (i6 > 9999) {
                sb.append('+');
            }
            sb.append(i6);
        } else if (i6 < 0) {
            sb.append(i6 - 10000);
            sb.deleteCharAt(1);
        } else {
            sb.append(i6 + 10000);
            sb.deleteCharAt(0);
        }
        short s6 = this.f19108b;
        sb.append(s6 < 10 ? "-0" : "-");
        sb.append((int) s6);
        short s7 = this.f19109c;
        sb.append(s7 < 10 ? "-0" : "-");
        sb.append((int) s7);
        return sb.toString();
    }

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

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

    final void v0(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(this.f19107a);
        dataOutput.writeByte(this.f19108b);
        dataOutput.writeByte(this.f19109c);
    }
}
