package org.joda.time;

import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicReference;
import org.joda.time.chrono.BaseChronology;
import org.joda.time.format.DateTimeFormatterBuilder;
import org.joda.time.tz.FixedDateTimeZone;
import y.x0;

/* loaded from: classes.dex */
public abstract class DateTimeZone implements Serializable {

    /* renamed from: p, reason: collision with root package name */
    public static final DateTimeZone f31852p = UTCDateTimeZone.f31902t;

    /* renamed from: q, reason: collision with root package name */
    private static final AtomicReference f31853q = new AtomicReference();

    /* renamed from: r, reason: collision with root package name */
    private static final AtomicReference f31854r = new AtomicReference();

    /* renamed from: s, reason: collision with root package name */
    private static final AtomicReference f31855s = new AtomicReference();
    private static final long serialVersionUID = 5546345482340108586L;
    private final String iID;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class LazyInit {

        /* renamed from: a, reason: collision with root package name */
        static final Map f31856a = b();

        /* renamed from: b, reason: collision with root package name */
        static final org.joda.time.format.b f31857b = a();

        private static org.joda.time.format.b a() {
            return new DateTimeFormatterBuilder().L(null, true, 2, 4).b0().s(new BaseChronology() { // from class: org.joda.time.DateTimeZone.LazyInit.1
                private static final long serialVersionUID = -3128740902654445468L;

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

                @Override // org.joda.time.a
                public a K(DateTimeZone dateTimeZone) {
                    return this;
                }

                @Override // org.joda.time.a
                public DateTimeZone m() {
                    return null;
                }

                @Override // org.joda.time.a
                public String toString() {
                    return AnonymousClass1.class.getName();
                }
            });
        }

        private static Map b() {
            HashMap hashMap = new HashMap();
            hashMap.put("GMT", "UTC");
            hashMap.put("WET", "WET");
            hashMap.put("CET", "CET");
            hashMap.put("MET", "CET");
            hashMap.put("ECT", "CET");
            hashMap.put("EET", "EET");
            hashMap.put("MIT", "Pacific/Apia");
            hashMap.put("HST", "Pacific/Honolulu");
            hashMap.put("AST", "America/Anchorage");
            hashMap.put("PST", "America/Los_Angeles");
            hashMap.put("MST", "America/Denver");
            hashMap.put("PNT", "America/Phoenix");
            hashMap.put("CST", "America/Chicago");
            hashMap.put("EST", "America/New_York");
            hashMap.put("IET", "America/Indiana/Indianapolis");
            hashMap.put("PRT", "America/Puerto_Rico");
            hashMap.put("CNT", "America/St_Johns");
            hashMap.put("AGT", "America/Argentina/Buenos_Aires");
            hashMap.put("BET", "America/Sao_Paulo");
            hashMap.put("ART", "Africa/Cairo");
            hashMap.put("CAT", "Africa/Harare");
            hashMap.put("EAT", "Africa/Addis_Ababa");
            hashMap.put("NET", "Asia/Yerevan");
            hashMap.put("PLT", "Asia/Karachi");
            hashMap.put("IST", "Asia/Kolkata");
            hashMap.put("BST", "Asia/Dhaka");
            hashMap.put("VST", "Asia/Ho_Chi_Minh");
            hashMap.put("CTT", "Asia/Shanghai");
            hashMap.put("JST", "Asia/Tokyo");
            hashMap.put("ACT", "Australia/Darwin");
            hashMap.put("AET", "Australia/Sydney");
            hashMap.put("SST", "Pacific/Guadalcanal");
            hashMap.put("NST", "Pacific/Auckland");
            return Collections.unmodifiableMap(hashMap);
        }
    }

    /* loaded from: classes.dex */
    private static final class Stub implements Serializable {
        private static final long serialVersionUID = -6471952376487863581L;

        /* renamed from: p, reason: collision with root package name */
        private transient String f31858p;

        Stub(String str) {
            this.f31858p = str;
        }

        private void readObject(ObjectInputStream objectInputStream) throws IOException {
            this.f31858p = objectInputStream.readUTF();
        }

        private Object readResolve() throws ObjectStreamException {
            return DateTimeZone.f(this.f31858p);
        }

        private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
            objectOutputStream.writeUTF(this.f31858p);
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public DateTimeZone(String str) {
        if (str == null) {
            throw new IllegalArgumentException("Id must not be null");
        }
        this.iID = str;
    }

    private static int A(String str) {
        return -((int) LazyInit.f31857b.h(str));
    }

    private static String C(int i10) {
        StringBuffer stringBuffer = new StringBuffer();
        if (i10 >= 0) {
            stringBuffer.append('+');
        } else {
            stringBuffer.append('-');
            i10 = -i10;
        }
        int i11 = i10 / 3600000;
        org.joda.time.format.h.b(stringBuffer, i11, 2);
        int i12 = i10 - (i11 * 3600000);
        int i13 = i12 / 60000;
        stringBuffer.append(':');
        org.joda.time.format.h.b(stringBuffer, i13, 2);
        int i14 = i12 - (i13 * 60000);
        if (i14 == 0) {
            return stringBuffer.toString();
        }
        int i15 = i14 / 1000;
        stringBuffer.append(':');
        org.joda.time.format.h.b(stringBuffer, i15, 2);
        int i16 = i14 - (i15 * 1000);
        if (i16 == 0) {
            return stringBuffer.toString();
        }
        stringBuffer.append('.');
        org.joda.time.format.h.b(stringBuffer, i16, 3);
        return stringBuffer.toString();
    }

    public static void D(DateTimeZone dateTimeZone) {
        SecurityManager securityManager = System.getSecurityManager();
        if (securityManager != null) {
            securityManager.checkPermission(new JodaTimePermission("DateTimeZone.setDefault"));
        }
        if (dateTimeZone == null) {
            throw new IllegalArgumentException("The datetime zone must not be null");
        }
        f31855s.set(dateTimeZone);
    }

    public static void E(org.joda.time.tz.c cVar) {
        SecurityManager securityManager = System.getSecurityManager();
        if (securityManager != null) {
            securityManager.checkPermission(new JodaTimePermission("DateTimeZone.setProvider"));
        }
        if (cVar == null) {
            cVar = m();
        } else {
            F(cVar);
        }
        f31853q.set(cVar);
    }

    private static org.joda.time.tz.c F(org.joda.time.tz.c cVar) {
        Set b10 = cVar.b();
        if (b10 == null || b10.size() == 0) {
            throw new IllegalArgumentException("The provider doesn't have any available ids");
        }
        if (!b10.contains("UTC")) {
            throw new IllegalArgumentException("The provider doesn't support UTC");
        }
        if (f31852p.equals(cVar.a("UTC"))) {
            return cVar;
        }
        throw new IllegalArgumentException("Invalid UTC zone provided");
    }

    private static String c(String str) {
        StringBuilder sb2 = new StringBuilder(str);
        for (int i10 = 0; i10 < sb2.length(); i10++) {
            int digit = Character.digit(sb2.charAt(i10), 10);
            if (digit >= 0) {
                sb2.setCharAt(i10, (char) (digit + 48));
            }
        }
        return sb2.toString();
    }

    private static DateTimeZone e(String str, int i10) {
        return i10 == 0 ? f31852p : new FixedDateTimeZone(str, null, i10, i10);
    }

    public static DateTimeZone f(String str) {
        if (str == null) {
            return k();
        }
        if (str.equals("UTC")) {
            return f31852p;
        }
        DateTimeZone a10 = u().a(str);
        if (a10 != null) {
            return a10;
        }
        if (str.startsWith("+") || str.startsWith("-")) {
            int A = A(str);
            return ((long) A) == 0 ? f31852p : e(C(A), A);
        }
        throw new IllegalArgumentException("The datetime zone id '" + str + "' is not recognised");
    }

    public static DateTimeZone g(int i10) {
        if (i10 >= -86399999 && i10 <= 86399999) {
            return e(C(i10), i10);
        }
        throw new IllegalArgumentException("Millis out of range: " + i10);
    }

    public static DateTimeZone h(TimeZone timeZone) {
        char charAt;
        if (timeZone == null) {
            return k();
        }
        String id2 = timeZone.getID();
        if (id2 == null) {
            throw new IllegalArgumentException("The TimeZone id must not be null");
        }
        if (id2.equals("UTC")) {
            return f31852p;
        }
        String j10 = j(id2);
        org.joda.time.tz.c u10 = u();
        DateTimeZone a10 = j10 != null ? u10.a(j10) : null;
        if (a10 == null) {
            a10 = u10.a(id2);
        }
        if (a10 != null) {
            return a10;
        }
        if (j10 != null || (!id2.startsWith("GMT+") && !id2.startsWith("GMT-"))) {
            throw new IllegalArgumentException("The datetime zone id '" + id2 + "' is not recognised");
        }
        String substring = id2.substring(3);
        if (substring.length() > 2 && (charAt = substring.charAt(1)) > '9' && Character.isDigit(charAt)) {
            substring = c(substring);
        }
        int A = A(substring);
        return ((long) A) == 0 ? f31852p : e(C(A), A);
    }

    public static Set i() {
        return u().b();
    }

    private static String j(String str) {
        return (String) LazyInit.f31856a.get(str);
    }

    public static DateTimeZone k() {
        DateTimeZone dateTimeZone = (DateTimeZone) f31855s.get();
        if (dateTimeZone != null) {
            return dateTimeZone;
        }
        try {
            String property = System.getProperty("org.joda.time.DateTimeZone.Timezone");
            if (property != null) {
                dateTimeZone = f(property);
            }
        } catch (RuntimeException unused) {
        }
        if (dateTimeZone == null) {
            try {
                dateTimeZone = h(TimeZone.getDefault());
            } catch (IllegalArgumentException unused2) {
            }
        }
        if (dateTimeZone == null) {
            dateTimeZone = f31852p;
        }
        AtomicReference atomicReference = f31855s;
        return !x0.a(atomicReference, null, dateTimeZone) ? (DateTimeZone) atomicReference.get() : dateTimeZone;
    }

    private static org.joda.time.tz.b l() {
        org.joda.time.tz.b bVar = null;
        try {
            String property = System.getProperty("org.joda.time.DateTimeZone.NameProvider");
            if (property != null) {
                try {
                    Class<?> cls = Class.forName(property, false, DateTimeZone.class.getClassLoader());
                    if (!org.joda.time.tz.b.class.isAssignableFrom(cls)) {
                        throw new IllegalArgumentException("System property referred to class that does not implement " + org.joda.time.tz.b.class);
                    }
                    bVar = (org.joda.time.tz.b) cls.asSubclass(org.joda.time.tz.b.class).getConstructor(new Class[0]).newInstance(new Object[0]);
                } catch (Exception e10) {
                    throw new RuntimeException(e10);
                }
            }
        } catch (SecurityException unused) {
        }
        return bVar == null ? new org.joda.time.tz.a() : bVar;
    }

    private static org.joda.time.tz.c m() {
        try {
            String property = System.getProperty("org.joda.time.DateTimeZone.Provider");
            if (property != null) {
                try {
                    Class<?> cls = Class.forName(property, false, DateTimeZone.class.getClassLoader());
                    if (org.joda.time.tz.c.class.isAssignableFrom(cls)) {
                        return F((org.joda.time.tz.c) cls.asSubclass(org.joda.time.tz.c.class).getConstructor(new Class[0]).newInstance(new Object[0]));
                    }
                    throw new IllegalArgumentException("System property referred to class that does not implement " + org.joda.time.tz.c.class);
                } catch (Exception e10) {
                    throw new RuntimeException(e10);
                }
            }
        } catch (SecurityException unused) {
        }
        try {
            String property2 = System.getProperty("org.joda.time.DateTimeZone.Folder");
            if (property2 != null) {
                try {
                    return F(new org.joda.time.tz.e(new File(property2)));
                } catch (Exception e11) {
                    throw new RuntimeException(e11);
                }
            }
        } catch (SecurityException unused2) {
        }
        try {
            return F(new org.joda.time.tz.e("org/joda/time/tz/data"));
        } catch (Exception e12) {
            e12.printStackTrace();
            return new org.joda.time.tz.d();
        }
    }

    public static org.joda.time.tz.b r() {
        AtomicReference atomicReference = f31854r;
        org.joda.time.tz.b bVar = (org.joda.time.tz.b) atomicReference.get();
        if (bVar != null) {
            return bVar;
        }
        org.joda.time.tz.b l10 = l();
        return !x0.a(atomicReference, null, l10) ? (org.joda.time.tz.b) atomicReference.get() : l10;
    }

    public static org.joda.time.tz.c u() {
        AtomicReference atomicReference = f31853q;
        org.joda.time.tz.c cVar = (org.joda.time.tz.c) atomicReference.get();
        if (cVar != null) {
            return cVar;
        }
        org.joda.time.tz.c m10 = m();
        return !x0.a(atomicReference, null, m10) ? (org.joda.time.tz.c) atomicReference.get() : m10;
    }

    public abstract long B(long j10);

    public long a(long j10, boolean z10) {
        long j11;
        int s10 = s(j10);
        long j12 = j10 - s10;
        int s11 = s(j12);
        if (s10 != s11 && (z10 || s10 < 0)) {
            long z11 = z(j12);
            if (z11 == j12) {
                z11 = Long.MAX_VALUE;
            }
            long j13 = j10 - s11;
            long z12 = z(j13);
            if (z11 != (z12 != j13 ? z12 : Long.MAX_VALUE)) {
                if (z10) {
                    throw new IllegalInstantException(j10, n());
                }
                long j14 = s10;
                j11 = j10 - j14;
                if ((j10 ^ j11) < 0 || (j10 ^ j14) >= 0) {
                    return j11;
                }
                throw new ArithmeticException("Subtracting time zone offset caused overflow");
            }
        }
        s10 = s11;
        long j142 = s10;
        j11 = j10 - j142;
        if ((j10 ^ j11) < 0) {
        }
        return j11;
    }

    public long b(long j10, boolean z10, long j11) {
        int s10 = s(j11);
        long j12 = j10 - s10;
        return s(j12) == s10 ? j12 : a(j10, z10);
    }

    public long d(long j10) {
        long s10 = s(j10);
        long j11 = j10 + s10;
        if ((j10 ^ j11) >= 0 || (j10 ^ s10) < 0) {
            return j11;
        }
        throw new ArithmeticException("Adding time zone offset caused overflow");
    }

    public abstract boolean equals(Object obj);

    public abstract int hashCode();

    public final String n() {
        return this.iID;
    }

    public long o(DateTimeZone dateTimeZone, long j10) {
        if (dateTimeZone == null) {
            dateTimeZone = k();
        }
        DateTimeZone dateTimeZone2 = dateTimeZone;
        return dateTimeZone2 == this ? j10 : dateTimeZone2.b(d(j10), false, j10);
    }

    public String p(long j10, Locale locale) {
        if (locale == null) {
            locale = Locale.getDefault();
        }
        String q10 = q(j10);
        if (q10 == null) {
            return this.iID;
        }
        org.joda.time.tz.b r10 = r();
        String d10 = r10 instanceof org.joda.time.tz.a ? ((org.joda.time.tz.a) r10).d(locale, this.iID, q10, y(j10)) : r10.a(locale, this.iID, q10);
        return d10 != null ? d10 : C(s(j10));
    }

    public abstract String q(long j10);

    public abstract int s(long j10);

    public int t(long j10) {
        int s10 = s(j10);
        long j11 = j10 - s10;
        int s11 = s(j11);
        if (s10 != s11) {
            if (s10 - s11 < 0) {
                long z10 = z(j11);
                if (z10 == j11) {
                    z10 = Long.MAX_VALUE;
                }
                long j12 = j10 - s11;
                long z11 = z(j12);
                if (z10 != (z11 != j12 ? z11 : Long.MAX_VALUE)) {
                    return s10;
                }
            }
        } else if (s10 >= 0) {
            long B = B(j11);
            if (B < j11) {
                int s12 = s(B);
                if (j11 - B <= s12 - s10) {
                    return s12;
                }
            }
        }
        return s11;
    }

    public String toString() {
        return n();
    }

    public String v(long j10, Locale locale) {
        if (locale == null) {
            locale = Locale.getDefault();
        }
        String q10 = q(j10);
        if (q10 == null) {
            return this.iID;
        }
        org.joda.time.tz.b r10 = r();
        String g10 = r10 instanceof org.joda.time.tz.a ? ((org.joda.time.tz.a) r10).g(locale, this.iID, q10, y(j10)) : r10.b(locale, this.iID, q10);
        return g10 != null ? g10 : C(s(j10));
    }

    public abstract int w(long j10);

    protected Object writeReplace() throws ObjectStreamException {
        return new Stub(this.iID);
    }

    public abstract boolean x();

    public boolean y(long j10) {
        return s(j10) == w(j10);
    }

    public abstract long z(long j10);
}
