package com.google.ads.interactivemedia.v3.internal;

import com.google.android.gms.measurement.internal.u1;
import defpackage.e;
import java.text.ParseException;
import java.text.ParsePosition;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

/* JADX INFO: loaded from: classes2.dex */
public final class zzabi {
    private static final TimeZone zza = TimeZone.getTimeZone("UTC");

    /* JADX WARN: Removed duplicated region for block: B:100:0x0200  */
    /* JADX WARN: Removed duplicated region for block: B:94:0x01ec  */
    /* JADX WARN: Removed duplicated region for block: B:95:0x01ee  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Date zza(String str, ParsePosition parsePosition) throws ParseException {
        String message;
        int i10;
        int i11;
        int iZzb;
        int iZzb2;
        int length;
        TimeZone timeZone;
        char cCharAt;
        int length2;
        try {
            int index = parsePosition.getIndex();
            int i12 = index + 4;
            int iZzb3 = zzb(str, index, i12);
            if (zzc(str, i12, '-')) {
                i12 = index + 5;
            }
            int i13 = i12 + 2;
            int iZzb4 = zzb(str, i12, i13);
            if (zzc(str, i13, '-')) {
                i13 = i12 + 3;
            }
            int i14 = i13 + 2;
            int iZzb5 = zzb(str, i13, i14);
            boolean zZzc = zzc(str, i14, 'T');
            if (!zZzc && str.length() <= i14) {
                GregorianCalendar gregorianCalendar = new GregorianCalendar(iZzb3, iZzb4 - 1, iZzb5);
                gregorianCalendar.setLenient(false);
                parsePosition.setIndex(i14);
                return gregorianCalendar.getTime();
            }
            if (zZzc) {
                int i15 = i13 + 5;
                int iZzb6 = zzb(str, i13 + 3, i15);
                if (zzc(str, i15, ':')) {
                    i15 = i13 + 6;
                }
                int i16 = i15 + 2;
                int iZzb7 = zzb(str, i15, i16);
                if (zzc(str, i16, ':')) {
                    i16 = i15 + 3;
                }
                if (str.length() <= i16 || (cCharAt = str.charAt(i16)) == 'Z' || cCharAt == '+' || cCharAt == '-') {
                    i11 = iZzb7;
                    iZzb = 0;
                    iZzb2 = 0;
                    i14 = i16;
                    i10 = iZzb6;
                } else {
                    int i17 = i16 + 2;
                    iZzb2 = zzb(str, i16, i17);
                    if (iZzb2 > 59 && iZzb2 < 63) {
                        iZzb2 = 59;
                    }
                    if (zzc(str, i17, '.')) {
                        int i18 = i16 + 3;
                        for (int i19 = i16 + 4; i19 < str.length(); i19++) {
                            char cCharAt2 = str.charAt(i19);
                            if (cCharAt2 >= '0' && cCharAt2 <= '9') {
                            }
                            length2 = i19;
                        }
                        length2 = str.length();
                        int iMin = Math.min(length2, i16 + 6);
                        iZzb = zzb(str, i18, iMin);
                        int i20 = iMin - i18;
                        if (i20 == 1) {
                            iZzb *= 100;
                        } else if (i20 == 2) {
                            iZzb *= 10;
                        }
                        i10 = iZzb6;
                        i14 = length2;
                        i11 = iZzb7;
                    } else {
                        i10 = iZzb6;
                        i14 = i17;
                        i11 = iZzb7;
                        iZzb = 0;
                    }
                }
            } else {
                i10 = 0;
                i11 = 0;
                iZzb = 0;
                iZzb2 = 0;
            }
            if (str.length() <= i14) {
                throw new IllegalArgumentException("No time zone indicator");
            }
            char cCharAt3 = str.charAt(i14);
            if (cCharAt3 == 'Z') {
                timeZone = zza;
                length = i14 + 1;
            } else {
                if (cCharAt3 != '+' && cCharAt3 != '-') {
                    throw new IndexOutOfBoundsException("Invalid time zone indicator '" + cCharAt3 + "'");
                }
                String strSubstring = str.substring(i14);
                if (strSubstring.length() < 5) {
                    strSubstring = strSubstring + "00";
                }
                length = i14 + strSubstring.length();
                if (strSubstring.equals("+0000") || strSubstring.equals("+00:00")) {
                    timeZone = zza;
                } else {
                    String str2 = "GMT" + strSubstring;
                    TimeZone timeZone2 = TimeZone.getTimeZone(str2);
                    String id2 = timeZone2.getID();
                    if (!id2.equals(str2) && !id2.replace(":", "").equals(str2)) {
                        throw new IndexOutOfBoundsException("Mismatching time zone indicator: " + str2 + " given, resolves to " + timeZone2.getID());
                    }
                    timeZone = timeZone2;
                }
            }
            GregorianCalendar gregorianCalendar2 = new GregorianCalendar(timeZone);
            gregorianCalendar2.setLenient(false);
            gregorianCalendar2.set(1, iZzb3);
            gregorianCalendar2.set(2, iZzb4 - 1);
            gregorianCalendar2.set(5, iZzb5);
            gregorianCalendar2.set(11, i10);
            gregorianCalendar2.set(12, i11);
            gregorianCalendar2.set(13, iZzb2);
            gregorianCalendar2.set(14, iZzb);
            parsePosition.setIndex(length);
            return gregorianCalendar2.getTime();
        } catch (IllegalArgumentException e10) {
            e = e10;
            String strK = str != null ? null : u1.k("\"", str, "\"");
            message = e.getMessage();
            if (message != null || message.isEmpty()) {
                message = u1.k("(", e.getClass().getName(), ")");
            }
            ParseException parseException = new ParseException(e.k("Failed to parse date [", strK, "]: ", message), parsePosition.getIndex());
            parseException.initCause(e);
            throw parseException;
        } catch (IndexOutOfBoundsException e11) {
            e = e11;
            if (str != null) {
            }
            message = e.getMessage();
            if (message != null) {
                message = u1.k("(", e.getClass().getName(), ")");
            }
            ParseException parseException2 = new ParseException(e.k("Failed to parse date [", strK, "]: ", message), parsePosition.getIndex());
            parseException2.initCause(e);
            throw parseException2;
        }
    }

    private static int zzb(String str, int i10, int i11) throws NumberFormatException {
        int i12;
        int i13;
        if (i10 < 0 || i11 > str.length() || i10 > i11) {
            throw new NumberFormatException(str);
        }
        if (i10 < i11) {
            i13 = i10 + 1;
            int iDigit = Character.digit(str.charAt(i10), 10);
            if (iDigit < 0) {
                throw new NumberFormatException("Invalid number: ".concat(String.valueOf(str.substring(i10, i11))));
            }
            i12 = -iDigit;
        } else {
            i12 = 0;
            i13 = i10;
        }
        while (i13 < i11) {
            int i14 = i13 + 1;
            int iDigit2 = Character.digit(str.charAt(i13), 10);
            if (iDigit2 < 0) {
                throw new NumberFormatException("Invalid number: ".concat(String.valueOf(str.substring(i10, i11))));
            }
            i12 = (i12 * 10) - iDigit2;
            i13 = i14;
        }
        return -i12;
    }

    private static boolean zzc(String str, int i10, char c6) {
        return i10 < str.length() && str.charAt(i10) == c6;
    }
}
