package o; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectStreamException; import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.threeten.bp.DateTimeException; import org.threeten.bp.format.DateTimeParseException; import org.threeten.bp.temporal.UnsupportedTemporalTypeException; /* renamed from: o.gso, reason: case insensitive filesystem */ /* loaded from: classes.dex */ public final class C15519gso implements gtN, Comparable, Serializable { private static final int NANOS_PER_MILLI = 1000000; private static final int NANOS_PER_SECOND = 1000000000; private static final long serialVersionUID = 3078945930695997490L; private final int nanos; private final long seconds; public static final C15519gso ZERO = new C15519gso(0, 0); private static final BigInteger BI_NANOS_PER_SECOND = BigInteger.valueOf(1000000000); private static final Pattern PATTERN = Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)D)?(T(?:([-+]?[0-9]+)H)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)(?:[.,]([0-9]{0,9}))?S)?)?", 2); public static C15519gso ofDays(long j) { return create(gtG.safeMultiply(j, 86400), 0); } public static C15519gso ofHours(long j) { return create(gtG.safeMultiply(j, 3600), 0); } public static C15519gso ofMinutes(long j) { return create(gtG.safeMultiply(j, 60), 0); } public static C15519gso ofSeconds(long j) { return create(j, 0); } public static C15519gso ofSeconds(long j, long j2) { return create(gtG.safeAdd(j, gtG.floorDiv(j2, 1000000000L)), gtG.floorMod(j2, 1000000000)); } public static C15519gso ofMillis(long j) { long j2 = j / 1000; int i = (int) (j % 1000); if (i < 0) { i += 1000; j2--; } return create(j2, i * NANOS_PER_MILLI); } public static C15519gso ofNanos(long j) { long j2 = j / 1000000000; int i = (int) (j % 1000000000); if (i < 0) { i += 1000000000; j2--; } return create(j2, i); } public static C15519gso of(long j, InterfaceC15539gtV interfaceC15539gtV) { return ZERO.plus(j, interfaceC15539gtV); } public static C15519gso from(gtN gtn) { gtG.requireNonNull(gtn, "amount"); C15519gso c15519gso = ZERO; for (InterfaceC15539gtV interfaceC15539gtV : gtn.getUnits()) { c15519gso = c15519gso.plus(gtn.get(interfaceC15539gtV), interfaceC15539gtV); } return c15519gso; } public static C15519gso between(InterfaceC15536gtL interfaceC15536gtL, InterfaceC15536gtL interfaceC15536gtL2) { long until = interfaceC15536gtL.until(interfaceC15536gtL2, gtH.SECONDS); long j = 0; if (interfaceC15536gtL.isSupported(EnumC15534gtD.NANO_OF_SECOND) && interfaceC15536gtL2.isSupported(EnumC15534gtD.NANO_OF_SECOND)) { try { long j2 = interfaceC15536gtL.getLong(EnumC15534gtD.NANO_OF_SECOND); long j3 = interfaceC15536gtL2.getLong(EnumC15534gtD.NANO_OF_SECOND) - j2; if (until > 0 && j3 < 0) { j = j3 + 1000000000; } else if (until >= 0 || j3 <= 0) { if (until == 0 && j3 != 0) { try { until = interfaceC15536gtL.until(interfaceC15536gtL2.with(EnumC15534gtD.NANO_OF_SECOND, j2), gtH.SECONDS); } catch (ArithmeticException | DateTimeException unused) { } } j = j3; } else { j = j3 - 1000000000; } } catch (ArithmeticException | DateTimeException unused2) { } } return ofSeconds(until, j); } public static C15519gso parse(CharSequence charSequence) { gtG.requireNonNull(charSequence, "text"); Matcher matcher = PATTERN.matcher(charSequence); if (matcher.matches() && !"T".equals(matcher.group(3))) { int i = 1; boolean equals = "-".equals(matcher.group(1)); String group = matcher.group(2); String group2 = matcher.group(4); String group3 = matcher.group(5); String group4 = matcher.group(6); String group5 = matcher.group(7); if (group != null || group2 != null || group3 != null || group4 != null) { long parseNumber = parseNumber(charSequence, group, 86400, "days"); long parseNumber2 = parseNumber(charSequence, group2, 3600, "hours"); long parseNumber3 = parseNumber(charSequence, group3, 60, "minutes"); long parseNumber4 = parseNumber(charSequence, group4, 1, "seconds"); if (group4 != null && group4.charAt(0) == '-') { i = -1; } try { return create(equals, parseNumber, parseNumber2, parseNumber3, parseNumber4, parseFraction(charSequence, group5, i)); } catch (ArithmeticException e) { throw ((DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: overflow", charSequence, 0).initCause(e)); } } } throw new DateTimeParseException("Text cannot be parsed to a Duration", charSequence, 0); } private static long parseNumber(CharSequence charSequence, String str, int i, String str2) { if (str == null) { return 0L; } try { if (str.startsWith("+")) { str = str.substring(1); } return gtG.safeMultiply(Long.parseLong(str), i); } catch (ArithmeticException e) { throw ((DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: ".concat(String.valueOf(str2)), charSequence, 0).initCause(e)); } catch (NumberFormatException e2) { throw ((DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: ".concat(String.valueOf(str2)), charSequence, 0).initCause(e2)); } } private static int parseFraction(CharSequence charSequence, String str, int i) { if (str == null || str.length() == 0) { return 0; } try { StringBuilder sb = new StringBuilder(); sb.append(str); sb.append("000000000"); return Integer.parseInt(sb.toString().substring(0, 9)) * i; } catch (ArithmeticException e) { throw ((DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: fraction", charSequence, 0).initCause(e)); } catch (NumberFormatException e2) { throw ((DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: fraction", charSequence, 0).initCause(e2)); } } private static C15519gso create(boolean z, long j, long j2, long j3, long j4, int i) { long safeAdd = gtG.safeAdd(j, gtG.safeAdd(j2, gtG.safeAdd(j3, j4))); if (z) { return ofSeconds(safeAdd, i).negated(); } return ofSeconds(safeAdd, i); } private static C15519gso create(long j, int i) { return (((long) i) | j) == 0 ? ZERO : new C15519gso(j, i); } private C15519gso(long j, int i) { this.seconds = j; this.nanos = i; } @Override // o.gtN public final List getUnits() { return Collections.unmodifiableList(Arrays.asList(gtH.SECONDS, gtH.NANOS)); } @Override // o.gtN public final long get(InterfaceC15539gtV interfaceC15539gtV) { if (interfaceC15539gtV == gtH.SECONDS) { return this.seconds; } if (interfaceC15539gtV == gtH.NANOS) { return this.nanos; } throw new UnsupportedTemporalTypeException("Unsupported unit: ".concat(String.valueOf(interfaceC15539gtV))); } public final C15519gso withSeconds(long j) { return create(j, this.nanos); } public final C15519gso withNanos(int i) { EnumC15534gtD.NANO_OF_SECOND.checkValidIntValue(i); return create(this.seconds, i); } public final C15519gso plus(C15519gso c15519gso) { return plus(c15519gso.getSeconds(), c15519gso.getNano()); } public final C15519gso plus(long j, InterfaceC15539gtV interfaceC15539gtV) { gtG.requireNonNull(interfaceC15539gtV, "unit"); if (interfaceC15539gtV == gtH.DAYS) { return plus(gtG.safeMultiply(j, 86400), 0L); } if (interfaceC15539gtV.isDurationEstimated()) { throw new DateTimeException("Unit must not have an estimated duration"); } if (j == 0) { return this; } if (interfaceC15539gtV instanceof gtH) { int i = AnonymousClass3.$SwitchMap$org$threeten$bp$temporal$ChronoUnit[((gtH) interfaceC15539gtV).ordinal()]; if (i == 1) { return plusNanos(j); } if (i == 2) { return plusSeconds((j / 1000000000) * 1000).plusNanos((j % 1000000000) * 1000); } if (i == 3) { return plusMillis(j); } if (i == 4) { return plusSeconds(j); } return plusSeconds(gtG.safeMultiply(interfaceC15539gtV.getDuration().seconds, j)); } return plusSeconds(interfaceC15539gtV.getDuration().multipliedBy(j).getSeconds()).plusNanos(r7.getNano()); } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: o.gso$3, reason: invalid class name */ /* loaded from: classes.dex */ public static /* synthetic */ class AnonymousClass3 { static final int[] $SwitchMap$org$threeten$bp$temporal$ChronoUnit; static { int[] iArr = new int[gtH.values().length]; $SwitchMap$org$threeten$bp$temporal$ChronoUnit = iArr; try { iArr[gtH.NANOS.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { $SwitchMap$org$threeten$bp$temporal$ChronoUnit[gtH.MICROS.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } try { $SwitchMap$org$threeten$bp$temporal$ChronoUnit[gtH.MILLIS.ordinal()] = 3; } catch (NoSuchFieldError unused3) { } try { $SwitchMap$org$threeten$bp$temporal$ChronoUnit[gtH.SECONDS.ordinal()] = 4; } catch (NoSuchFieldError unused4) { } } } public final C15519gso plusDays(long j) { return plus(gtG.safeMultiply(j, 86400), 0L); } public final C15519gso plusHours(long j) { return plus(gtG.safeMultiply(j, 3600), 0L); } public final C15519gso plusMinutes(long j) { return plus(gtG.safeMultiply(j, 60), 0L); } public final C15519gso plusSeconds(long j) { return plus(j, 0L); } public final C15519gso plusMillis(long j) { return plus(j / 1000, (j % 1000) * 1000000); } public final C15519gso plusNanos(long j) { return plus(0L, j); } private C15519gso plus(long j, long j2) { return (j | j2) == 0 ? this : ofSeconds(gtG.safeAdd(gtG.safeAdd(this.seconds, j), j2 / 1000000000), this.nanos + (j2 % 1000000000)); } public final C15519gso minus(C15519gso c15519gso) { long seconds = c15519gso.getSeconds(); int nano = c15519gso.getNano(); if (seconds == Long.MIN_VALUE) { return plus(Long.MAX_VALUE, -nano).plus(1L, 0L); } return plus(-seconds, -nano); } public final C15519gso minus(long j, InterfaceC15539gtV interfaceC15539gtV) { return j == Long.MIN_VALUE ? plus(Long.MAX_VALUE, interfaceC15539gtV).plus(1L, interfaceC15539gtV) : plus(-j, interfaceC15539gtV); } public final C15519gso minusDays(long j) { return j == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1L) : plusDays(-j); } public final C15519gso minusHours(long j) { return j == Long.MIN_VALUE ? plusHours(Long.MAX_VALUE).plusHours(1L) : plusHours(-j); } public final C15519gso minusMinutes(long j) { return j == Long.MIN_VALUE ? plusMinutes(Long.MAX_VALUE).plusMinutes(1L) : plusMinutes(-j); } public final C15519gso minusSeconds(long j) { return j == Long.MIN_VALUE ? plusSeconds(Long.MAX_VALUE).plusSeconds(1L) : plusSeconds(-j); } public final C15519gso minusMillis(long j) { return j == Long.MIN_VALUE ? plusMillis(Long.MAX_VALUE).plusMillis(1L) : plusMillis(-j); } public final C15519gso minusNanos(long j) { return j == Long.MIN_VALUE ? plusNanos(Long.MAX_VALUE).plusNanos(1L) : plusNanos(-j); } public final C15519gso multipliedBy(long j) { return j == 0 ? ZERO : j == 1 ? this : create(toSeconds().multiply(BigDecimal.valueOf(j))); } public final C15519gso dividedBy(long j) { if (j != 0) { return j == 1 ? this : create(toSeconds().divide(BigDecimal.valueOf(j), RoundingMode.DOWN)); } throw new ArithmeticException("Cannot divide by zero"); } private BigDecimal toSeconds() { return BigDecimal.valueOf(this.seconds).add(BigDecimal.valueOf(this.nanos, 9)); } private static C15519gso create(BigDecimal bigDecimal) { BigInteger bigIntegerExact = bigDecimal.movePointRight(9).toBigIntegerExact(); BigInteger[] divideAndRemainder = bigIntegerExact.divideAndRemainder(BI_NANOS_PER_SECOND); if (divideAndRemainder[0].bitLength() > 63) { throw new ArithmeticException("Exceeds capacity of Duration: ".concat(String.valueOf(bigIntegerExact))); } return ofSeconds(divideAndRemainder[0].longValue(), divideAndRemainder[1].intValue()); } public final C15519gso negated() { return multipliedBy(-1L); } public final C15519gso abs() { return isNegative() ? negated() : this; } @Override // o.gtN public final InterfaceC15536gtL addTo(InterfaceC15536gtL interfaceC15536gtL) { long j = this.seconds; if (j != 0) { interfaceC15536gtL = interfaceC15536gtL.plus(j, gtH.SECONDS); } int i = this.nanos; return i != 0 ? interfaceC15536gtL.plus(i, gtH.NANOS) : interfaceC15536gtL; } @Override // o.gtN public final InterfaceC15536gtL subtractFrom(InterfaceC15536gtL interfaceC15536gtL) { long j = this.seconds; if (j != 0) { interfaceC15536gtL = interfaceC15536gtL.minus(j, gtH.SECONDS); } int i = this.nanos; return i != 0 ? interfaceC15536gtL.minus(i, gtH.NANOS) : interfaceC15536gtL; } public final long toDays() { return this.seconds / 86400; } public final long toHours() { return this.seconds / 3600; } public final long toMinutes() { return this.seconds / 60; } public final long toMillis() { return gtG.safeAdd(gtG.safeMultiply(this.seconds, 1000), this.nanos / NANOS_PER_MILLI); } public final long toNanos() { return gtG.safeAdd(gtG.safeMultiply(this.seconds, 1000000000), this.nanos); } public final long toDaysPart() { return this.seconds / 86400; } public final int toHoursPart() { return (int) (toHours() % 24); } public final int toMinutesPart() { return (int) (toMinutes() % 60); } public final int toSecondsPart() { return (int) (this.seconds % 60); } public final int toMillisPart() { return this.nanos / NANOS_PER_MILLI; } @Override // java.lang.Comparable public final int compareTo(C15519gso c15519gso) { int compareLongs = gtG.compareLongs(this.seconds, c15519gso.seconds); return compareLongs != 0 ? compareLongs : this.nanos - c15519gso.nanos; } public final boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof C15519gso)) { return false; } C15519gso c15519gso = (C15519gso) obj; return this.seconds == c15519gso.seconds && this.nanos == c15519gso.nanos; } public final String toString() { if (this == ZERO) { return "PT0S"; } long j = this.seconds; long j2 = j / 3600; int i = (int) ((j % 3600) / 60); int i2 = (int) (j % 60); StringBuilder sb = new StringBuilder(24); sb.append("PT"); if (j2 != 0) { sb.append(j2); sb.append('H'); } if (i != 0) { sb.append(i); sb.append('M'); } if (i2 == 0 && this.nanos == 0 && sb.length() > 2) { return sb.toString(); } if (i2 >= 0 || this.nanos <= 0) { sb.append(i2); } else if (i2 == -1) { sb.append("-0"); } else { sb.append(i2 + 1); } if (this.nanos > 0) { int length = sb.length(); if (i2 < 0) { sb.append(2000000000 - this.nanos); } else { sb.append(this.nanos + 1000000000); } while (sb.charAt(sb.length() - 1) == '0') { sb.setLength(sb.length() - 1); } sb.setCharAt(length, '.'); } sb.append('S'); return sb.toString(); } private Object writeReplace() { return new C15501gsD((byte) 1, this); } private Object readResolve() throws ObjectStreamException { throw new InvalidObjectException("Deserialization via serialization delegate"); } /* JADX INFO: Access modifiers changed from: package-private */ public final void writeExternal(DataOutput dataOutput) throws IOException { dataOutput.writeLong(this.seconds); dataOutput.writeInt(this.nanos); } /* JADX INFO: Access modifiers changed from: package-private */ public static C15519gso readExternal(DataInput dataInput) throws IOException { return ofSeconds(dataInput.readLong(), dataInput.readInt()); } public final int toNanosPart() { return this.nanos; } public final boolean isZero() { return (this.seconds | ((long) this.nanos)) == 0; } public final boolean isNegative() { return this.seconds < 0; } public final int hashCode() { long j = this.seconds; return ((int) (j ^ (j >>> 32))) + (this.nanos * 51); } public final long getSeconds() { return this.seconds; } public final int getNano() { return this.nanos; } }