package com.google.android.gms.internal.ads;

import androidx.annotation.Nullable;
import androidx.media3.exoplayer.rtsp.RtspHeaders;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

/* JADX INFO: loaded from: classes2.dex */
public abstract class wc {
    public static long a(String str) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
            simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
            return simpleDateFormat.parse(str).getTime();
        } catch (ParseException unused) {
            if (SessionDescription.SUPPORTED_SDP_VERSION.equals(str) || "-1".equals(str)) {
                oc.a("Unable to parse dateStr: %s, falling back to 0", str);
                return 0L;
            }
            oc.b("Unable to parse dateStr: %s, falling back to 0", str);
            return 0L;
        }
    }

    @Nullable
    public static yb zza(fc fcVar) {
        boolean z10;
        long j10;
        long j11;
        long j12;
        long j13;
        long jCurrentTimeMillis = System.currentTimeMillis();
        Map map = fcVar.zzc;
        if (map == null) {
            return null;
        }
        String str = (String) map.get(RtspHeaders.DATE);
        long jA = str != null ? a(str) : 0L;
        String str2 = (String) map.get(RtspHeaders.CACHE_CONTROL);
        int i10 = 0;
        if (str2 != null) {
            String[] strArrSplit = str2.split(",", 0);
            z10 = false;
            j10 = 0;
            j11 = 0;
            while (i10 < strArrSplit.length) {
                String strTrim = strArrSplit[i10].trim();
                if (strTrim.equals("no-cache") || strTrim.equals("no-store")) {
                    return null;
                }
                if (strTrim.startsWith("max-age=")) {
                    try {
                        j11 = Long.parseLong(strTrim.substring(8));
                    } catch (Exception unused) {
                    }
                } else if (strTrim.startsWith("stale-while-revalidate=")) {
                    j10 = Long.parseLong(strTrim.substring(23));
                } else if (strTrim.equals("must-revalidate") || strTrim.equals("proxy-revalidate")) {
                    z10 = true;
                }
                i10++;
            }
            i10 = 1;
        } else {
            z10 = false;
            j10 = 0;
            j11 = 0;
        }
        String str3 = (String) map.get(RtspHeaders.EXPIRES);
        long jA2 = str3 != null ? a(str3) : 0L;
        String str4 = (String) map.get("Last-Modified");
        long jA3 = str4 != null ? a(str4) : 0L;
        String str5 = (String) map.get("ETag");
        if (i10 != 0) {
            j13 = jCurrentTimeMillis + (j11 * 1000);
            j12 = z10 ? j13 : (j10 * 1000) + j13;
        } else {
            j12 = 0;
            if (jA <= 0 || jA2 < jA) {
                j13 = 0;
            } else {
                j13 = jCurrentTimeMillis + (jA2 - jA);
                j12 = j13;
            }
        }
        yb ybVar = new yb();
        ybVar.f18779a = fcVar.f11170b;
        ybVar.f18780b = str5;
        ybVar.f18784f = j13;
        ybVar.f18783e = j12;
        ybVar.f18781c = jA;
        ybVar.f18782d = jA3;
        ybVar.f18785g = map;
        ybVar.f18786h = fcVar.zzd;
        return ybVar;
    }
}
