Deprecate joda-time
- ref:
http://blog.joda.org/2014/11/converting-from-joda-time-to-javatime.html
Change-Id: I1115e8053f601e78cb933ccbfa664ff8787d2da1
diff --git a/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java b/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java
index f2dba03..adf8ead 100644
--- a/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java
+++ b/core/api/src/main/java/org/onosproject/ui/table/cell/TimeFormatter.java
@@ -16,13 +16,21 @@
package org.onosproject.ui.table.cell;
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.format.DateTimeFormat;
-import org.joda.time.format.DateTimeFormatter;
+import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
+import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
+import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
+
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.temporal.ChronoField;
+import java.time.temporal.TemporalAccessor;
import java.util.Locale;
+import org.joda.time.DateTimeZone;
+
/**
* Formats time values using {@link DateTimeFormatter}.
*/
@@ -38,7 +46,19 @@
* Constructs a time formatter that uses the default locale and timezone.
*/
public TimeFormatter() {
- dtf = DateTimeFormat.longTime();
+ dtf = new DateTimeFormatterBuilder()
+ .appendValue(CLOCK_HOUR_OF_AMPM)
+ .appendLiteral(':')
+ .appendValue(MINUTE_OF_HOUR, 2)
+ .optionalStart()
+ .appendLiteral(':')
+ .appendValue(SECOND_OF_MINUTE, 2)
+ .appendLiteral(' ')
+ .appendText(ChronoField.AMPM_OF_DAY)
+ .optionalStart()
+ .appendLiteral(' ')
+ .appendOffset("+HH:MM", "+00:00")
+ .toFormatter();
}
/**
@@ -58,14 +78,33 @@
* @param zone time zone to use
* @return self, for chaining
*/
- public TimeFormatter withZone(DateTimeZone zone) {
+ public TimeFormatter withZone(ZoneId zone) {
dtf = dtf.withZone(zone);
return this;
}
+ /**
+ * Sets the time zone to use for formatting the time.
+ *
+ * @param zone time zone to use
+ * @return self, for chaining
+ *
+ * @deprecated in 1.12.0
+ */
+ @Deprecated
+ public TimeFormatter withZone(DateTimeZone zone) {
+ return withZone(zone.toTimeZone().toZoneId());
+ }
+
@Override
protected String nonNullFormat(Object value) {
- return dtf.print((DateTime) value);
+ if (value instanceof TemporalAccessor) {
+ return dtf.format((TemporalAccessor) value);
+ } else if (value instanceof org.joda.time.DateTime) {
+ return dtf.format(Instant.ofEpochMilli(((org.joda.time.DateTime) value).getMillis()));
+ }
+ // should never reach here
+ return String.valueOf(value);
}
}