116 lines
3.9 KiB
Java
116 lines
3.9 KiB
Java
package com.google.gson;
|
|
|
|
import c.i.a.f.e.o.c;
|
|
import c.i.d.q.o;
|
|
import c.i.d.q.x.d.a;
|
|
import com.google.gson.stream.JsonReader;
|
|
import com.google.gson.stream.JsonToken;
|
|
import com.google.gson.stream.JsonWriter;
|
|
import java.io.IOException;
|
|
import java.sql.Timestamp;
|
|
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.List;
|
|
import java.util.Locale;
|
|
public final class DefaultDateTypeAdapter extends TypeAdapter<Date> {
|
|
public final Class<? extends Date> a;
|
|
public final List<DateFormat> b;
|
|
|
|
public DefaultDateTypeAdapter(Class<? extends Date> cls, int i, int i2) {
|
|
ArrayList arrayList = new ArrayList();
|
|
this.b = arrayList;
|
|
a(cls);
|
|
this.a = cls;
|
|
Locale locale = Locale.US;
|
|
arrayList.add(DateFormat.getDateTimeInstance(i, i2, locale));
|
|
if (!Locale.getDefault().equals(locale)) {
|
|
arrayList.add(DateFormat.getDateTimeInstance(i, i2));
|
|
}
|
|
if (o.a >= 9) {
|
|
arrayList.add(c.N(i, i2));
|
|
}
|
|
}
|
|
|
|
public static Class<? extends Date> a(Class<? extends Date> cls) {
|
|
if (cls == Date.class || cls == java.sql.Date.class || cls == Timestamp.class) {
|
|
return cls;
|
|
}
|
|
throw new IllegalArgumentException("Date type must be one of " + Date.class + ", " + Timestamp.class + ", or " + java.sql.Date.class + " but was " + cls);
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
@Override // com.google.gson.TypeAdapter
|
|
public Date read(JsonReader jsonReader) throws IOException {
|
|
Date date;
|
|
Date date2;
|
|
if (jsonReader.N() == JsonToken.NULL) {
|
|
jsonReader.H();
|
|
return null;
|
|
}
|
|
String K = jsonReader.K();
|
|
synchronized (this.b) {
|
|
Iterator<DateFormat> it = this.b.iterator();
|
|
while (true) {
|
|
if (it.hasNext()) {
|
|
try {
|
|
date = it.next().parse(K);
|
|
break;
|
|
} catch (ParseException unused) {
|
|
}
|
|
} else {
|
|
try {
|
|
date = a.b(K, new ParsePosition(0));
|
|
break;
|
|
} catch (ParseException e) {
|
|
throw new JsonSyntaxException(K, e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Class<? extends Date> cls = this.a;
|
|
if (cls == Date.class) {
|
|
return date;
|
|
}
|
|
if (cls == Timestamp.class) {
|
|
date2 = new Timestamp(date.getTime());
|
|
} else if (cls == java.sql.Date.class) {
|
|
date2 = new java.sql.Date(date.getTime());
|
|
} else {
|
|
throw new AssertionError();
|
|
}
|
|
return date2;
|
|
}
|
|
|
|
public String toString() {
|
|
DateFormat dateFormat = this.b.get(0);
|
|
if (dateFormat instanceof SimpleDateFormat) {
|
|
StringBuilder L = c.d.b.a.a.L("DefaultDateTypeAdapter(");
|
|
L.append(((SimpleDateFormat) dateFormat).toPattern());
|
|
L.append(')');
|
|
return L.toString();
|
|
}
|
|
StringBuilder L2 = c.d.b.a.a.L("DefaultDateTypeAdapter(");
|
|
L2.append(dateFormat.getClass().getSimpleName());
|
|
L2.append(')');
|
|
return L2.toString();
|
|
}
|
|
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [com.google.gson.stream.JsonWriter, java.lang.Object] */
|
|
@Override // com.google.gson.TypeAdapter
|
|
public void write(JsonWriter jsonWriter, Date date) throws IOException {
|
|
Date date2 = date;
|
|
if (date2 == null) {
|
|
jsonWriter.s();
|
|
return;
|
|
}
|
|
synchronized (this.b) {
|
|
jsonWriter.H(this.b.get(0).format(date2));
|
|
}
|
|
}
|
|
}
|