Search in sources :

Example 66 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project joda-time by JodaOrg.

the class Partial method toString.

//-----------------------------------------------------------------------
/**
     * Output the date in an appropriate ISO8601 format.
     * <p>
     * This method will output the partial in one of two ways.
     * If {@link #getFormatter()}
     * <p>
     * If there is no appropriate ISO format a dump of the fields is output
     * via {@link #toStringList()}.
     * 
     * @return ISO8601 formatted string
     */
public String toString() {
    DateTimeFormatter[] f = iFormatter;
    if (f == null) {
        getFormatter();
        f = iFormatter;
        if (f == null) {
            return toStringList();
        }
    }
    DateTimeFormatter f1 = f[1];
    if (f1 == null) {
        return toStringList();
    }
    return f1.print(this);
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 67 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project joda-time by JodaOrg.

the class TestConverterManager method testGetPartialConverterBadMultipleMatches.

public void testGetPartialConverterBadMultipleMatches() {
    PartialConverter c = new PartialConverter() {

        public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono) {
            return null;
        }

        public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono, DateTimeFormatter parser) {
            return null;
        }

        public Chronology getChronology(Object object, DateTimeZone zone) {
            return null;
        }

        public Chronology getChronology(Object object, Chronology chrono) {
            return null;
        }

        public Class getSupportedType() {
            return Serializable.class;
        }
    };
    try {
        ConverterManager.getInstance().addPartialConverter(c);
        try {
            ConverterManager.getInstance().getPartialConverter(new DateTime());
            fail();
        } catch (IllegalStateException ex) {
        // Serializable and ReadablePartial both match, so cannot pick
        }
    } finally {
        ConverterManager.getInstance().removePartialConverter(c);
    }
    assertEquals(PARTIAL_SIZE, ConverterManager.getInstance().getPartialConverters().length);
}
Also used : Serializable(java.io.Serializable) ReadablePartial(org.joda.time.ReadablePartial) Chronology(org.joda.time.Chronology) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) ReadableDateTime(org.joda.time.ReadableDateTime)

Example 68 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project joda-time by JodaOrg.

the class TestConverterManager method testGetPartialConverterOKMultipleMatches.

public void testGetPartialConverterOKMultipleMatches() {
    PartialConverter c = new PartialConverter() {

        public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono) {
            return null;
        }

        public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono, DateTimeFormatter parser) {
            return null;
        }

        public Chronology getChronology(Object object, DateTimeZone zone) {
            return null;
        }

        public Chronology getChronology(Object object, Chronology chrono) {
            return null;
        }

        public Class getSupportedType() {
            return ReadableDateTime.class;
        }
    };
    try {
        ConverterManager.getInstance().addPartialConverter(c);
        PartialConverter ok = ConverterManager.getInstance().getPartialConverter(new DateTime());
        // ReadableDateTime and ReadablePartial both match, but RI discarded as less specific
        assertEquals(ReadableDateTime.class, ok.getSupportedType());
    } finally {
        ConverterManager.getInstance().removePartialConverter(c);
    }
    assertEquals(PARTIAL_SIZE, ConverterManager.getInstance().getPartialConverters().length);
}
Also used : ReadablePartial(org.joda.time.ReadablePartial) ReadableDateTime(org.joda.time.ReadableDateTime) Chronology(org.joda.time.Chronology) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) ReadableDateTime(org.joda.time.ReadableDateTime)

Example 69 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project helios by spotify.

the class JobHistoryCommand method run.

@Override
int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException {
    final String jobIdString = options.getString(jobIdArg.getDest());
    final Map<JobId, Job> jobs = client.jobs(jobIdString).get();
    if (jobs.size() == 0) {
        out.printf("Unknown job: %s%n", jobIdString);
        return 1;
    } else if (jobs.size() > 1) {
        out.printf("Ambiguous job id: %s%n", jobIdString);
        return 1;
    }
    final JobId jobId = getLast(jobs.keySet());
    final TaskStatusEvents result = client.jobHistory(jobId).get();
    if (json) {
        out.println(Json.asPrettyStringUnchecked(result));
        return 0;
    }
    final Table table = table(out);
    table.row("HOST", "TIMESTAMP", "STATE", "THROTTLED", "CONTAINERID");
    final List<TaskStatusEvent> events = result.getEvents();
    final DateTimeFormatter format = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss.SSS");
    for (final TaskStatusEvent event : events) {
        final String host = checkNotNull(event.getHost());
        final long timestamp = checkNotNull(event.getTimestamp());
        final TaskStatus status = checkNotNull(event.getStatus());
        final State state = checkNotNull(status.getState());
        String containerId = status.getContainerId();
        containerId = containerId == null ? "<none>" : containerId;
        table.row(host, format.print(timestamp), state, status.getThrottled(), containerId);
    }
    table.print();
    return 0;
}
Also used : TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) Table(com.spotify.helios.cli.Table) State(com.spotify.helios.common.descriptors.TaskStatus.State) TaskStatusEvents(com.spotify.helios.common.protocol.TaskStatusEvents) Job(com.spotify.helios.common.descriptors.Job) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) JobId(com.spotify.helios.common.descriptors.JobId)

Example 70 with DateTimeFormatter

use of org.joda.time.format.DateTimeFormatter in project spring-framework by spring-projects.

the class DateTimeFormatterFactoryTests method createDateTimeFormatterWithFallback.

@Test
public void createDateTimeFormatterWithFallback() throws Exception {
    DateTimeFormatter fallback = DateTimeFormat.forStyle("LL");
    DateTimeFormatter formatter = factory.createDateTimeFormatter(fallback);
    assertThat(formatter, is(sameInstance(fallback)));
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Test(org.junit.Test)

Aggregations

DateTimeFormatter (org.joda.time.format.DateTimeFormatter)209 DateTime (org.joda.time.DateTime)95 Date (java.util.Date)40 Test (org.junit.Test)25 DateTimeZone (org.joda.time.DateTimeZone)19 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 SolrInputDocument (org.apache.solr.common.SolrInputDocument)12 IndexSchema (org.apache.solr.schema.IndexSchema)12 DateTimeFormatterBuilder (org.joda.time.format.DateTimeFormatterBuilder)12 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)10 IOException (java.io.IOException)9 Calendar (java.util.Calendar)8 Map (java.util.Map)8 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)7 FormatDateTimeFormatter (org.elasticsearch.common.joda.FormatDateTimeFormatter)7 Test (org.testng.annotations.Test)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 FilterType (net.opengis.filter.v_1_1_0.FilterType)6 Deployment (org.activiti.engine.test.Deployment)6