com.google.gson.internal.bind.util.ISO8601Utils Java Examples

The following examples show how to use com.google.gson.internal.bind.util.ISO8601Utils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSON.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #2
Source File: JSON.java    From eve-esi with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example #3
Source File: JSON.java    From swagger-aem with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #4
Source File: Tags.java    From intra42 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: JSON.java    From influxdb-client-java with MIT License 6 votes vote down vote up
@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);
            }
    }
}
 
Example #6
Source File: JSON.java    From swaggy-jenkins with MIT License 6 votes vote down vote up
@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);
            }
    }
}
 
Example #7
Source File: JSON.java    From director-sdk with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #8
Source File: JSON.java    From nifi-swagger-client with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #9
Source File: JSON.java    From android with MIT License 6 votes vote down vote up
@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);
            }
    }
}
 
Example #10
Source File: JSON.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #11
Source File: JSON.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #12
Source File: JSON.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #13
Source File: DateUtil.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #14
Source File: JSON.java    From huaweicloud-cs-sdk with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #15
Source File: JSON.java    From huaweicloud-cs-sdk with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #16
Source File: JSON.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #17
Source File: JSON.java    From oxd with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #18
Source File: JSON.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@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);
            }
    }
}
 
Example #19
Source File: PostBackupScript.java    From gocd with Apache License 2.0 5 votes vote down vote up
CommandLine commandLine() {
    ImmutableMap.Builder<String, String> envBuilder = new ImmutableMap.Builder<>();

    envBuilder.put("GOCD_BACKUP_TIMESTAMP", ISO8601Utils.format(backupTime));

    if (backup == null) {
        envBuilder.put("GOCD_BACKUP_STATUS", "failure");
    } else {
        envBuilder.put("GOCD_BACKUP_STATUS", "success")
                .put("GOCD_BACKUP_BASE_DIR", backupBaseDir)
                .put("GOCD_BACKUP_PATH", backup.getPath());
    }

    switch (initiatedBy) {
        case TIMER:
            envBuilder.put("GOCD_BACKUP_INITIATED_VIA", "TIMER");
            break;
        case USER:
            envBuilder.put("GOCD_BACKUP_INITIATED_BY_USER", username);
            break;
    }

    return CommandLine.createCommandLine(postBackupScript)
            .withEncoding("UTF-8")
            .withEnv(envBuilder.build());

}
 
Example #20
Source File: JSON.java    From oxd with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #21
Source File: JSON.java    From eve-esi with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #22
Source File: DateParseTests.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #23
Source File: JSON.java    From director-sdk with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #24
Source File: DefaultDateTypeAdapter.java    From gson with Apache License 2.0 5 votes vote down vote up
private Date deserializeToDate(String s) {
  synchronized (dateFormats) {
    for (DateFormat dateFormat : dateFormats) {
      try {
        return dateFormat.parse(s);
      } catch (ParseException ignored) {}
    }
    try {
      return ISO8601Utils.parse(s, new ParsePosition(0));
    } catch (ParseException e) {
      throw new JsonSyntaxException(s, e);
    }
  }
}
 
Example #25
Source File: NewVersionAvailableEventTest.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
        responseBuilder.message("");
        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);
}
 
Example #26
Source File: DateTypeAdapter.java    From gson with Apache License 2.0 5 votes vote down vote up
private synchronized Date deserializeToDate(String json) {
  for (DateFormat dateFormat : dateFormats) {
    try {
      return dateFormat.parse(json);
    } catch (ParseException ignored) {}
  }
  try {
  	return ISO8601Utils.parse(json, new ParsePosition(0));
  } catch (ParseException e) {
    throw new JsonSyntaxException(json, e);
  }
}
 
Example #27
Source File: JSON.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example #28
Source File: ISO8601DateTypeAdapter.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #29
Source File: JSON.java    From influxdb-client-java with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example #30
Source File: JSON.java    From nifi-swagger-client with Apache License 2.0 5 votes vote down vote up
@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);
    }
}