Permalink
Browse files

Merge pull request #289 from LiveRamp/date_format

replace SimpleDateFormat with equivalent from joda lib
  • Loading branch information...
2 parents c61dbd7 + cc070fd commit c4c68d6eb2d826a570b19858aa240b42f0f770be @thomas-kielbus thomas-kielbus committed Jun 27, 2014
View
@@ -142,6 +142,12 @@
<version>3.2.0.RELEASE</version>
</dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>2.3</version>
+ </dependency>
+
</dependencies>
<build>
@@ -1,16 +1,17 @@
package com.liveramp.hank.monitor.notification;
-import com.liveramp.hank.monitor.notifier.Notification;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
import java.util.Date;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import com.liveramp.hank.monitor.notifier.Notification;
+
public abstract class AbstractNotification implements Notification {
private final Date date;
private static final String DATE_FORMAT = "yy/MM/dd HH:mm:ss";
- private static final DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
+ private static final DateTimeFormatter dateFormat = DateTimeFormat.forPattern(DATE_FORMAT);
public AbstractNotification() {
date = new Date();
@@ -25,6 +26,6 @@ public Date getDate() {
@Override
public final String format(NotificationFormatter formatter) {
- return dateFormat.format(date) + " " + formatCore(formatter);
+ return dateFormat.print(date.getTime()) + " " + formatCore(formatter);
}
}
@@ -1,24 +1,39 @@
package com.liveramp.hank.ui;
-import com.liveramp.hank.coordinator.*;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.UUID;
+
+import org.apache.commons.lang.StringUtils;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import com.liveramp.hank.coordinator.Domain;
+import com.liveramp.hank.coordinator.DomainAndVersion;
+import com.liveramp.hank.coordinator.DomainGroup;
+import com.liveramp.hank.coordinator.DomainVersion;
+import com.liveramp.hank.coordinator.Host;
+import com.liveramp.hank.coordinator.HostState;
+import com.liveramp.hank.coordinator.Ring;
+import com.liveramp.hank.coordinator.RingGroup;
+import com.liveramp.hank.coordinator.UpdateProgress;
+import com.liveramp.hank.coordinator.UpdateProgressAggregator;
import com.liveramp.hank.partition_server.DoublePopulationStatisticsAggregator;
import com.liveramp.hank.partition_server.FilesystemStatisticsAggregator;
import com.liveramp.hank.partition_server.RuntimeStatisticsAggregator;
import com.liveramp.hank.util.FormatUtils;
-import org.apache.commons.lang.StringUtils;
-
-import java.io.IOException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.*;
public class UiUtils {
private UiUtils() {
}
private static final int BAR_SIZE = 100;
- private static DateFormat dateFormat = new SimpleDateFormat("d MMM yyyy HH:mm:ss");
+ private static DateTimeFormatter dateFormat = DateTimeFormat.forPattern("d MMM yyyy HH:mm:ss");
public static String hostStateToClass(HostState state) throws IOException {
switch (state) {
@@ -133,7 +148,7 @@ public static String formatDomainVersionClosedAt(DomainVersion domainVersion) th
if (closedAt == null) {
return "-";
} else {
- return dateFormat.format(new Date(closedAt));
+ return dateFormat.print(closedAt);
}
}
@@ -7,9 +7,9 @@
<%@page import="com.liveramp.hank.util.*" %>
<%@page import="java.util.*" %>
<%@page import="java.text.DecimalFormat" %>
- <%@page import="java.text.SimpleDateFormat" %>
+ <%@page import="org.joda.time.format.DateTimeFormat" %>
- <%
+ <%
Coordinator coord = (Coordinator)getServletContext().getAttribute("coordinator");
RingGroup ringGroup = coord.getRingGroup(request.getParameter("g"));
Ring ring = ringGroup.getRing(Integer.parseInt(request.getParameter("r")));
@@ -139,7 +139,7 @@
<% if (upSince == null) { %>
undefined
<% } else { %>
- Started <%= new SimpleDateFormat().format(new Date(upSince)) %>
+ Started <%= DateTimeFormat.forStyle("SS").print(upSince) %>
(online for <%= FormatUtils.formatSecondsDuration((System.currentTimeMillis() - upSince) / 1000) %>)
<% } %>
</td>
@@ -14,7 +14,7 @@
<%@page import="org.apache.thrift.*" %>
<%@page import="org.apache.commons.lang.StringEscapeUtils" %>
<%@page import="java.text.DecimalFormat" %>
- <%@page import="java.text.SimpleDateFormat" %>
+ <%@page import="org.joda.time.format.DateTimeFormat" %>
<%
@@ -532,7 +532,7 @@ Collections.sort(clients, new ClientMetadataComparator());
<%= FormatUtils.formatSecondsDuration((System.currentTimeMillis() - client.get_connected_at()) / 1000) %>
</td>
<td>
- <%= new SimpleDateFormat().format(new Date(client.get_connected_at())) %>
+ <%= DateTimeFormat.forStyle("SS").print(client.get_connected_at()) %>
</td>
<td><%= client.get_type() %></td>
<td><%= client.get_version() %></td>

0 comments on commit c4c68d6

Please sign in to comment.