List of usage examples for org.joda.time.base AbstractInstant toString
public String toString(DateTimeFormatter formatter)
From source file:graphene.web.components.JodaTimeOutput.java
License:Apache License
private String format(Object value) { String formatted = ""; if (value != null) { // If value is an AbstractInstant - includes DateTime and // DateMidnight if (value instanceof Long) { DateTime d = new DateTime((long) value); if (style != null) { formatted = DateTimeFormat.forStyle(style).print(d); } else if (formatter != null) { formatted = d.toString(formatter); } else if (pattern != null) { formatted = DateTimeFormat.forPattern(pattern).print(d); } else { formatted = value.toString(); }// www . j a va 2 s. c o m } else if (value instanceof AbstractInstant) { AbstractInstant ai = ((AbstractInstant) value); if (style != null) { formatted = DateTimeFormat.forStyle(style).print(ai); } else if (formatter != null) { formatted = ai.toString(formatter); } else if (pattern != null) { formatted = DateTimeFormat.forPattern(pattern).print(ai); } else { formatted = value.toString(); } } // Else if value is an AbstractPartial - includes LocalDate, // LocalTime, // LocalDateTime, YearMonthDay, and TimeOfDay else if (value instanceof AbstractPartial) { AbstractPartial ap = ((AbstractPartial) value); if (style != null) { formatted = DateTimeFormat.forStyle(style).print(ap); } else if (formatter != null) { formatted = ap.toString(formatter); } else if (pattern != null) { formatted = DateTimeFormat.forPattern(pattern).print(ap); } else { formatted = value.toString(); } } // Else value is an unsupported type else { throw new IllegalArgumentException( "JodaTimeOutput received a value of the wrong type. Supported types are subclasses of AbstractInstant and AbstractPartial or instances of Long. Type found is " + value.getClass().getName() + "."); } } return formatted; }