@Override public Map<String, String> getMetadata() { return singletonMap("startup", this.timestamp.format(DateTimeFormatter.ISO_DATE_TIME)); } }
DateTimeFormatter formatter = DateTimeFormatter .ofPattern("yyyy-MM-dd'T'HH:mm:ss,nnnnnnnnnZ"); OffsetDateTime odt = OffsetDateTime.of(2015, 11, 2, 12, 38, 0, 123456789, ZoneOffset.UTC); System.out.println(odt.format(formatter));
@Override public void serialize(OffsetDateTime dateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeString(dateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)); } }
public String timestamp() { if (timestamp == 0) { return "n/a"; } return Instant.ofEpochMilli(timestamp) .atOffset(ZoneOffset.UTC) .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); }
/** {@inheritDoc} */ @Override public String getStartTimeLocal() { return statMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME); }
@Override public String format(final LogRecord record) { OffsetDateTime date = fromMillis(record.getMillis()); StringBuilder sb = new StringBuilder(); // Minimize memory allocations here. sb.append("[").append(Thread.currentThread().getName()).append("] "); sb.append(date.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)).append(" "); sb.append(record.getLevel()).append(" ["); sb.append(record.getLoggerName()).append("]").append(" "); sb.append(record.getMessage()); sb.append(Utils.LINE_SEPARATOR); if (record.getThrown() != null) { try { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); record.getThrown().printStackTrace(pw); pw.close(); sb.append(sw.toString()); } catch (Exception ex) { ex.printStackTrace(); } } return sb.toString(); }
/** * Get the ISO 8601 formatted representation of the given {@link OffsetDateTime}. * * @param timestamp the timestamp value * @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no * adjustment is necessary * @return the ISO 8601 formatted string */ public static String toIsoString(OffsetDateTime timestamp, TemporalAdjuster adjuster) { if (adjuster != null) { timestamp = timestamp.with(adjuster); } return timestamp.format(FORMATTER); }
public String getStartingTimestampAsMediumString() { return startingTimestamp == null ? null : startingTimestamp.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)); }
public static String[] parseISORepeatable(String isoString) { String[] result = new String[3]; String[] elements = isoString.split("/"); if (elements.length==3) { result[0] = elements[0].substring(1); result[1] = elements[1]; result[2] = elements[2]; } else { result[0] = elements[0].substring(1); result[1] = OffsetDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME); result[2] = elements[1]; } return result; }
public void initBenchmarkReportDirectory(File benchmarkDirectory) { String timestampString = startingTimestamp.format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss")); if (StringUtils.isEmpty(name)) { name = timestampString; } if (!benchmarkDirectory.mkdirs()) { if (!benchmarkDirectory.isDirectory()) { throw new IllegalArgumentException("The benchmarkDirectory (" + benchmarkDirectory + ") already exists, but is not a directory."); } if (!benchmarkDirectory.canWrite()) { throw new IllegalArgumentException("The benchmarkDirectory (" + benchmarkDirectory + ") already exists, but is not writable."); } } int duplicationIndex = 0; do { String directoryName = timestampString + (duplicationIndex == 0 ? "" : "_" + duplicationIndex); duplicationIndex++; benchmarkReportDirectory = new File(benchmarkDirectory, BooleanUtils.isFalse(aggregation) ? directoryName : directoryName + "_aggregation"); } while (!benchmarkReportDirectory.mkdir()); for (ProblemBenchmarkResult problemBenchmarkResult : unifiedProblemBenchmarkResultList) { problemBenchmarkResult.makeDirs(); } }
/** * Applies local time zone offset to timestamp value read using specified {@code reader}. * * @param writer writer to store string representation of timestamp value * @param fieldName name of the field * @param reader document reader */ @Override protected void writeTimeStamp(MapOrListWriterImpl writer, String fieldName, DocumentReader reader) { String formattedTimestamp = Instant.ofEpochMilli(reader.getTimestampLong()) .atOffset(OffsetDateTime.now().getOffset()).format(DateUtility.UTC_FORMATTER); writeString(writer, fieldName, formattedTimestamp); } };
: Instant.EPOCH.atOffset(ZoneOffset.UTC); sb.append("; Expires=") .append(expires.format(DateTimeFormatter.RFC_1123_DATE_TIME));
@Test public void testParseDateTime() { OffsetDateTime hourAfterEpoch = OffsetDateTime.of(1970, 1, 1, 1, 0, 0, 0, ZoneOffset.UTC); long parsedMilliseconds = DateTimeUtils.parseDateTime(hourAfterEpoch.format(DateTimeFormatter.ISO_DATE_TIME)); assertEquals(HOUR_IN_MILLISECONDS, parsedMilliseconds); }
/** * Returns a prettier String-representation of a OffsetDateTime object * * @param time * The OffsetDateTime object to format * * @return The String of the formatted OffsetDateTime */ public static String getDateTimeString(OffsetDateTime time) { return time.format(dtFormatter); }
/** * Simple test JMX bean for caches IO stats. * * @throws Exception In case of failure. */ @Test public void testCacheBasic() throws Exception { IoStatisticsMetricsMXBean bean = ioStatMXBean(); IoStatisticsManager ioStatMgr = ignite.context().ioStats(); Assert.assertEquals(ioStatMgr.startTime().toEpochSecond(), bean.getStartTime()); Assert.assertEquals(ioStatMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME), bean.getStartTimeLocal()); bean.reset(); Assert.assertEquals(ioStatMgr.startTime().toEpochSecond(), bean.getStartTime()); Assert.assertEquals(ioStatMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME), bean.getStartTimeLocal()); int cnt = 100; warmUpMemmory(bean, cnt); populateCache(cnt); Long cacheLogicalReadsCnt = bean.getCacheGroupLogicalReads(DEFAULT_CACHE_NAME); Assert.assertNotNull(cacheLogicalReadsCnt); Assert.assertEquals(cnt, cacheLogicalReadsCnt.longValue()); Long cachePhysicalReadsCnt = bean.getCacheGroupPhysicalReads(DEFAULT_CACHE_NAME); Assert.assertNotNull(cachePhysicalReadsCnt); Assert.assertEquals(0, cachePhysicalReadsCnt.longValue()); String formatted = bean.getCacheGroupStatistics(DEFAULT_CACHE_NAME); Assert.assertEquals("CACHE_GROUP default [LOGICAL_READS=100, PHYSICAL_READS=0]", formatted); String unexistedStats = bean.getCacheGroupStatistics("unknownCache"); Assert.assertEquals("CACHE_GROUP unknownCache []", unexistedStats); }
@Test public void testParseRepeatableStartEndDateTime() { OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1); OffsetDateTime twoMinutesFromNow = oneMinuteFromNow.plusMinutes(1); String oneMinuteFromNowFormatted = oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME); String twoMinutesFromNowFormatted = twoMinutesFromNow.format(DateTimeFormatter.ISO_DATE_TIME); String isoString = "R5/" + oneMinuteFromNowFormatted + "/" + twoMinutesFromNowFormatted; long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString); assertEquals(5L, parsedRepeatable[0]); assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS); assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS); assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]); }
@Test public void testParseDateAsDuration() { OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1); long parsedMilliseconds = DateTimeUtils.parseDateAsDuration(oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME)); assertTrue("Parsed date as duration is bigger than " + MINUTE_IN_MILLISECONDS, parsedMilliseconds <= MINUTE_IN_MILLISECONDS); assertTrue("Parsed date as duration is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedMilliseconds, parsedMilliseconds > FIFTY_NINE_SECONDS_IN_MILLISECONDS); }
@Test public void testParseRepeatablePeriodAndEndDateTime() { OffsetDateTime twoMinutesFromNow = OffsetDateTime.now().plusMinutes(2); String twoMinutesFromNowFormatted = twoMinutesFromNow.format(DateTimeFormatter.ISO_DATE_TIME); String isoString = "R5/PT1M/" + twoMinutesFromNowFormatted; long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString); assertEquals(5L, parsedRepeatable[0]); assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS); assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS); assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]); }
@Test public void testParseRepeatableStartDateTimeAndPeriod() { OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1); String oneMinuteFromNowFormatted = oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME); String isoString = "R5/" + oneMinuteFromNowFormatted + "/PT1M"; long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString); assertEquals(5L, parsedRepeatable[0]); assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS); assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS); assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]); }