package com.google.gson.internal.bind;

import com.google.gson.q;
import com.google.gson.u;
import com.google.gson.v;
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;
import uk.i;

/* loaded from: classes3.dex */
public final class DateTypeAdapter extends u {

    /* renamed from: b, reason: collision with root package name */
    public static final v f14885b = new v() { // from class: com.google.gson.internal.bind.DateTypeAdapter.1
        @Override // com.google.gson.v
        public u create(com.google.gson.d dVar, com.google.gson.reflect.a aVar) {
            if (aVar.getRawType() == Date.class) {
                return new DateTypeAdapter();
            }
            return null;
        }
    };

    /* renamed from: a, reason: collision with root package name */
    private final List f14886a;

    public DateTypeAdapter() {
        ArrayList arrayList = new ArrayList();
        this.f14886a = arrayList;
        Locale locale = Locale.US;
        arrayList.add(DateFormat.getDateTimeInstance(2, 2, locale));
        if (!Locale.getDefault().equals(locale)) {
            arrayList.add(DateFormat.getDateTimeInstance(2, 2));
        }
        if (uk.d.d()) {
            arrayList.add(i.c(2, 2));
        }
    }

    private Date a(xk.a aVar) {
        String J = aVar.J();
        synchronized (this.f14886a) {
            Iterator it = this.f14886a.iterator();
            while (it.hasNext()) {
                try {
                    return ((DateFormat) it.next()).parse(J);
                } catch (ParseException unused) {
                }
            }
            try {
                return vk.a.c(J, new ParsePosition(0));
            } catch (ParseException e10) {
                throw new q("Failed parsing '" + J + "' as Date; at path " + aVar.m(), e10);
            }
        }
    }

    @Override // com.google.gson.u
    /* renamed from: b, reason: merged with bridge method [inline-methods] */
    public Date read(xk.a aVar) {
        if (aVar.L() != xk.b.NULL) {
            return a(aVar);
        }
        aVar.G();
        return null;
    }

    @Override // com.google.gson.u
    /* renamed from: c, reason: merged with bridge method [inline-methods] */
    public void write(xk.c cVar, Date date) {
        String format;
        if (date == null) {
            cVar.t();
            return;
        }
        DateFormat dateFormat = (DateFormat) this.f14886a.get(0);
        synchronized (this.f14886a) {
            format = dateFormat.format(date);
        }
        cVar.Q(format);
    }
}
