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);
}
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);
}
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);
}
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;
}
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)));
}
Aggregations