/** * Convert the provided unixtimestamp (miliseconds since midnight, January 1, 1970 UTC) to an ISO8601 string. Use the fallback timestamp if the provided * timestamp is null. * * @param timestampInMs * @param fallback * @return */ public static String toISO8601(Long timestampInMs, long fallback) { long time = timestampInMs == null ? fallback : timestampInMs; return toISO8601(time); }
/** * Check whether the date can be parsed. * * @param dateString * @return */ public static boolean isDate(String dateString) { Long date = fromISO8601(dateString); return date != null; }
public JsonObjectAssert pathIsDate(String path, String msg) { if (msg == null) { msg = ""; } String value = JsonPath.read(actual.toString(), path); assertNotNull("Value on path {" + path + "} was null", value); assertTrue("The specified value {" + value + "} on path {" + path + "} was no date: " + msg, DateUtils.isDate(value)); return this; }
/** * Return the stop date of the job. * * @return */ default String getStopDate() { Long timestamp = getStopTimestamp(); if (timestamp == null) { return null; } return DateUtils.toISO8601(timestamp); }
public static Long fromISO8601(String dateString) { return fromISO8601(dateString, false); }
/** * Return the API token issue date. * * @return ISO8601 formatted date or null if the date has not yet been set */ default String getAPITokenIssueDate() { Long timestamp = getAPITokenIssueTimestamp(); if (timestamp == null) { return null; } return DateUtils.toISO8601(timestamp, System.currentTimeMillis()); }
@Test public void testDate() { assertNotNull(DateUtils.fromISO8601("2017-07-25T12:40:00Z")); assertNotNull(DateUtils.fromISO8601("2017-07-25T12:40:00+00:00")); assertNotNull(DateUtils.fromISO8601("2017-07-25T12:40:00+01:00")); assertNotNull(DateUtils.fromISO8601("2017-07-25T12:40:00")); assertNull(DateUtils.fromISO8601("Bogus")); assertNull(DateUtils.fromISO8601("0")); assertNull(DateUtils.fromISO8601("1")); assertNull(DateUtils.fromISO8601("42")); } }
/** * Return the ISO 8601 formatted creation date. * * @return */ default String getCreationDate() { return DateUtils.toISO8601(getCreationTimestamp(), 0); }
/** * Return the start date of the job. * * @return */ default String getStartDate() { Long timestamp = getStartTimestamp(); if (timestamp == null) { return null; } return DateUtils.toISO8601(timestamp); }
/** * Return the ISO8601 formatted edited date. * * @return */ default String getLastEditedDate() { return DateUtils.toISO8601(getLastEditedTimestamp(), 0); }
instanceInfo.setStatus(m.field("status")); Date date = m.field("startedOn"); instanceInfo.setStartDate(DateUtils.toISO8601(date.getTime()));
return null; return dateList.getList().stream().map(item -> DateUtils.toISO8601(item.getDate(), 0)).collect(Collectors.toList()); case "node": NodeGraphFieldList nodeList = container.getNodeList(schema.getName());
public GraphQLFieldDefinition createDateDef(FieldSchema schema) { return newFieldDefinition().name(schema.getName()).description(schema.getLabel()).type(GraphQLString).dataFetcher(env -> { GraphFieldContainer container = env.getSource(); DateGraphField dateField = container.getDate(schema.getName()); if (dateField != null) { return DateUtils.toISO8601(dateField.getDate(), 0); } return null; }).build(); }