Search in sources :

Example 11 with MutableDateTime

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);
    }
}
Also used : MutableDateTime(org.joda.time.MutableDateTime)

Example 12 with MutableDateTime

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));
}
Also used : ReadableInstant(org.joda.time.ReadableInstant) Instant(org.joda.time.Instant) MutableDateTime(org.joda.time.MutableDateTime) Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology) JulianChronology(org.joda.time.chrono.JulianChronology) DateTime(org.joda.time.DateTime) MutableDateTime(org.joda.time.MutableDateTime)

Example 13 with MutableDateTime

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);
    }
}
Also used : MutableDateTime(org.joda.time.MutableDateTime) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) DateTime(org.joda.time.DateTime) MutableDateTime(org.joda.time.MutableDateTime)

Example 14 with MutableDateTime

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));
}
Also used : MutableDateTime(org.joda.time.MutableDateTime)

Example 15 with MutableDateTime

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);
}
Also used : MutableDateTime(org.joda.time.MutableDateTime)

Aggregations

MutableDateTime (org.joda.time.MutableDateTime)76 DateTime (org.joda.time.DateTime)12 Instant (org.joda.time.Instant)6 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)6 Date (java.util.Date)5 Chronology (org.joda.time.Chronology)4 DateTimeZone (org.joda.time.DateTimeZone)4 ISOChronology (org.joda.time.chrono.ISOChronology)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)3 SlidingWindows (org.apache.beam.sdk.transforms.windowing.SlidingWindows)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 KV (org.apache.beam.sdk.values.KV)2 TimestampedValue (org.apache.beam.sdk.values.TimestampedValue)2 Duration (org.joda.time.Duration)2 Category (org.junit.experimental.categories.Category)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1