package org.joda.time.chrono;

import java.util.HashMap;
import java.util.Locale;
import org.joda.time.DateTimeZone;
import org.joda.time.IllegalFieldValueException;
import org.joda.time.IllegalInstantException;
import org.joda.time.chrono.AssembledChronology;
import org.joda.time.field.BaseDurationField;

/* loaded from: classes5.dex */
public final class ZonedChronology extends AssembledChronology {
    private static final long serialVersionUID = -1079258847191166848L;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes5.dex */
    public static class ZonedDurationField extends BaseDurationField {
        private static final long serialVersionUID = -485345310999208286L;
        final org.joda.time.d iField;
        final boolean iTimeField;
        final DateTimeZone iZone;

        ZonedDurationField(org.joda.time.d dVar, DateTimeZone dateTimeZone) {
            super(dVar.r());
            if (!dVar.u()) {
                throw new IllegalArgumentException();
            }
            this.iField = dVar;
            this.iTimeField = ZonedChronology.X(dVar);
            this.iZone = dateTimeZone;
        }

        private int x(long j10) {
            int t10 = this.iZone.t(j10);
            long j11 = t10;
            if (((j10 - j11) ^ j10) >= 0 || (j10 ^ j11) >= 0) {
                return t10;
            }
            throw new ArithmeticException("Subtracting time zone offset caused overflow");
        }

        private int y(long j10) {
            int s10 = this.iZone.s(j10);
            long j11 = s10;
            if (((j10 + j11) ^ j10) >= 0 || (j10 ^ j11) < 0) {
                return s10;
            }
            throw new ArithmeticException("Adding time zone offset caused overflow");
        }

        @Override // org.joda.time.d
        public long a(long j10, int i10) {
            int y10 = y(j10);
            long a10 = this.iField.a(j10 + y10, i10);
            if (!this.iTimeField) {
                y10 = x(a10);
            }
            return a10 - y10;
        }

        @Override // org.joda.time.d
        public long e(long j10, long j11) {
            int y10 = y(j10);
            long e10 = this.iField.e(j10 + y10, j11);
            if (!this.iTimeField) {
                y10 = x(e10);
            }
            return e10 - y10;
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof ZonedDurationField)) {
                return false;
            }
            ZonedDurationField zonedDurationField = (ZonedDurationField) obj;
            return this.iField.equals(zonedDurationField.iField) && this.iZone.equals(zonedDurationField.iZone);
        }

        @Override // org.joda.time.field.BaseDurationField, org.joda.time.d
        public int g(long j10, long j11) {
            return this.iField.g(j10 + (this.iTimeField ? r0 : y(j10)), j11 + y(j11));
        }

        public int hashCode() {
            return this.iZone.hashCode() ^ this.iField.hashCode();
        }

        @Override // org.joda.time.d
        public long m(long j10, long j11) {
            return this.iField.m(j10 + (this.iTimeField ? r0 : y(j10)), j11 + y(j11));
        }

        @Override // org.joda.time.d
        public long s() {
            return this.iField.s();
        }

        @Override // org.joda.time.d
        public boolean t() {
            return this.iTimeField ? this.iField.t() : this.iField.t() && this.iZone.x();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes5.dex */
    public static final class a extends org.joda.time.field.a {

        /* renamed from: q, reason: collision with root package name */
        final org.joda.time.b f31988q;

        /* renamed from: r, reason: collision with root package name */
        final DateTimeZone f31989r;

        /* renamed from: s, reason: collision with root package name */
        final org.joda.time.d f31990s;

        /* renamed from: t, reason: collision with root package name */
        final boolean f31991t;

        /* renamed from: u, reason: collision with root package name */
        final org.joda.time.d f31992u;

        /* renamed from: v, reason: collision with root package name */
        final org.joda.time.d f31993v;

        a(org.joda.time.b bVar, DateTimeZone dateTimeZone, org.joda.time.d dVar, org.joda.time.d dVar2, org.joda.time.d dVar3) {
            super(bVar.s());
            if (!bVar.v()) {
                throw new IllegalArgumentException();
            }
            this.f31988q = bVar;
            this.f31989r = dateTimeZone;
            this.f31990s = dVar;
            this.f31991t = ZonedChronology.X(dVar);
            this.f31992u = dVar2;
            this.f31993v = dVar3;
        }

        private int J(long j10) {
            int s10 = this.f31989r.s(j10);
            long j11 = s10;
            if (((j10 + j11) ^ j10) >= 0 || (j10 ^ j11) < 0) {
                return s10;
            }
            throw new ArithmeticException("Adding time zone offset caused overflow");
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public long C(long j10, int i10) {
            long C = this.f31988q.C(this.f31989r.d(j10), i10);
            long b10 = this.f31989r.b(C, false, j10);
            if (c(b10) == i10) {
                return b10;
            }
            IllegalInstantException illegalInstantException = new IllegalInstantException(C, this.f31989r.n());
            IllegalFieldValueException illegalFieldValueException = new IllegalFieldValueException(this.f31988q.s(), Integer.valueOf(i10), illegalInstantException.getMessage());
            illegalFieldValueException.initCause(illegalInstantException);
            throw illegalFieldValueException;
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public long D(long j10, String str, Locale locale) {
            return this.f31989r.b(this.f31988q.D(this.f31989r.d(j10), str, locale), false, j10);
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public long a(long j10, int i10) {
            if (this.f31991t) {
                long J = J(j10);
                return this.f31988q.a(j10 + J, i10) - J;
            }
            return this.f31989r.b(this.f31988q.a(this.f31989r.d(j10), i10), false, j10);
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public long b(long j10, long j11) {
            if (this.f31991t) {
                long J = J(j10);
                return this.f31988q.b(j10 + J, j11) - J;
            }
            return this.f31989r.b(this.f31988q.b(this.f31989r.d(j10), j11), false, j10);
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public int c(long j10) {
            return this.f31988q.c(this.f31989r.d(j10));
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public String d(int i10, Locale locale) {
            return this.f31988q.d(i10, locale);
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public String e(long j10, Locale locale) {
            return this.f31988q.e(this.f31989r.d(j10), locale);
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof a)) {
                return false;
            }
            a aVar = (a) obj;
            return this.f31988q.equals(aVar.f31988q) && this.f31989r.equals(aVar.f31989r) && this.f31990s.equals(aVar.f31990s) && this.f31992u.equals(aVar.f31992u);
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public String g(int i10, Locale locale) {
            return this.f31988q.g(i10, locale);
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public String h(long j10, Locale locale) {
            return this.f31988q.h(this.f31989r.d(j10), locale);
        }

        public int hashCode() {
            return this.f31989r.hashCode() ^ this.f31988q.hashCode();
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public int j(long j10, long j11) {
            return this.f31988q.j(j10 + (this.f31991t ? r0 : J(j10)), j11 + J(j11));
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public long k(long j10, long j11) {
            return this.f31988q.k(j10 + (this.f31991t ? r0 : J(j10)), j11 + J(j11));
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public final org.joda.time.d l() {
            return this.f31990s;
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public final org.joda.time.d m() {
            return this.f31993v;
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public int n(Locale locale) {
            return this.f31988q.n(locale);
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public int o() {
            return this.f31988q.o();
        }

        @Override // org.joda.time.b
        public int p() {
            return this.f31988q.p();
        }

        @Override // org.joda.time.b
        public final org.joda.time.d r() {
            return this.f31992u;
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public boolean t(long j10) {
            return this.f31988q.t(this.f31989r.d(j10));
        }

        @Override // org.joda.time.b
        public boolean u() {
            return this.f31988q.u();
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public long w(long j10) {
            return this.f31988q.w(this.f31989r.d(j10));
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public long x(long j10) {
            if (this.f31991t) {
                long J = J(j10);
                return this.f31988q.x(j10 + J) - J;
            }
            return this.f31989r.b(this.f31988q.x(this.f31989r.d(j10)), false, j10);
        }

        @Override // org.joda.time.field.a, org.joda.time.b
        public long y(long j10) {
            if (this.f31991t) {
                long J = J(j10);
                return this.f31988q.y(j10 + J) - J;
            }
            return this.f31989r.b(this.f31988q.y(this.f31989r.d(j10)), false, j10);
        }
    }

    private ZonedChronology(org.joda.time.a aVar, DateTimeZone dateTimeZone) {
        super(aVar, dateTimeZone);
    }

    private org.joda.time.b T(org.joda.time.b bVar, HashMap hashMap) {
        if (bVar == null || !bVar.v()) {
            return bVar;
        }
        if (hashMap.containsKey(bVar)) {
            return (org.joda.time.b) hashMap.get(bVar);
        }
        a aVar = new a(bVar, m(), U(bVar.l(), hashMap), U(bVar.r(), hashMap), U(bVar.m(), hashMap));
        hashMap.put(bVar, aVar);
        return aVar;
    }

    private org.joda.time.d U(org.joda.time.d dVar, HashMap hashMap) {
        if (dVar == null || !dVar.u()) {
            return dVar;
        }
        if (hashMap.containsKey(dVar)) {
            return (org.joda.time.d) hashMap.get(dVar);
        }
        ZonedDurationField zonedDurationField = new ZonedDurationField(dVar, m());
        hashMap.put(dVar, zonedDurationField);
        return zonedDurationField;
    }

    public static ZonedChronology V(org.joda.time.a aVar, DateTimeZone dateTimeZone) {
        if (aVar == null) {
            throw new IllegalArgumentException("Must supply a chronology");
        }
        org.joda.time.a J = aVar.J();
        if (J == null) {
            throw new IllegalArgumentException("UTC chronology must not be null");
        }
        if (dateTimeZone != null) {
            return new ZonedChronology(J, dateTimeZone);
        }
        throw new IllegalArgumentException("DateTimeZone must not be null");
    }

    private long W(long j10) {
        if (j10 == Long.MAX_VALUE) {
            return Long.MAX_VALUE;
        }
        if (j10 == Long.MIN_VALUE) {
            return Long.MIN_VALUE;
        }
        DateTimeZone m10 = m();
        int t10 = m10.t(j10);
        long j11 = j10 - t10;
        if (j10 > 604800000 && j11 < 0) {
            return Long.MAX_VALUE;
        }
        if (j10 < -604800000 && j11 > 0) {
            return Long.MIN_VALUE;
        }
        if (t10 == m10.s(j11)) {
            return j11;
        }
        throw new IllegalInstantException(j10, m10.n());
    }

    static boolean X(org.joda.time.d dVar) {
        return dVar != null && dVar.s() < 43200000;
    }

    @Override // org.joda.time.a
    public org.joda.time.a J() {
        return Q();
    }

    @Override // org.joda.time.a
    public org.joda.time.a K(DateTimeZone dateTimeZone) {
        if (dateTimeZone == null) {
            dateTimeZone = DateTimeZone.k();
        }
        return dateTimeZone == R() ? this : dateTimeZone == DateTimeZone.f31852p ? Q() : new ZonedChronology(Q(), dateTimeZone);
    }

    @Override // org.joda.time.chrono.AssembledChronology
    protected void P(AssembledChronology.a aVar) {
        HashMap hashMap = new HashMap();
        aVar.f31928l = U(aVar.f31928l, hashMap);
        aVar.f31927k = U(aVar.f31927k, hashMap);
        aVar.f31926j = U(aVar.f31926j, hashMap);
        aVar.f31925i = U(aVar.f31925i, hashMap);
        aVar.f31924h = U(aVar.f31924h, hashMap);
        aVar.f31923g = U(aVar.f31923g, hashMap);
        aVar.f31922f = U(aVar.f31922f, hashMap);
        aVar.f31921e = U(aVar.f31921e, hashMap);
        aVar.f31920d = U(aVar.f31920d, hashMap);
        aVar.f31919c = U(aVar.f31919c, hashMap);
        aVar.f31918b = U(aVar.f31918b, hashMap);
        aVar.f31917a = U(aVar.f31917a, hashMap);
        aVar.E = T(aVar.E, hashMap);
        aVar.F = T(aVar.F, hashMap);
        aVar.G = T(aVar.G, hashMap);
        aVar.H = T(aVar.H, hashMap);
        aVar.I = T(aVar.I, hashMap);
        aVar.f31940x = T(aVar.f31940x, hashMap);
        aVar.f31941y = T(aVar.f31941y, hashMap);
        aVar.f31942z = T(aVar.f31942z, hashMap);
        aVar.D = T(aVar.D, hashMap);
        aVar.A = T(aVar.A, hashMap);
        aVar.B = T(aVar.B, hashMap);
        aVar.C = T(aVar.C, hashMap);
        aVar.f31929m = T(aVar.f31929m, hashMap);
        aVar.f31930n = T(aVar.f31930n, hashMap);
        aVar.f31931o = T(aVar.f31931o, hashMap);
        aVar.f31932p = T(aVar.f31932p, hashMap);
        aVar.f31933q = T(aVar.f31933q, hashMap);
        aVar.f31934r = T(aVar.f31934r, hashMap);
        aVar.f31935s = T(aVar.f31935s, hashMap);
        aVar.f31937u = T(aVar.f31937u, hashMap);
        aVar.f31936t = T(aVar.f31936t, hashMap);
        aVar.f31938v = T(aVar.f31938v, hashMap);
        aVar.f31939w = T(aVar.f31939w, hashMap);
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof ZonedChronology)) {
            return false;
        }
        ZonedChronology zonedChronology = (ZonedChronology) obj;
        return Q().equals(zonedChronology.Q()) && m().equals(zonedChronology.m());
    }

    public int hashCode() {
        return (m().hashCode() * 11) + 326565 + (Q().hashCode() * 7);
    }

    @Override // org.joda.time.chrono.AssembledChronology, org.joda.time.chrono.BaseChronology, org.joda.time.a
    public long k(int i10, int i11, int i12, int i13) {
        return W(Q().k(i10, i11, i12, i13));
    }

    @Override // org.joda.time.chrono.AssembledChronology, org.joda.time.chrono.BaseChronology, org.joda.time.a
    public long l(int i10, int i11, int i12, int i13, int i14, int i15, int i16) {
        return W(Q().l(i10, i11, i12, i13, i14, i15, i16));
    }

    @Override // org.joda.time.chrono.AssembledChronology, org.joda.time.a
    public DateTimeZone m() {
        return (DateTimeZone) R();
    }

    @Override // org.joda.time.a
    public String toString() {
        return "ZonedChronology[" + Q() + ", " + m().n() + ']';
    }
}
