package g.e.b.g0.f0;

import g.e.b.d0;
import g.e.b.e0;
import g.e.b.x;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

/* JADX INFO: loaded from: classes.dex */
public final class c extends d0<Date> {
    public static final e0 a = new a();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final List<DateFormat> f4045b;

    public class a implements e0 {
        @Override // g.e.b.e0
        public <T> d0<T> b(g.e.b.j jVar, g.e.b.h0.a<T> aVar) {
            if (aVar.a == Date.class) {
                return new c();
            }
            return null;
        }
    }

    public c() {
        ArrayList arrayList = new ArrayList();
        this.f4045b = arrayList;
        Locale locale = Locale.US;
        arrayList.add(DateFormat.getDateTimeInstance(2, 2, locale));
        if (!Locale.getDefault().equals(locale)) {
            arrayList.add(DateFormat.getDateTimeInstance(2, 2));
        }
        if (g.e.b.g0.t.a()) {
            arrayList.add(g.e.a.a.a.p(2, 2));
        }
    }

    @Override // g.e.b.d0
    public Date a(g.e.b.i0.a aVar) throws IOException {
        Date dateB;
        if (aVar.I() == g.e.b.i0.b.NULL) {
            aVar.E();
            return null;
        }
        String strG = aVar.G();
        synchronized (this.f4045b) {
            Iterator<DateFormat> it = this.f4045b.iterator();
            while (true) {
                if (!it.hasNext()) {
                    try {
                        dateB = g.e.b.g0.f0.v.a.b(strG, new ParsePosition(0));
                        break;
                    } catch (ParseException e2) {
                        throw new x(g.a.a.a.a.h(aVar, g.a.a.a.a.K("Failed parsing '", strG, "' as Date; at path ")), e2);
                    }
                }
                try {
                    dateB = it.next().parse(strG);
                    break;
                } catch (ParseException unused) {
                }
            }
        }
        return dateB;
    }

    @Override // g.e.b.d0
    public void b(g.e.b.i0.c cVar, Date date) {
        String str;
        Date date2 = date;
        if (date2 == null) {
            cVar.m();
            return;
        }
        DateFormat dateFormat = this.f4045b.get(0);
        synchronized (this.f4045b) {
            str = dateFormat.format(date2);
        }
        cVar.B(str);
    }
}
