package sp;

import jn.l;
import jn.o;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import kotlin.text.z;

/* loaded from: classes3.dex */
public final class a implements Comparable {

    /* renamed from: q, reason: collision with root package name */
    public static final C0845a f35959q = new C0845a(null);

    /* renamed from: r, reason: collision with root package name */
    private static final long f35960r = u(0);

    /* renamed from: s, reason: collision with root package name */
    private static final long f35961s;

    /* renamed from: t, reason: collision with root package name */
    private static final long f35962t;

    /* renamed from: p, reason: collision with root package name */
    private final long f35963p;

    /* renamed from: sp.a$a, reason: collision with other inner class name */
    /* loaded from: classes3.dex */
    public static final class C0845a {
        private C0845a() {
        }

        public /* synthetic */ C0845a(k kVar) {
            this();
        }

        public final long a() {
            return a.f35961s;
        }

        public final long b() {
            return a.f35960r;
        }

        public final long c(String value) {
            long p10;
            t.g(value, "value");
            try {
                p10 = c.p(value, true);
                return p10;
            } catch (IllegalArgumentException e10) {
                throw new IllegalArgumentException("Invalid ISO duration string format: '" + value + "'.", e10);
            }
        }
    }

    static {
        long j10;
        long j11;
        j10 = c.j(4611686018427387903L);
        f35961s = j10;
        j11 = c.j(-4611686018427387903L);
        f35962t = j11;
    }

    private /* synthetic */ a(long j10) {
        this.f35963p = j10;
    }

    public static final long A(long j10) {
        return (K(j10) && J(j10)) ? H(j10) : Q(j10, d.MILLISECONDS);
    }

    public static final long B(long j10) {
        return Q(j10, d.MINUTES);
    }

    public static final long C(long j10) {
        return Q(j10, d.SECONDS);
    }

    public static final int D(long j10) {
        if (M(j10)) {
            return 0;
        }
        return (int) (B(j10) % 60);
    }

    public static final int E(long j10) {
        if (M(j10)) {
            return 0;
        }
        return (int) (K(j10) ? c.n(H(j10) % 1000) : H(j10) % 1000000000);
    }

    public static final int F(long j10) {
        if (M(j10)) {
            return 0;
        }
        return (int) (C(j10) % 60);
    }

    private static final d G(long j10) {
        return L(j10) ? d.NANOSECONDS : d.MILLISECONDS;
    }

    private static final long H(long j10) {
        return j10 >> 1;
    }

    public static int I(long j10) {
        return Long.hashCode(j10);
    }

    public static final boolean J(long j10) {
        return !M(j10);
    }

    private static final boolean K(long j10) {
        return (((int) j10) & 1) == 1;
    }

    private static final boolean L(long j10) {
        return (((int) j10) & 1) == 0;
    }

    public static final boolean M(long j10) {
        return j10 == f35961s || j10 == f35962t;
    }

    public static final boolean N(long j10) {
        return j10 < 0;
    }

    public static final boolean O(long j10) {
        return j10 > 0;
    }

    public static final long P(long j10, long j11) {
        long k10;
        long m10;
        if (M(j10)) {
            if (J(j11) || (j11 ^ j10) >= 0) {
                return j10;
            }
            throw new IllegalArgumentException("Summing infinite durations of different signs yields an undefined result.");
        }
        if (M(j11)) {
            return j11;
        }
        if ((((int) j10) & 1) != (((int) j11) & 1)) {
            return K(j10) ? g(j10, H(j10), H(j11)) : g(j10, H(j11), H(j10));
        }
        long H = H(j10) + H(j11);
        if (L(j10)) {
            m10 = c.m(H);
            return m10;
        }
        k10 = c.k(H);
        return k10;
    }

    public static final long Q(long j10, d unit) {
        t.g(unit, "unit");
        if (j10 == f35961s) {
            return Long.MAX_VALUE;
        }
        if (j10 == f35962t) {
            return Long.MIN_VALUE;
        }
        return e.b(H(j10), G(j10), unit);
    }

    public static String R(long j10) {
        if (j10 == 0) {
            return "0s";
        }
        if (j10 == f35961s) {
            return "Infinity";
        }
        if (j10 == f35962t) {
            return "-Infinity";
        }
        boolean N = N(j10);
        StringBuilder sb2 = new StringBuilder();
        if (N) {
            sb2.append('-');
        }
        long w10 = w(j10);
        long y10 = y(w10);
        int x10 = x(w10);
        int D = D(w10);
        int F = F(w10);
        int E = E(w10);
        int i10 = 0;
        boolean z10 = y10 != 0;
        boolean z11 = x10 != 0;
        boolean z12 = D != 0;
        boolean z13 = (F == 0 && E == 0) ? false : true;
        if (z10) {
            sb2.append(y10);
            sb2.append('d');
            i10 = 1;
        }
        if (z11 || (z10 && (z12 || z13))) {
            int i11 = i10 + 1;
            if (i10 > 0) {
                sb2.append(' ');
            }
            sb2.append(x10);
            sb2.append('h');
            i10 = i11;
        }
        if (z12 || (z13 && (z11 || z10))) {
            int i12 = i10 + 1;
            if (i10 > 0) {
                sb2.append(' ');
            }
            sb2.append(D);
            sb2.append('m');
            i10 = i12;
        }
        if (z13) {
            int i13 = i10 + 1;
            if (i10 > 0) {
                sb2.append(' ');
            }
            if (F != 0 || z10 || z11 || z12) {
                m(j10, sb2, F, E, 9, "s", false);
            } else if (E >= 1000000) {
                m(j10, sb2, E / 1000000, E % 1000000, 6, "ms", false);
            } else if (E >= 1000) {
                m(j10, sb2, E / 1000, E % 1000, 3, "us", false);
            } else {
                sb2.append(E);
                sb2.append("ns");
            }
            i10 = i13;
        }
        if (N && i10 > 1) {
            sb2.insert(1, '(').append(')');
        }
        String sb3 = sb2.toString();
        t.f(sb3, "toString(...)");
        return sb3;
    }

    public static final long S(long j10) {
        long i10;
        i10 = c.i(-H(j10), ((int) j10) & 1);
        return i10;
    }

    private static final long g(long j10, long j11, long j12) {
        long o10;
        long l10;
        long j13;
        long n10;
        long n11;
        long l11;
        o10 = c.o(j12);
        long j14 = j11 + o10;
        if (!new l(-4611686018426L, 4611686018426L).x(j14)) {
            l10 = o.l(j14, -4611686018427387903L, 4611686018427387903L);
            j13 = c.j(l10);
            return j13;
        }
        n10 = c.n(o10);
        long j15 = j12 - n10;
        n11 = c.n(j14);
        l11 = c.l(n11 + j15);
        return l11;
    }

    private static final void m(long j10, StringBuilder sb2, int i10, int i11, int i12, String str, boolean z10) {
        String r02;
        sb2.append(i10);
        if (i11 != 0) {
            sb2.append('.');
            r02 = z.r0(String.valueOf(i11), i12, '0');
            int i13 = -1;
            int length = r02.length() - 1;
            if (length >= 0) {
                while (true) {
                    int i14 = length - 1;
                    if (r02.charAt(length) != '0') {
                        i13 = length;
                        break;
                    } else if (i14 < 0) {
                        break;
                    } else {
                        length = i14;
                    }
                }
            }
            int i15 = i13 + 1;
            if (z10 || i15 >= 3) {
                sb2.append((CharSequence) r02, 0, ((i15 + 2) / 3) * 3);
                t.f(sb2, "append(...)");
            } else {
                sb2.append((CharSequence) r02, 0, i15);
                t.f(sb2, "append(...)");
            }
        }
        sb2.append(str);
    }

    public static final /* synthetic */ a r(long j10) {
        return new a(j10);
    }

    public static int t(long j10, long j11) {
        long j12 = j10 ^ j11;
        if (j12 < 0 || (((int) j12) & 1) == 0) {
            return t.j(j10, j11);
        }
        int i10 = (((int) j10) & 1) - (((int) j11) & 1);
        return N(j10) ? -i10 : i10;
    }

    public static long u(long j10) {
        if (b.a()) {
            if (L(j10)) {
                if (!new l(-4611686018426999999L, 4611686018426999999L).x(H(j10))) {
                    throw new AssertionError(H(j10) + " ns is out of nanoseconds range");
                }
            } else {
                if (!new l(-4611686018427387903L, 4611686018427387903L).x(H(j10))) {
                    throw new AssertionError(H(j10) + " ms is out of milliseconds range");
                }
                if (new l(-4611686018426L, 4611686018426L).x(H(j10))) {
                    throw new AssertionError(H(j10) + " ms is denormalized");
                }
            }
        }
        return j10;
    }

    public static boolean v(long j10, Object obj) {
        return (obj instanceof a) && j10 == ((a) obj).T();
    }

    public static final long w(long j10) {
        return N(j10) ? S(j10) : j10;
    }

    public static final int x(long j10) {
        if (M(j10)) {
            return 0;
        }
        return (int) (z(j10) % 24);
    }

    public static final long y(long j10) {
        return Q(j10, d.DAYS);
    }

    public static final long z(long j10) {
        return Q(j10, d.HOURS);
    }

    public final /* synthetic */ long T() {
        return this.f35963p;
    }

    @Override // java.lang.Comparable
    public /* bridge */ /* synthetic */ int compareTo(Object obj) {
        return s(((a) obj).T());
    }

    public boolean equals(Object obj) {
        return v(this.f35963p, obj);
    }

    public int hashCode() {
        return I(this.f35963p);
    }

    public int s(long j10) {
        return t(this.f35963p, j10);
    }

    public String toString() {
        return R(this.f35963p);
    }
}
