package com.google.gson.internal.bind;

import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.google.gson.Gson;
import com.google.gson.b.a;
import com.google.gson.c.b;
import com.google.gson.c.c;
import com.google.gson.internal.d;
import com.google.gson.internal.i;
import com.google.gson.s;
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.List;
import java.util.Locale;

public final class DateTypeAdapter extends u<Date> {
    public static final v LIZ = new v() {
        static {
            Covode.recordClassIndex(45409);
        }

        public final <T> u<T> create(Gson gson, a<T> aVar) {
            if (aVar.rawType == Date.class) {
                return new DateTypeAdapter();
            }
            return null;
        }
    };
    public final List<DateFormat> LIZIZ;

    static {
        Covode.recordClassIndex(45408);
    }

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

    public final /* synthetic */ Object read(com.google.gson.c.a aVar) {
        if (aVar.LJFF() != b.NULL) {
            return LIZ(aVar.LJIIIIZZ());
        }
        aVar.LJIIJ();
        return null;
    }

    /* JADX WARNING: type inference failed for: r0v3, types: [java.lang.Throwable, com.google.gson.s] */
    private synchronized Date LIZ(String str) {
        MethodCollector.i(1390);
        for (DateFormat parse : this.LIZIZ) {
            try {
                Date parse2 = parse.parse(str);
                MethodCollector.o(1390);
                return parse2;
            } catch (ParseException unused) {
            }
        }
        try {
            Date LIZ2 = com.google.gson.internal.bind.a.a.LIZ(str, new ParsePosition(0));
            MethodCollector.o(1390);
            return LIZ2;
        } catch (ParseException e) {
            ? sVar = new s(str, e);
            MethodCollector.o(1390);
            throw sVar;
        }
    }

    /* access modifiers changed from: private */
    /* renamed from: LIZ */
    public synchronized void write(c cVar, Date date) {
        MethodCollector.i(1395);
        if (date == null) {
            cVar.LJFF();
            MethodCollector.o(1395);
            return;
        }
        cVar.LIZIZ(this.LIZIZ.get(0).format(date));
        MethodCollector.o(1395);
    }
}
