package h;

import d.AbstractC0421a;
import d.C0424d;
import g.C0474a;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.Date;

/* JADX INFO: loaded from: classes.dex */
public class z extends AbstractC0500b implements t {

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final z f4184c = new z(true);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private boolean f4185a = false;

    public z() {
    }

    @Override // h.t
    public int d() {
        return 2;
    }

    @Override // h.AbstractC0500b
    protected Object f(C0474a c0474a, Type type, Object obj, Object obj2) {
        long timeInMillis;
        if (this.f4185a) {
            return g(c0474a, type, obj, obj2);
        }
        if (obj2 == null) {
            return null;
        }
        if (obj2 instanceof Date) {
            return new java.sql.Date(((Date) obj2).getTime());
        }
        if (obj2 instanceof BigDecimal) {
            return new java.sql.Date(l.l.D0((BigDecimal) obj2));
        }
        if (obj2 instanceof Number) {
            return new java.sql.Date(((Number) obj2).longValue());
        }
        if (!(obj2 instanceof String)) {
            throw new C0424d("parse error : " + obj2);
        }
        String str = (String) obj2;
        if (str.length() == 0) {
            return null;
        }
        g.f fVar = new g.f(str);
        try {
            if (fVar.X0()) {
                timeInMillis = fVar.k0().getTimeInMillis();
            } else {
                try {
                    java.sql.Date date = new java.sql.Date(c0474a.m().parse(str).getTime());
                    fVar.close();
                    return date;
                } catch (ParseException unused) {
                    timeInMillis = Long.parseLong(str);
                }
            }
            fVar.close();
            return new java.sql.Date(timeInMillis);
        } catch (Throwable th) {
            fVar.close();
            throw th;
        }
    }

    protected Object g(C0474a c0474a, Type type, Object obj, Object obj2) {
        long timeInMillis;
        if (obj2 == null) {
            return null;
        }
        if (obj2 instanceof Date) {
            return new Timestamp(((Date) obj2).getTime());
        }
        if (obj2 instanceof BigDecimal) {
            return new Timestamp(l.l.D0((BigDecimal) obj2));
        }
        if (obj2 instanceof Number) {
            return new Timestamp(((Number) obj2).longValue());
        }
        if (!(obj2 instanceof String)) {
            throw new C0424d("parse error");
        }
        String str = (String) obj2;
        if (str.length() == 0) {
            return null;
        }
        g.f fVar = new g.f(str);
        try {
            if (str.length() > 19 && str.charAt(4) == '-' && str.charAt(7) == '-' && str.charAt(10) == ' ' && str.charAt(13) == ':' && str.charAt(16) == ':' && str.charAt(19) == '.') {
                String strL = c0474a.l();
                if (strL.length() != str.length() && strL == AbstractC0421a.f3677y) {
                    return Timestamp.valueOf(str);
                }
            }
            if (fVar.Y0(false)) {
                timeInMillis = fVar.k0().getTimeInMillis();
            } else {
                try {
                    return new Timestamp(c0474a.m().parse(str).getTime());
                } catch (ParseException unused) {
                    timeInMillis = Long.parseLong(str);
                }
            }
            fVar.close();
            return new Timestamp(timeInMillis);
        } finally {
            fVar.close();
        }
    }

    public z(boolean z2) {
    }
}
