Skip to content

Commit 7e88f9f

Browse files
committed
add and use getFormattedDate()
1 parent d22009b commit 7e88f9f

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogSession.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
package org.eclipse.ui.internal.views.log;
1717

1818
import java.io.PrintWriter;
19-
import java.text.ParseException;
20-
import java.text.SimpleDateFormat;
19+
import java.time.LocalDateTime;
20+
import java.time.ZoneId;
21+
import java.time.format.DateTimeFormatter;
22+
import java.time.format.DateTimeParseException;
2123
import java.util.Date;
2224

2325
/**
@@ -31,8 +33,12 @@ public class LogSession extends Group {
3133
* @since 3.5
3234
*/
3335
public static final String SESSION = "!SESSION"; //$NON-NLS-1$
36+
private static final DateTimeFormatter LOCAL_SDF = DateTimeFormatter.ofPattern(LogEntry.F_DATE_FORMAT)
37+
.withZone(ZoneId.systemDefault());
38+
3439
private String sessionData;
3540
private Date date;
41+
private String fDateString;
3642

3743
public LogSession() {
3844
super(Messages.LogViewLabelProvider_Session);
@@ -42,11 +48,24 @@ public Date getDate() {
4248
return date;
4349
}
4450

51+
/**
52+
* Returns a pretty-print formatting for the date for this entry
53+
*
54+
* @return the formatted date for this entry
55+
*/
56+
public String getFormattedDate() {
57+
if (fDateString == null) {
58+
fDateString = LOCAL_SDF.format(getDate().toInstant());
59+
}
60+
return fDateString;
61+
}
62+
4563
public void setDate(String dateString) {
46-
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$
4764
try {
48-
date = formatter.parse(dateString);
49-
} catch (ParseException e) { // do nothing
65+
LocalDateTime ldt = LocalDateTime.parse(dateString, LOCAL_SDF);
66+
this.date = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
67+
} catch (DateTimeParseException e) {
68+
// do nothing
5069
}
5170
}
5271

bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogViewLabelProvider.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*******************************************************************************/
1616
package org.eclipse.ui.internal.views.log;
1717

18-
import java.text.DateFormat;
19-
import java.text.SimpleDateFormat;
2018
import java.util.ArrayList;
2119
import org.eclipse.core.runtime.IStatus;
2220
import org.eclipse.jface.resource.JFaceResources;
@@ -35,8 +33,6 @@ public class LogViewLabelProvider extends LabelProvider implements ITableLabelPr
3533
private Image errorWithStackImage;
3634
private Image hierarchicalImage;
3735
ArrayList<Object> consumers = new ArrayList<>();
38-
private DateFormat dateFormat = new SimpleDateFormat(LogEntry.F_DATE_FORMAT);
39-
4036
private LogView logView;
4137

4238
public LogViewLabelProvider(LogView logView) {
@@ -82,7 +78,7 @@ public String getColumnText(Object element, int columnIndex) {
8278
if (session.getDate() == null)
8379
return ""; //$NON-NLS-1$
8480

85-
return dateFormat.format(session.getDate());
81+
return session.getFormattedDate();
8682
}
8783

8884
if ((element instanceof Group) && (columnIndex == 0)) {
@@ -107,7 +103,7 @@ public String getColumnText(Object element, int columnIndex) {
107103
if (entry.getPluginId() != null)
108104
return entry.getPluginId();
109105
case 2 :
110-
return dateFormat.format(entry.getDate());
106+
return entry.getFormattedDate();
111107
}
112108
}
113109

0 commit comments

Comments
 (0)