本文整理汇总了Java中com.google.gson.internal.bind.util.ISO8601Utils类的典型用法代码示例。如果您正苦于以下问题:Java ISO8601Utils类的具体用法?Java ISO8601Utils怎么用?Java ISO8601Utils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ISO8601Utils类属于com.google.gson.internal.bind.util包,在下文中一共展示了ISO8601Utils类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
@Override
public java.sql.Date read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
try {
if (dateFormat != null) {
return new java.sql.Date(dateFormat.parse(date).getTime());
}
return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime());
} catch (ParseException e) {
throw new JsonParseException(e);
}
}
}
示例2: getTagsUpdate
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
@Nullable
public static List<Tags> getTagsUpdate(ApiService api, Date updateAtStart, Date updateAtEnd) {
List<Tags> list = new ArrayList<>();
int pageSize = 100;
String range = ISO8601Utils.format(updateAtStart) + "," + ISO8601Utils.format(updateAtEnd);
try {
Response<List<Tags>> response = api.getTags(range, pageSize, Pagination.getPage(list, pageSize)).execute();
if (!Tools.apiIsSuccessfulNoThrow(response))
return null;
int total = Integer.decode(response.headers().get("X-Total"));
list.addAll(response.body());
while (list.size() < total) {
response = api.getTags(range, pageSize, Pagination.getPage(list, pageSize)).execute();
if (!Tools.apiIsSuccessfulNoThrow(response))
return null;
list.addAll(response.body());
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
示例3: read
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
@Override
public Date read(JsonReader in) throws IOException {
final JsonToken peek = in.peek();
if (peek == JsonToken.NULL) {
in.nextNull();
return null;
} else {
String stringValue = in.nextString();
if (!stringValue.isEmpty()) {
try {
return ISO8601Utils.parse(stringValue, new ParsePosition(0));
} catch (ParseException e) {
try {
return getDateFormat().parse(stringValue);
} catch (ParseException f) {
throw new JsonSyntaxException(stringValue, e);
}
}
} else {
return null;
}
}
}
示例4: convertToDate
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
public static Date convertToDate(String date) {
if(date==null){
return null;
}
java.util.Date parsedate = null;
final ParsePosition parsePosition = new ParsePosition(0);
try {
parsedate = ISO8601Utils.parse(date, parsePosition);
logger.debug("Parsed Data"+parsedate);
return parsedate;
} catch (ParseException e) {
logger.error(e);
}
return parsedate;
}
示例5: getUpdatedAt
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
@Override
protected int getUpdatedAt(D d)
{
try {
Customer c = (Customer) d;
return (int) (ISO8601Utils.parse(c.getUpdatedAt(), new ParsePosition(0)).getTime() / 1000);
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}
示例6: write
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
@Override
public void write(JsonWriter out, Date date) throws IOException {
if (date == null) {
out.nullValue();
} else {
String value;
if (dateFormat != null) {
value = dateFormat.format(date);
} else {
value = ISO8601Utils.format(date, true);
}
out.value(value);
}
}
示例7: read
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
@Override
@NonNull
public Date read(final JsonReader in) throws IOException {
final String date = in.nextString();
final ParsePosition parsePosition = new ParsePosition(0);
try {
return ISO8601Utils.parse(date, parsePosition);
} catch (ParseException e) {
throw new JsonSyntaxException(date, e);
}
}
示例8: postEventFromInterceptor
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
/**
* Post the provided data by passing the appropriate headers and status code in a request chain
* through an {@link NewVersionBroadcastInterceptor}.
*
* @param interceptor The interceptor through which the data is to be posted.
* @param newVersion The new version.
* @param lastSupportedDate The last supported date.
* @param isUnsupported Whether the current version is unsupported.
* @return The posted event. This can be null if the data does not constitute a valid event.
*/
@Nullable
private static NewVersionAvailableEvent postEventFromInterceptor(
@NonNull final NewVersionBroadcastInterceptor interceptor,
@Nullable final Version newVersion,
@Nullable final Date lastSupportedDate,
final boolean isUnsupported) throws IOException {
// This will throw an AssumptionViolatedException if the Android runtime
// isn't loaded (i.e. through using the Robolectric test runner).
final EventBus eventBus = getEventBus();
eventBus.removeStickyEvent(NewVersionAvailableEvent.class);
final Interceptor.Chain chain = mock(Interceptor.Chain.class);
final Request request = new Request.Builder()
.url("https://localhost:1/")
.build();
final Response response; {
final Response.Builder responseBuilder = new Response.Builder();
responseBuilder.request(request);
responseBuilder.protocol(Protocol.HTTP_1_1);
responseBuilder.code(isUnsupported ? UPGRADE_REQUIRED : ACCEPTED);
if (newVersion != null) {
responseBuilder.header(HEADER_APP_LATEST_VERSION, newVersion.toString());
}
if (lastSupportedDate != null) {
responseBuilder.header(HEADER_APP_VERSION_LAST_SUPPORTED_DATE,
ISO8601Utils.format(lastSupportedDate, true));
}
response = responseBuilder.build();
}
when(chain.request()).thenReturn(request);
when(chain.proceed(request)).thenReturn(response);
interceptor.intercept(chain);
final InOrder inOrder = inOrder(chain);
inOrder.verify(chain).request();
inOrder.verify(chain).proceed(request);
verifyNoMoreInteractions(chain);
return eventBus.getStickyEvent(NewVersionAvailableEvent.class);
}
示例9: testGetCurrentTimeStamp
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
@Test
public void testGetCurrentTimeStamp() {
String date = DateUtil.getCurrentTimeStamp();
assertNotNull(date);
print("modification date = " + date);
// Verify that it's been formatted to an ISO 8601
// compatible format.
try {
ISO8601Utils.parse(date, new ParsePosition(0));
} catch (ParseException e) {
fail("Invalid date format: '" + date +
"' is not an ISO 8601 compliant string", e);
}
}
示例10: getGson
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
static public Gson getGson() {
class DateDeserializer implements JsonDeserializer<Date> {
private final String TAG = DateDeserializer.class.getSimpleName();
@Override
public java.util.Date deserialize(JsonElement element, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
String date = element.getAsString();
Date returnDate = null;
try {
returnDate = ISO8601Utils.parse(date, new ParsePosition(0));
} catch (ParseException | IllegalArgumentException e) {
Log.e(TAG, "Failed to parse dateString: (" + date + "), due to:", e);
}
return returnDate;
}
}
class DateSerializer implements JsonSerializer<Date> {
@Override
public JsonElement serialize(java.util.Date src, Type typeOfSrc, JsonSerializationContext context) {
String dateFormatAsString = ISO8601Utils.format(src, false, TimeZone.getTimeZone("GMT"));
return new JsonPrimitive(dateFormatAsString);
}
}
return new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
.registerTypeAdapter(Slots.class, new Slots.SlotsDeserializer())
.registerTypeAdapter(Slots.class, new Slots.SlotsSerializer())
.registerTypeAdapter(java.util.Date.class, new DateDeserializer())
.registerTypeAdapter(java.util.Date.class, new DateSerializer())
.registerTypeAdapter(UsersLTE.class, new UsersLTE.UserLTEDeserializer())
.registerTypeAdapter(Messages.UserVotes.class, new Messages.UserVotes.UserVotesDeserializer())
.registerTypeAdapter(UsersLTE.getListType(), new UsersLTE.ListUserLTEDeserializer())
// .registerTypeAdapter(ScaleTeams.class, new ScaleTeams.ScaleTeamsDeserializer())
.create();
}
示例11: write
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
@Override
public void write(@NonNull JsonWriter out, @NonNull Date date) throws IOException {
out.value(ISO8601Utils.format(date, true));
}
示例12: getCurrentTimeStamp
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
/**
* @return The current date and time in a ISO 8601 compliant format.
*/
public static String getCurrentTimeStamp(){
return ISO8601Utils.format(new Date(), true); // Find todays date
}
示例13: format
import com.google.gson.internal.bind.util.ISO8601Utils; //导入依赖的package包/类
/**
* Formats date time to ISO 8601 string.
*
* @param dateTime date time to format
* @return formatted string
*/
public static String format(DateTime dateTime) {
Calendar calendar = checkNotNull(dateTime, "dateTime").getCalendar();
return ISO8601Utils.format(calendar.getTime(), true, calendar.getTimeZone());
}