use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.
the class DateTimePerformance method checkJodaSetYear.
// Set year
//------------------------------------------------------------------------
private void checkJodaSetYear() {
int COUNT = COUNT_FAST;
// Is it fair to use only MutableDateTime here? You decide.
MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
for (int i = 0; i < AVERAGE; i++) {
start("Joda", "setYear");
for (int j = 0; j < COUNT; j++) {
dt.setYear(1972);
if (dt == null) {
System.out.println("Anti optimise");
}
}
end(COUNT);
}
}
use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.
the class TestReadableInstantConverter method testGetChronology_Object_nullChronology.
public void testGetChronology_Object_nullChronology() throws Exception {
assertEquals(ISO.withUTC(), ReadableInstantConverter.INSTANCE.getChronology(new Instant(123L), (Chronology) null));
assertEquals(ISO, ReadableInstantConverter.INSTANCE.getChronology(new DateTime(123L), (Chronology) null));
MutableDateTime mdt = new MutableDateTime() {
public Chronology getChronology() {
// bad
return null;
}
};
assertEquals(ISO, ReadableInstantConverter.INSTANCE.getChronology(mdt, (Chronology) null));
}
use of org.joda.time.MutableDateTime in project ddf by codice.
the class RrdMetricsRetriever method createSummary.
private void createSummary(Workbook wb, List<String> metricNames, String metricsDir, long startTime, long endTime, SUMMARY_INTERVALS summaryInterval) throws IOException, MetricsGraphException {
// convert seconds to milliseconds
startTime = TimeUnit.SECONDS.toMillis(startTime);
endTime = TimeUnit.SECONDS.toMillis(endTime);
DateTime reportStart = new DateTime(startTime, DateTimeZone.UTC);
DateTime reportEnd = new DateTime(endTime, DateTimeZone.UTC);
Sheet sheet = wb.createSheet();
wb.setSheetName(0, reportStart.toString(SUMMARY_TIMESTAMP) + " to " + reportEnd.toString(SUMMARY_TIMESTAMP));
Row headingRow = sheet.createRow(0);
int columnMax = 1;
for (String metricName : metricNames) {
MutableDateTime chunkStart = new MutableDateTime(reportStart);
MutableDateTime chunkEnd = new MutableDateTime(chunkStart);
Row row = sheet.createRow(metricNames.indexOf(metricName) + 1);
int columnCounter = 1;
Boolean isSum = null;
while (reportEnd.compareTo(chunkEnd) > 0 && columnCounter < EXCEL_MAX_COLUMNS) {
increment(chunkEnd, summaryInterval);
if (chunkEnd.isAfter(reportEnd)) {
chunkEnd.setMillis(reportEnd);
}
// offset range by one millisecond so rrd will calculate granularity correctly
chunkEnd.addMillis(-1);
MetricData metricData = getMetricData(getRrdFilename(metricsDir, metricName), TimeUnit.MILLISECONDS.toSeconds(chunkStart.getMillis()), TimeUnit.MILLISECONDS.toSeconds(chunkEnd.getMillis()));
isSum = metricData.hasTotalCount();
chunkEnd.addMillis(1);
if (headingRow.getCell(columnCounter) == null) {
Cell headingRowCell = headingRow.createCell(columnCounter);
headingRowCell.getCellStyle().setWrapText(true);
headingRowCell.setCellValue(getTimestamp(chunkStart, chunkEnd, columnCounter, summaryInterval));
}
Cell sumOrAvg = row.createCell(columnCounter);
if (isSum) {
sumOrAvg.setCellValue((double) metricData.getTotalCount());
} else {
sumOrAvg.setCellValue(cumulativeRunningAverage(metricData.getValues()));
}
chunkStart.setMillis(chunkEnd);
columnCounter++;
}
columnMax = columnCounter;
if (isSum != null) {
row.createCell(0).setCellValue(convertCamelCase(metricName) + " (" + (isSum ? "sum" : "avg") + ")");
}
}
for (int i = 0; i < columnMax; i++) {
sheet.autoSizeColumn(i);
}
}
use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.
the class TestDateTimeFormatter method testParseInto_simple.
//-----------------------------------------------------------------------
public void testParseInto_simple() {
MutableDateTime expect = null;
expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
MutableDateTime result = new MutableDateTime(0L);
assertEquals(20, g.parseInto(result, "2004-06-09T10:20:30Z", 0));
assertEquals(expect, result);
try {
g.parseInto(null, "2004-06-09T10:20:30Z", 0);
fail();
} catch (IllegalArgumentException ex) {
}
assertEquals(~0, g.parseInto(result, "ABC", 0));
assertEquals(~10, g.parseInto(result, "2004-06-09", 0));
assertEquals(~13, g.parseInto(result, "XX2004-06-09T", 2));
}
use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.
the class TestDateTimeFormatter method testParseInto_monthOnly_parseEndYear.
public void testParseInto_monthOnly_parseEndYear() {
DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
MutableDateTime result = new MutableDateTime(2004, 1, 31, 12, 20, 30, 0, TOKYO);
assertEquals(2, f.parseInto(result, "12", 0));
assertEquals(new MutableDateTime(2004, 12, 31, 12, 20, 30, 0, TOKYO), result);
}
Aggregations