private Optional<Instant> getExpiration(JsonNode expirationNode) { return Optional.ofNullable(expirationNode).map(node -> { // Convert the expirationNode string to ISO-8601 format. String expirationValue = node.asText().replaceAll("\\+0000$", "Z"); try { return DateUtils.parseIso8601Date(expirationValue); } catch (RuntimeException e) { throw new IllegalStateException("Unable to parse credentials expiration date from metadata service.", e); } }); }
private Optional<Instant> getExpiration(JsonNode expirationNode) { return Optional.ofNullable(expirationNode).map(node -> { // Convert the expirationNode string to ISO-8601 format. String expirationValue = node.asText().replaceAll("\\+0000$", "Z"); try { return DateUtils.parseIso8601Date(expirationValue); } catch (RuntimeException e) { throw new IllegalStateException("Unable to parse credentials expiration date from metadata service.", e); } }); }
@Override public Instant convert(String value, SdkField<Instant> field) { if (value == null) { return null; } TimestampFormatTrait.Format format = resolveTimestampFormat(field); switch (format) { case ISO_8601: return DateUtils.parseIso8601Date(value); case UNIX_TIMESTAMP: return safeParseDate(DateUtils::parseUnixTimestampInstant).apply(value); case UNIX_TIMESTAMP_MILLIS: return safeParseDate(DateUtils::parseUnixTimestampMillisInstant).apply(value); case RFC_822: return DateUtils.parseRfc1123Date(value); default: throw SdkClientException.create("Unrecognized timestamp format - " + format); } }
@Override public Instant convert(String value, SdkField<Instant> field) { if (value == null) { return null; } TimestampFormatTrait.Format format = resolveTimestampFormat(field); switch (format) { case ISO_8601: return DateUtils.parseIso8601Date(value); case UNIX_TIMESTAMP: return safeParseDate(DateUtils::parseUnixTimestampInstant).apply(value); case UNIX_TIMESTAMP_MILLIS: return safeParseDate(DateUtils::parseUnixTimestampMillisInstant).apply(value); case RFC_822: return DateUtils.parseRfc1123Date(value); default: throw SdkClientException.create("Unrecognized timestamp format - " + format); } }