package d.t0;

import com.seewo.libmcuservice.constant.ITVStateConstants;
import d.n;
import d.n0.c.l;
import d.n0.c.s;
import d.p0.k;
import d.s0.r;

/* JADX INFO: compiled from: Duration.kt */
/* JADX INFO: loaded from: classes.dex */
@n
public final class a implements Comparable<a> {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final C0088a f2727c = new C0088a(null);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static final long f2728d = h(0);

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static final long f2729e = c.j(4611686018427387903L);

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private static final long f2730f = c.j(-4611686018427387903L);

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

    /* JADX INFO: renamed from: d.t0.a$a, reason: collision with other inner class name */
    /* JADX INFO: compiled from: Duration.kt */
    @n
    public static final class C0088a {
        private C0088a() {
        }

        public /* synthetic */ C0088a(l lVar) {
            this();
        }

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

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

        public final long c(String str) {
            s.e(str, ITVStateConstants.KEY_VOICE_VALUE);
            try {
                return c.p(str, true);
            } catch (IllegalArgumentException e2) {
                throw new IllegalArgumentException("Invalid ISO duration string format: '" + str + "'.", e2);
            }
        }
    }

    private /* synthetic */ a(long j) {
        this.f2731g = j;
    }

    public static final long A(long j, long j2) {
        if (y(j)) {
            if (v(j2) || (j2 ^ j) >= 0) {
                return j;
            }
            throw new IllegalArgumentException("Summing infinite durations of different signs yields an undefined result.");
        }
        if (y(j2)) {
            return j2;
        }
        if ((((int) j) & 1) != (((int) j2) & 1)) {
            return w(j) ? c(j, t(j), t(j2)) : c(j, t(j2), t(j));
        }
        long jT = t(j) + t(j2);
        return x(j) ? c.m(jT) : c.k(jT);
    }

    public static final String B(long j) {
        StringBuilder sb = new StringBuilder();
        if (z(j)) {
            sb.append('-');
        }
        sb.append("PT");
        long j2 = j(j);
        long jM = m(j2);
        int iP = p(j2);
        int iR = r(j2);
        int iQ = q(j2);
        if (y(j)) {
            jM = 9999999999999L;
        }
        boolean z = true;
        boolean z2 = jM != 0;
        boolean z3 = (iR == 0 && iQ == 0) ? false : true;
        if (iP == 0 && (!z3 || !z2)) {
            z = false;
        }
        if (z2) {
            sb.append(jM);
            sb.append('H');
        }
        if (z) {
            sb.append(iP);
            sb.append('M');
        }
        if (z3 || (!z2 && !z)) {
            d(j, sb, iR, iQ, 9, "S", true);
        }
        String string = sb.toString();
        s.d(string, "StringBuilder().apply(builderAction).toString()");
        return string;
    }

    public static final long C(long j, d dVar) {
        s.e(dVar, "unit");
        if (j == f2729e) {
            return Long.MAX_VALUE;
        }
        if (j == f2730f) {
            return Long.MIN_VALUE;
        }
        return e.b(t(j), s(j), dVar);
    }

    public static String D(long j) {
        if (j == 0) {
            return "0s";
        }
        if (j == f2729e) {
            return "Infinity";
        }
        if (j == f2730f) {
            return "-Infinity";
        }
        boolean z = z(j);
        StringBuilder sb = new StringBuilder();
        if (z) {
            sb.append('-');
        }
        long j2 = j(j);
        long jL = l(j2);
        int iK = k(j2);
        int iP = p(j2);
        int iR = r(j2);
        int iQ = q(j2);
        int i = 0;
        boolean z2 = jL != 0;
        boolean z3 = iK != 0;
        boolean z4 = iP != 0;
        boolean z5 = (iR == 0 && iQ == 0) ? false : true;
        if (z2) {
            sb.append(jL);
            sb.append('d');
            i = 1;
        }
        if (z3 || (z2 && (z4 || z5))) {
            int i2 = i + 1;
            if (i > 0) {
                sb.append(' ');
            }
            sb.append(iK);
            sb.append('h');
            i = i2;
        }
        if (z4 || (z5 && (z3 || z2))) {
            int i3 = i + 1;
            if (i > 0) {
                sb.append(' ');
            }
            sb.append(iP);
            sb.append('m');
            i = i3;
        }
        if (z5) {
            int i4 = i + 1;
            if (i > 0) {
                sb.append(' ');
            }
            if (iR != 0 || z2 || z3 || z4) {
                d(j, sb, iR, iQ, 9, "s", false);
            } else if (iQ >= 1000000) {
                d(j, sb, iQ / 1000000, iQ % 1000000, 6, "ms", false);
            } else if (iQ >= 1000) {
                d(j, sb, iQ / 1000, iQ % 1000, 3, "us", false);
            } else {
                sb.append(iQ);
                sb.append("ns");
            }
            i = i4;
        }
        if (z && i > 1) {
            sb.insert(1, '(').append(')');
        }
        String string = sb.toString();
        s.d(string, "StringBuilder().apply(builderAction).toString()");
        return string;
    }

    public static final long E(long j) {
        return c.i(-t(j), ((int) j) & 1);
    }

    private static final long c(long j, long j2, long j3) {
        long jO = c.o(j3);
        long j4 = j2 + jO;
        if (!new k(-4611686018426L, 4611686018426L).d(j4)) {
            return c.j(d.p0.n.e(j4, -4611686018427387903L, 4611686018427387903L));
        }
        return c.l(c.n(j4) + (j3 - c.n(jO)));
    }

    private static final void d(long j, StringBuilder sb, int i, int i2, int i3, String str, boolean z) {
        sb.append(i);
        if (i2 != 0) {
            sb.append('.');
            String strP = r.P(String.valueOf(i2), i3, '0');
            int i4 = -1;
            int length = strP.length() - 1;
            if (length >= 0) {
                while (true) {
                    int i5 = length - 1;
                    if (strP.charAt(length) != '0') {
                        i4 = length;
                        break;
                    } else if (i5 < 0) {
                        break;
                    } else {
                        length = i5;
                    }
                }
            }
            int i6 = i4 + 1;
            if (z || i6 >= 3) {
                sb.append((CharSequence) strP, 0, ((i6 + 2) / 3) * 3);
                s.d(sb, "this.append(value, startIndex, endIndex)");
            } else {
                sb.append((CharSequence) strP, 0, i6);
                s.d(sb, "this.append(value, startIndex, endIndex)");
            }
        }
        sb.append(str);
    }

    public static final /* synthetic */ a e(long j) {
        return new a(j);
    }

    public static int g(long j, long j2) {
        long j3 = j ^ j2;
        if (j3 < 0 || (((int) j3) & 1) == 0) {
            return s.g(j, j2);
        }
        int i = (((int) j) & 1) - (((int) j2) & 1);
        return z(j) ? -i : i;
    }

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

    public static boolean i(long j, Object obj) {
        return (obj instanceof a) && j == ((a) obj).F();
    }

    public static final long j(long j) {
        return z(j) ? E(j) : j;
    }

    public static final int k(long j) {
        if (y(j)) {
            return 0;
        }
        return (int) (m(j) % ((long) 24));
    }

    public static final long l(long j) {
        return C(j, d.DAYS);
    }

    public static final long m(long j) {
        return C(j, d.HOURS);
    }

    public static final long n(long j) {
        return C(j, d.MINUTES);
    }

    public static final long o(long j) {
        return C(j, d.SECONDS);
    }

    public static final int p(long j) {
        if (y(j)) {
            return 0;
        }
        return (int) (n(j) % ((long) 60));
    }

    public static final int q(long j) {
        if (y(j)) {
            return 0;
        }
        return (int) (w(j) ? c.n(t(j) % ((long) 1000)) : t(j) % ((long) 1000000000));
    }

    public static final int r(long j) {
        if (y(j)) {
            return 0;
        }
        return (int) (o(j) % ((long) 60));
    }

    private static final d s(long j) {
        return x(j) ? d.NANOSECONDS : d.MILLISECONDS;
    }

    private static final long t(long j) {
        return j >> 1;
    }

    public static int u(long j) {
        return (int) (j ^ (j >>> 32));
    }

    public static final boolean v(long j) {
        return !y(j);
    }

    private static final boolean w(long j) {
        return (((int) j) & 1) == 1;
    }

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

    public static final boolean y(long j) {
        return j == f2729e || j == f2730f;
    }

    public static final boolean z(long j) {
        return j < 0;
    }

    public final /* synthetic */ long F() {
        return this.f2731g;
    }

    @Override // java.lang.Comparable
    public /* bridge */ /* synthetic */ int compareTo(a aVar) {
        return f(aVar.F());
    }

    public boolean equals(Object obj) {
        return i(this.f2731g, obj);
    }

    public int f(long j) {
        return g(this.f2731g, j);
    }

    public int hashCode() {
        return u(this.f2731g);
    }

    public String toString() {
        return D(this.f2731g);
    }
}
