package l3;

import i3.C0639g;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import p0.AbstractC0928a;
import q3.C0957b;

/* JADX INFO: loaded from: classes.dex */
public final class d extends i3.k {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final C0829a f8911b = new C0829a(1);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ArrayList f8912a;

    public d() {
        ArrayList arrayList = new ArrayList();
        this.f8912a = arrayList;
        Locale locale = Locale.US;
        arrayList.add(DateFormat.getDateTimeInstance(2, 2, locale));
        if (!Locale.getDefault().equals(locale)) {
            arrayList.add(DateFormat.getDateTimeInstance(2, 2));
        }
        if (k3.j.f8638a >= 9) {
            arrayList.add(new SimpleDateFormat("MMM d, yyyy h:mm:ss a", locale));
        }
    }

    @Override // i3.k
    public final Object a(C0957b c0957b) throws IOException {
        if (c0957b.G() == 9) {
            c0957b.C();
            return null;
        }
        String strE = c0957b.E();
        synchronized (this.f8912a) {
            try {
                Iterator it = this.f8912a.iterator();
                while (it.hasNext()) {
                    try {
                        return ((DateFormat) it.next()).parse(strE);
                    } catch (ParseException unused) {
                    }
                }
                try {
                    return m3.a.b(strE, new ParsePosition(0));
                } catch (ParseException e2) {
                    StringBuilder sbN = AbstractC0928a.n("Failed parsing '", strE, "' as Date; at path ");
                    sbN.append(c0957b.r());
                    throw new C0639g(sbN.toString(), e2);
                }
            } finally {
            }
        }
    }

    @Override // i3.k
    public final void b(q3.c cVar, Object obj) throws IOException {
        String str;
        Date date = (Date) obj;
        if (date == null) {
            cVar.o();
            return;
        }
        DateFormat dateFormat = (DateFormat) this.f8912a.get(0);
        synchronized (this.f8912a) {
            str = dateFormat.format(date);
        }
        cVar.y(str);
    }
}
