mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GT-3286 - Updated usage of timestamps in the UI to be consistent
This commit is contained in:
parent
2cafb27574
commit
feaf203365
17 changed files with 130 additions and 165 deletions
|
@ -17,7 +17,6 @@ package ghidra.app.plugin.core.comments;
|
|||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextPane;
|
||||
|
@ -26,6 +25,7 @@ import javax.swing.text.*;
|
|||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.listing.CommentHistory;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.util.DateUtils;
|
||||
import ghidra.util.Msg;
|
||||
|
||||
/**
|
||||
|
@ -44,7 +44,6 @@ class CommentHistoryPanel extends JPanel {
|
|||
private StyledDocument doc;
|
||||
private JTextPane textPane;
|
||||
|
||||
private SimpleDateFormat formatter;
|
||||
private int commentType;
|
||||
|
||||
/**
|
||||
|
@ -56,7 +55,6 @@ class CommentHistoryPanel extends JPanel {
|
|||
super(new BorderLayout());
|
||||
setUpAttributes();
|
||||
this.commentType = commentType;
|
||||
formatter = new SimpleDateFormat("yyyy MMM dd hh:mm aaa");
|
||||
create();
|
||||
}
|
||||
|
||||
|
@ -105,8 +103,8 @@ class CommentHistoryPanel extends JPanel {
|
|||
doc.insertString(offset, userName, userAttrSet);
|
||||
|
||||
offset = doc.getLength();
|
||||
doc.insertString(offset, "\t" + formatter.format(history.getModificationDate()),
|
||||
dateAttrSet);
|
||||
doc.insertString(offset,
|
||||
"\t" + DateUtils.formatDateTimestamp(history.getModificationDate()), dateAttrSet);
|
||||
doc.setParagraphAttributes(offset, 1, tabAttrSet, false);
|
||||
|
||||
offset = doc.getLength();
|
||||
|
|
|
@ -15,18 +15,16 @@
|
|||
*/
|
||||
package ghidra.app.plugin.core.datamgr;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import ghidra.program.model.data.DataType;
|
||||
import ghidra.program.model.data.DataTypeManager;
|
||||
import ghidra.util.DateUtils;
|
||||
import ghidra.util.UniversalID;
|
||||
|
||||
public class DataTypeSyncInfo {
|
||||
private static DateFormat dateFormat;
|
||||
|
||||
private final DataType refDt;
|
||||
private final DataType sourceDt;
|
||||
|
@ -106,7 +104,7 @@ public class DataTypeSyncInfo {
|
|||
/**
|
||||
* Commits the data type to the source archive.
|
||||
* Call canCommit() to check the state before calling this.
|
||||
* @see canCommit()
|
||||
* @see #canCommit()
|
||||
*/
|
||||
public void commit() {
|
||||
DataTypeSynchronizer.commitAssumingTransactionsOpen(sourceDTM, refDt);
|
||||
|
@ -115,7 +113,7 @@ public class DataTypeSyncInfo {
|
|||
/**
|
||||
* Updates the data type from the one in the source archive.
|
||||
* Call canUpdate() to check the state before calling this.
|
||||
* @see canUpdate()
|
||||
* @see #canUpdate()
|
||||
*/
|
||||
public void update() {
|
||||
DataTypeSynchronizer.updateAssumingTransactionsOpen(refDt.getDataTypeManager(), sourceDt);
|
||||
|
@ -124,7 +122,7 @@ public class DataTypeSyncInfo {
|
|||
/**
|
||||
* Reverts the data type to match the one in the source archive.
|
||||
* Call canRevert() to check the state before calling this.
|
||||
* @see canRevert()
|
||||
* @see #canRevert()
|
||||
*/
|
||||
public void revert() {
|
||||
DataTypeSynchronizer.updateAssumingTransactionsOpen(refDt.getDataTypeManager(), sourceDt);
|
||||
|
@ -177,10 +175,7 @@ public class DataTypeSyncInfo {
|
|||
if (date == 0) {
|
||||
return "";
|
||||
}
|
||||
if (dateFormat == null) {
|
||||
dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
|
||||
}
|
||||
return dateFormat.format(new Date(date));
|
||||
return DateUtils.formatDateTimestamp(new Date(date));
|
||||
}
|
||||
|
||||
public DataType getRefDataType() {
|
||||
|
|
|
@ -18,7 +18,6 @@ package ghidra.app.plugin.core.label;
|
|||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -42,13 +41,14 @@ class LabelHistoryPanel extends JPanel {
|
|||
|
||||
private LabelHistoryTableModel tableModel;
|
||||
private JTable historyTable;
|
||||
private SimpleDateFormat dateFormatter;
|
||||
private LabelHistoryListener listener;
|
||||
private boolean showAddresses;
|
||||
private final Program program;
|
||||
|
||||
/**
|
||||
* Construct a new history panel.
|
||||
* Construct a new history panel
|
||||
*
|
||||
* @param program the program
|
||||
* @param list list of LabelHistory objects
|
||||
* @param listener listener that is notified when the user clicks on a
|
||||
* row in the table; null if only label history at a specific address
|
||||
|
@ -60,13 +60,9 @@ class LabelHistoryPanel extends JPanel {
|
|||
showAddresses = listener != null;
|
||||
this.listener = listener;
|
||||
|
||||
dateFormatter = new SimpleDateFormat("yyyy MMM dd hh:mm aaa");
|
||||
create(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the label history for the given address.
|
||||
*/
|
||||
void setCurrentAddress(java.util.List<LabelHistory> list) {
|
||||
tableModel = new LabelHistoryTableModel(list, true);
|
||||
}
|
||||
|
@ -91,7 +87,7 @@ class LabelHistoryPanel extends JPanel {
|
|||
TableColumn column = columnModel.getColumn(i);
|
||||
String name = (String) column.getIdentifier();
|
||||
if (name.equals(LabelHistoryTableModel.DATE)) {
|
||||
column.setCellRenderer(new GenericDateCellRenderer(dateFormatter));
|
||||
column.setCellRenderer(new GenericDateCellRenderer());
|
||||
column.setPreferredWidth(190);
|
||||
}
|
||||
else if (name.equals(LabelHistoryTableModel.LABEL)) {
|
||||
|
@ -131,8 +127,8 @@ class LabelHistoryPanel extends JPanel {
|
|||
private Font monoFont;
|
||||
|
||||
LabelCellRenderer() {
|
||||
Font defaultFont = getFont();
|
||||
monoFont = new Font("monospaced", defaultFont.getStyle(), defaultFont.getSize());
|
||||
Font f = getFont();
|
||||
monoFont = new Font("monospaced", f.getStyle(), f.getSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,8 +19,6 @@ import java.awt.*;
|
|||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.print.*;
|
||||
import java.math.BigInteger;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import docking.util.GraphicsUtils;
|
||||
|
@ -29,6 +27,7 @@ import docking.widgets.fieldpanel.LayoutModel;
|
|||
import docking.widgets.fieldpanel.internal.EmptyLayoutBackgroundColorManager;
|
||||
import docking.widgets.fieldpanel.internal.LayoutBackgroundColorManager;
|
||||
import docking.widgets.fieldpanel.internal.PaintContext;
|
||||
import ghidra.util.DateUtils;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
|
@ -60,7 +59,8 @@ public class CodeUnitPrintable implements Printable {
|
|||
}
|
||||
|
||||
public CodeUnitPrintable(LayoutModel lm, int startIndex, int endIndex, double scaleAmount,
|
||||
TaskMonitor monitor, PrintOptionsDialog pod, Book book, PrinterJob job, Date startDate) {
|
||||
TaskMonitor monitor, PrintOptionsDialog pod, Book book, PrinterJob job,
|
||||
Date startDate) {
|
||||
this.lm = lm;
|
||||
this.startIndex = startIndex;
|
||||
this.endIndex = endIndex;
|
||||
|
@ -71,14 +71,17 @@ public class CodeUnitPrintable implements Printable {
|
|||
this.job = job;
|
||||
this.startDate = startDate;
|
||||
|
||||
if (pod.getMonochrome())
|
||||
if (pod.getMonochrome()) {
|
||||
PAINT_CONTEXT.setPrintColor(Color.BLACK);
|
||||
else
|
||||
}
|
||||
else {
|
||||
PAINT_CONTEXT.setPrintColor(null);
|
||||
}
|
||||
}
|
||||
|
||||
public CodeUnitPrintable(LayoutModel lm, java.util.List<Layout> layouts, double scaleAmount,
|
||||
TaskMonitor monitor, PrintOptionsDialog pod, Book book, PrinterJob job, Date startDate) {
|
||||
TaskMonitor monitor, PrintOptionsDialog pod, Book book, PrinterJob job,
|
||||
Date startDate) {
|
||||
this.lm = lm;
|
||||
this.layouts = layouts;
|
||||
this.scaleAmount = scaleAmount;
|
||||
|
@ -88,10 +91,12 @@ public class CodeUnitPrintable implements Printable {
|
|||
this.job = job;
|
||||
this.startDate = startDate;
|
||||
|
||||
if (pod.getMonochrome())
|
||||
if (pod.getMonochrome()) {
|
||||
PAINT_CONTEXT.setPrintColor(Color.BLACK);
|
||||
else
|
||||
}
|
||||
else {
|
||||
PAINT_CONTEXT.setPrintColor(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,13 +112,12 @@ public class CodeUnitPrintable implements Printable {
|
|||
return NO_SUCH_PAGE;
|
||||
}
|
||||
|
||||
Rectangle rect =
|
||||
new Rectangle((int) pageFormat.getImageableWidth(),
|
||||
(int) pageFormat.getImageableHeight());
|
||||
if (scaleAmount < 1.0)
|
||||
rect =
|
||||
new Rectangle((int) (pageFormat.getImageableWidth() / scaleAmount),
|
||||
(int) (pageFormat.getImageableHeight() / scaleAmount));
|
||||
Rectangle rect = new Rectangle((int) pageFormat.getImageableWidth(),
|
||||
(int) pageFormat.getImageableHeight());
|
||||
if (scaleAmount < 1.0) {
|
||||
rect = new Rectangle((int) (pageFormat.getImageableWidth() / scaleAmount),
|
||||
(int) (pageFormat.getImageableHeight() / scaleAmount));
|
||||
}
|
||||
LayoutBackgroundColorManager ls =
|
||||
new EmptyLayoutBackgroundColorManager(PAINT_CONTEXT.getBackground());
|
||||
|
||||
|
@ -128,8 +132,7 @@ public class CodeUnitPrintable implements Printable {
|
|||
GraphicsUtils.drawString(null, g2, job.getJobName(), 0, metrics.getMaxAscent());
|
||||
}
|
||||
if (pod.getPrintDate()) {
|
||||
DateFormat format = new SimpleDateFormat("MM/dd/yy h:mm:ss a");
|
||||
String dateTime = format.format(startDate);
|
||||
String dateTime = DateUtils.formatDateTimestamp(startDate);
|
||||
GraphicsUtils.drawString(null, g2, dateTime, 0, (int) bottomPos);
|
||||
}
|
||||
if (pod.getPrintPageNum()) {
|
||||
|
@ -139,16 +142,19 @@ public class CodeUnitPrintable implements Printable {
|
|||
(int) bottomPos);
|
||||
}
|
||||
g2.setFont(originalFont);
|
||||
if (pod.showHeader())
|
||||
if (pod.showHeader()) {
|
||||
g2.translate(0, pod.getHeaderHeight());
|
||||
}
|
||||
|
||||
if (scaleAmount < 1.0)
|
||||
if (scaleAmount < 1.0) {
|
||||
g2.transform(AffineTransform.getScaleInstance(scaleAmount, scaleAmount));
|
||||
}
|
||||
|
||||
if (layouts != null) {
|
||||
//If no layouts, ignore blank page
|
||||
if (layouts.size() == 0)
|
||||
if (layouts.size() == 0) {
|
||||
return NO_SUCH_PAGE;
|
||||
}
|
||||
for (int i = 0; i < layouts.size(); i++) {
|
||||
Layout layout = layouts.get(i);
|
||||
try {
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
package ghidra.program.flatapi;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import ghidra.app.cmd.comments.SetCommentCmd;
|
||||
|
@ -42,7 +42,6 @@ import ghidra.program.model.util.CodeUnitInsertionException;
|
|||
import ghidra.program.util.AddressEvaluator;
|
||||
import ghidra.program.util.string.*;
|
||||
import ghidra.util.Conv;
|
||||
import ghidra.util.SystemUtilities;
|
||||
import ghidra.util.ascii.AsciiCharSetRecognizer;
|
||||
import ghidra.util.datastruct.Accumulator;
|
||||
import ghidra.util.datastruct.ListAccumulator;
|
||||
|
@ -2456,8 +2455,9 @@ public class FlatProgramAPI {
|
|||
folder.createFile(program.getName(), program, monitor);
|
||||
}
|
||||
catch (DuplicateFileException e) {
|
||||
folder.createFile(program.getName() + "_" + SystemUtilities.currentTimeStamp(), program,
|
||||
monitor);
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("dd.MMM.yyyy_HH.mm.ss");
|
||||
String time = formatter.format(new Date());
|
||||
folder.createFile(program.getName() + "_" + time, program, monitor);
|
||||
}
|
||||
finally {
|
||||
if (program == currentProgram) {
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
package docking.widgets;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import docking.widgets.table.GTableCellRenderer;
|
||||
import docking.widgets.table.GTableCellRenderingData;
|
||||
import ghidra.util.DateUtils;
|
||||
|
||||
/**
|
||||
* The JDK-provided DateRenderer does not inherit the backgrounds and such properly.
|
||||
|
@ -30,16 +30,15 @@ import docking.widgets.table.GTableCellRenderingData;
|
|||
* column does not have the correct background. This fixes that.
|
||||
*/
|
||||
public class GenericDateCellRenderer extends GTableCellRenderer {
|
||||
private DateFormat format;
|
||||
|
||||
private String toolTip;
|
||||
|
||||
public GenericDateCellRenderer(DateFormat format, String toolTip) {
|
||||
this.format = format;
|
||||
this.toolTip = toolTip;
|
||||
public GenericDateCellRenderer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public GenericDateCellRenderer(DateFormat format) {
|
||||
this(format, null);
|
||||
public GenericDateCellRenderer(String toolTip) {
|
||||
this.toolTip = toolTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,7 +46,8 @@ public class GenericDateCellRenderer extends GTableCellRenderer {
|
|||
|
||||
Date value = (Date) data.getValue();
|
||||
|
||||
GTableCellRenderingData newData = data.copyWithNewValue(format.format(value));
|
||||
GTableCellRenderingData newData =
|
||||
data.copyWithNewValue(DateUtils.formatDateTimestamp(value));
|
||||
|
||||
JComponent c = (JComponent) super.getTableCellRendererComponent(newData);
|
||||
if (toolTip != null) {
|
||||
|
|
|
@ -134,7 +134,7 @@ class DirectoryTable extends GTable implements GhidraFileChooserDirectoryModelIf
|
|||
column.setCellRenderer(new FileSizeRenderer());
|
||||
|
||||
column = columnModel.getColumn(DirectoryTableModel.TIME_COL);
|
||||
column.setCellRenderer(new GenericDateCellRenderer(GhidraFileChooser.format));
|
||||
column.setCellRenderer(new GenericDateCellRenderer());
|
||||
}
|
||||
|
||||
private void maybeSelectItem(MouseEvent e) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import javax.swing.filechooser.FileSystemView;
|
|||
import docking.widgets.DropDownSelectionTextField;
|
||||
import docking.widgets.DropDownTextFieldDataModel;
|
||||
import docking.widgets.list.GListCellRenderer;
|
||||
import ghidra.util.DateUtils;
|
||||
import ghidra.util.HTMLUtilities;
|
||||
import ghidra.util.exception.AssertException;
|
||||
|
||||
|
@ -130,7 +131,7 @@ public class FileDropDownSelectionDataModel implements DropDownTextFieldDataMode
|
|||
"<b>" + HTMLUtilities.escapeHTML(file.getName()) + "</b>" + "</td></tr>" +
|
||||
"<tr><td>Size:</td><td>" + (isDir ? "0" : file.length()) + " bytes" + "</td></tr>" +
|
||||
"<tr><td>Last modified:</td><td>" +
|
||||
GhidraFileChooser.format.format(new Date(file.lastModified())) + "</td></tr>" +
|
||||
DateUtils.formatDateTimestamp(new Date(file.lastModified())) + "</td></tr>" +
|
||||
"</table>";
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import java.awt.*;
|
|||
import java.awt.event.*;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -126,8 +125,6 @@ public class GhidraFileChooser extends DialogComponentProvider
|
|||
return null;
|
||||
}
|
||||
|
||||
static final SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm aaa");
|
||||
|
||||
/** Instruction to display only files. */
|
||||
public static final int FILES_ONLY = 0;
|
||||
/** Instruction to display only directories. */
|
||||
|
|
|
@ -24,8 +24,20 @@ import java.util.*;
|
|||
import ghidra.util.exception.AssertException;
|
||||
|
||||
public class DateUtils {
|
||||
private static final String DATEFORMAT_STR = "MM/dd/yyyy";
|
||||
private static final String TIMEFORMAT_STR = "h:mm";
|
||||
|
||||
/** Example: Oct 31, 2019 03:24 PM */
|
||||
private static final String DATE_TIME_FORMAT_STRING = "MMM dd, yyyy hh:mm aaa";
|
||||
private static final String DATE_FORMAT_STRING = "MM/dd/yyyy";
|
||||
private static final String TIME_FORMAT_STRING = "h:mm";
|
||||
|
||||
private static final ThreadLocal<SimpleDateFormat> DATE_TIME_FORMAT =
|
||||
ThreadLocal.withInitial(() -> new SimpleDateFormat(DATE_TIME_FORMAT_STRING));
|
||||
|
||||
private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT =
|
||||
ThreadLocal.withInitial(() -> new SimpleDateFormat(DATE_FORMAT_STRING));
|
||||
|
||||
private static final ThreadLocal<SimpleDateFormat> TIME_FORMAT =
|
||||
ThreadLocal.withInitial(() -> new SimpleDateFormat(TIME_FORMAT_STRING));
|
||||
|
||||
public static final long MS_PER_SEC = 1000;
|
||||
public static final long MS_PER_MIN = MS_PER_SEC * 60;
|
||||
|
@ -172,7 +184,7 @@ public class DateUtils {
|
|||
|
||||
public static Date normalizeDate(Date date) {
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT_STR);
|
||||
SimpleDateFormat sdf = DATE_FORMAT.get();
|
||||
return sdf.parse(sdf.format(date));
|
||||
}
|
||||
catch (ParseException e) {
|
||||
|
@ -201,19 +213,35 @@ public class DateUtils {
|
|||
return dayOfWeek == SATURDAY || dayOfWeek == SUNDAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the given date into a string. This is in contrast to
|
||||
* {@link #formatDateTimestamp(Date)}, which will also return the time portion of the date.
|
||||
*
|
||||
* @param date the date to format
|
||||
* @return the date string
|
||||
*/
|
||||
public static String formatDate(Date date) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT_STR);
|
||||
return sdf.format(date);
|
||||
return DATE_FORMAT.get().format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current local timezone time-of-day as an HOUR:MIN string.
|
||||
* Formats the given date into a string that contains the date and time. This is in
|
||||
* contrast to {@link #formatDate(Date)}, which only returns a date string.
|
||||
*
|
||||
* @param date the date to format
|
||||
* @return the date and time string
|
||||
*/
|
||||
public static String formatDateTimestamp(Date date) {
|
||||
return DATE_TIME_FORMAT.get().format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current local time zone time-of-day as an HOUR:MIN string.
|
||||
*
|
||||
* @return current time-of-day as "HOUR:MIN"
|
||||
*/
|
||||
public static String getTimeNow() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(TIMEFORMAT_STR);
|
||||
return sdf.format(new Date());
|
||||
return TIME_FORMAT.get().format(new Date());
|
||||
}
|
||||
|
||||
public static Date getDate(int year, int month, int day) {
|
||||
|
@ -230,7 +258,7 @@ public class DateUtils {
|
|||
int days = 0;
|
||||
while (cal.getTime().compareTo(date2) < 0) {
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
if (!DateUtils.isWeekend(cal) && !DateUtils.isHoliday(cal)) {
|
||||
if (!isWeekend(cal) && !isHoliday(cal)) {
|
||||
days++;
|
||||
}
|
||||
}
|
||||
|
@ -239,8 +267,8 @@ public class DateUtils {
|
|||
|
||||
/**
|
||||
* Formats a millisecond duration as a English string expressing the number of
|
||||
* hours, minutes and seconds in the duration.
|
||||
* <p>
|
||||
* hours, minutes and seconds in the duration
|
||||
*
|
||||
* @param millis Count of milliseconds of an elapsed duration.
|
||||
* @return String such as "5 hours, 3 mins, 22 secs".
|
||||
*/
|
||||
|
|
|
@ -15,49 +15,41 @@
|
|||
*/
|
||||
package ghidra.util;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import generic.test.AbstractGenericTest;
|
||||
public class DateUtilsTest {
|
||||
|
||||
public class DateUtilsTest extends AbstractGenericTest {
|
||||
|
||||
public DateUtilsTest() {
|
||||
// nada
|
||||
@Test
|
||||
public void testFormatDate() {
|
||||
Date date = new Date(1572896586687L);
|
||||
assertEquals("11/04/2019", DateUtils.formatDate(date));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test was moved here from DateUtils.main()
|
||||
*/
|
||||
//@Test
|
||||
public void testHolidays() {
|
||||
for (int year = 2012; year < 2020; year++) {
|
||||
List<Date> holidays = DateUtils.getHolidays(year);
|
||||
for (Date date : holidays) {
|
||||
System.out.println(DateUtils.formatDate(date));
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testFormatDateTime() {
|
||||
Date date = new Date(1572896586687L);
|
||||
assertEquals("Nov 04, 2019 02:43 PM", DateUtils.formatDateTimestamp(date));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatDuration() {
|
||||
Assert.assertEquals("0 secs", DateUtils.formatDuration(100));
|
||||
Assert.assertEquals("0 secs", DateUtils.formatDuration(DateUtils.MS_PER_SEC - 1));
|
||||
Assert.assertEquals("1 secs", DateUtils.formatDuration(DateUtils.MS_PER_SEC));
|
||||
Assert.assertEquals("1 secs", DateUtils.formatDuration(DateUtils.MS_PER_SEC + 1));
|
||||
Assert.assertEquals("59 secs", DateUtils.formatDuration(DateUtils.MS_PER_MIN - 1));
|
||||
Assert.assertEquals("1 mins, 0 secs", DateUtils.formatDuration(DateUtils.MS_PER_MIN));
|
||||
Assert.assertEquals("1 mins, 1 secs",
|
||||
assertEquals("0 secs", DateUtils.formatDuration(100));
|
||||
assertEquals("0 secs", DateUtils.formatDuration(DateUtils.MS_PER_SEC - 1));
|
||||
assertEquals("1 secs", DateUtils.formatDuration(DateUtils.MS_PER_SEC));
|
||||
assertEquals("1 secs", DateUtils.formatDuration(DateUtils.MS_PER_SEC + 1));
|
||||
assertEquals("59 secs", DateUtils.formatDuration(DateUtils.MS_PER_MIN - 1));
|
||||
assertEquals("1 mins, 0 secs", DateUtils.formatDuration(DateUtils.MS_PER_MIN));
|
||||
assertEquals("1 mins, 1 secs",
|
||||
DateUtils.formatDuration(DateUtils.MS_PER_MIN + DateUtils.MS_PER_SEC));
|
||||
Assert.assertEquals("23 hours, 59 mins, 59 secs",
|
||||
assertEquals("23 hours, 59 mins, 59 secs",
|
||||
DateUtils.formatDuration(DateUtils.MS_PER_DAY - 1));
|
||||
Assert.assertEquals("1 days, 0 hours, 0 mins, 0 secs",
|
||||
assertEquals("1 days, 0 hours, 0 mins, 0 secs",
|
||||
DateUtils.formatDuration(DateUtils.MS_PER_DAY));
|
||||
Assert.assertEquals("1 days, 0 hours, 0 mins, 0 secs",
|
||||
assertEquals("1 days, 0 hours, 0 mins, 0 secs",
|
||||
DateUtils.formatDuration(DateUtils.MS_PER_DAY + 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ package ghidra.framework.main.datatable;
|
|||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -35,8 +33,7 @@ import docking.widgets.table.threaded.*;
|
|||
import ghidra.framework.main.FrontEndPlugin;
|
||||
import ghidra.framework.model.*;
|
||||
import ghidra.framework.plugintool.PluginTool;
|
||||
import ghidra.util.HelpLocation;
|
||||
import ghidra.util.SystemUtilities;
|
||||
import ghidra.util.*;
|
||||
import ghidra.util.bean.GGlassPane;
|
||||
import ghidra.util.bean.GGlassPanePainter;
|
||||
|
||||
|
@ -117,16 +114,12 @@ public class ProjectDataTablePanel extends JPanel {
|
|||
table.dispose(); // this will dispose the gTable as well
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the help location for the data tree.
|
||||
*/
|
||||
public void setHelpLocation(HelpLocation helpLocation) {
|
||||
HelpService help = Help.getHelpService();
|
||||
help.registerHelp(table, helpLocation);
|
||||
}
|
||||
|
||||
private class DateCellRenderer extends GTableCellRenderer {
|
||||
DateFormat formatter = new SimpleDateFormat("MMM dd, yyyy HH:mm");
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(GTableCellRenderingData data) {
|
||||
|
@ -136,7 +129,7 @@ public class ProjectDataTablePanel extends JPanel {
|
|||
Object value = data.getValue();
|
||||
|
||||
if (value != null) {
|
||||
renderer.setText(formatter.format((Date) value));
|
||||
renderer.setText(DateUtils.formatDateTimestamp((Date) value));
|
||||
}
|
||||
else {
|
||||
renderer.setText("");
|
||||
|
|
|
@ -17,7 +17,6 @@ package ghidra.framework.main.datatree;
|
|||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -52,7 +51,6 @@ public class CheckoutsPanel extends JPanel {
|
|||
private DomainFile domainFile;
|
||||
private CheckoutsTableModel tableModel;
|
||||
private GTable table;
|
||||
private SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy MMM dd hh:mm aaa");
|
||||
private MyFolderListener listener;
|
||||
|
||||
private User user;
|
||||
|
@ -63,7 +61,7 @@ public class CheckoutsPanel extends JPanel {
|
|||
* @param tool tool to get project data for adding a listener
|
||||
* @param user user that is logged in
|
||||
* @param domainFile domain file to view checkouts
|
||||
* @throws IOException
|
||||
* @param checkouts the checkouts to show
|
||||
*/
|
||||
public CheckoutsPanel(Component parent, PluginTool tool, User user, DomainFile domainFile,
|
||||
ItemCheckoutStatus[] checkouts) {
|
||||
|
@ -115,8 +113,7 @@ public class CheckoutsPanel extends JPanel {
|
|||
|
||||
column = columnModel.getColumn(CheckoutsTableModel.DATE_COL);
|
||||
column.setPreferredWidth(120);
|
||||
column.setCellRenderer(
|
||||
new GenericDateCellRenderer(dateFormatter, "Date when file was checked out"));
|
||||
column.setCellRenderer(new GenericDateCellRenderer("Date when file was checked out"));
|
||||
columnModel.getColumn(CheckoutsTableModel.VERSION_COL).setPreferredWidth(50);
|
||||
columnModel.getColumn(CheckoutsTableModel.USER_COL).setPreferredWidth(80);
|
||||
columnModel.getColumn(CheckoutsTableModel.HOST_COL).setPreferredWidth(120);
|
||||
|
@ -127,8 +124,8 @@ public class CheckoutsPanel extends JPanel {
|
|||
private void terminateCheckout(int[] rows) {
|
||||
|
||||
Set<ItemCheckoutStatus> toTerminate = new HashSet<>();
|
||||
for (int i = 0; i < rows.length; i++) {
|
||||
ItemCheckoutStatus item = tableModel.getRowObject(rows[i]);
|
||||
for (int row : rows) {
|
||||
ItemCheckoutStatus item = tableModel.getRowObject(row);
|
||||
toTerminate.add(item);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ package ghidra.framework.main.datatree;
|
|||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
|
@ -38,8 +37,7 @@ import ghidra.framework.main.projectdata.actions.VersionControlUndoCheckOutActio
|
|||
import ghidra.framework.model.DomainFile;
|
||||
import ghidra.framework.model.DomainFolder;
|
||||
import ghidra.framework.plugintool.Plugin;
|
||||
import ghidra.util.HelpLocation;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.*;
|
||||
|
||||
/**
|
||||
* Dialog that shows all checkouts in a specific folder and all of its subfolders.
|
||||
|
@ -51,7 +49,6 @@ public class FindCheckoutsDialog extends DialogComponentProvider {
|
|||
private Plugin plugin;
|
||||
private DomainFolder folder;
|
||||
private JTable table;
|
||||
private SimpleDateFormat formatter;
|
||||
private VersionControlCheckInAction checkInAction;
|
||||
private VersionControlUndoCheckOutAction undoCheckOutAction;
|
||||
private boolean showMessage = true;
|
||||
|
@ -61,7 +58,6 @@ public class FindCheckoutsDialog extends DialogComponentProvider {
|
|||
super("Find Checkouts");
|
||||
this.plugin = plugin;
|
||||
this.folder = folder;
|
||||
formatter = new SimpleDateFormat("yyyy MMM dd hh:mm aaa");
|
||||
create();
|
||||
setHelpLocation(new HelpLocation("VersionControl", "Find_Checkouts"));
|
||||
}
|
||||
|
@ -165,7 +161,7 @@ public class FindCheckoutsDialog extends DialogComponentProvider {
|
|||
Object value = data.getValue();
|
||||
|
||||
if (value instanceof Date) {
|
||||
setText(formatter.format((Date) value));
|
||||
setText(DateUtils.formatDateTimestamp((Date) value));
|
||||
}
|
||||
|
||||
setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.awt.dnd.*;
|
|||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
@ -59,7 +58,6 @@ public class VersionHistoryPanel extends JPanel implements Draggable {
|
|||
private String domainFilePath;
|
||||
private VersionHistoryTableModel tableModel;
|
||||
private GTable table;
|
||||
private SimpleDateFormat formatter;
|
||||
|
||||
private DragSource dragSource;
|
||||
private DragGestureAdapter dragGestureAdapter;
|
||||
|
@ -87,7 +85,6 @@ public class VersionHistoryPanel extends JPanel implements Draggable {
|
|||
super(new BorderLayout());
|
||||
this.tool = tool;
|
||||
create();
|
||||
formatter = new SimpleDateFormat("yyyy MMM dd hh:mm aaa");
|
||||
if (enableUserInteraction) {
|
||||
setUpDragSite();
|
||||
table.addMouseListener(new MyMouseListener());
|
||||
|
@ -389,7 +386,7 @@ public class VersionHistoryPanel extends JPanel implements Draggable {
|
|||
int col = data.getColumnModelIndex();
|
||||
|
||||
if (value instanceof Date) {
|
||||
setText(formatter.format((Date) value));
|
||||
setText(DateUtils.formatDateTimestamp((Date) value));
|
||||
}
|
||||
|
||||
setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
|
||||
|
|
|
@ -75,9 +75,6 @@ class VersionHistoryTableModel extends AbstractSortedTableModel<Version> {
|
|||
return columnNames[column];
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the table model.
|
||||
*/
|
||||
void refresh(Version[] newVersions) {
|
||||
List<Version> newVersionList = new ArrayList<>();
|
||||
for (Version version : newVersions) {
|
||||
|
@ -98,7 +95,7 @@ class VersionHistoryTableModel extends AbstractSortedTableModel<Version> {
|
|||
public Object getColumnValueForRow(Version version, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case VERSION_COL:
|
||||
return new Integer(version.getVersion());
|
||||
return version.getVersion();
|
||||
case DATE_COL:
|
||||
return new Date(version.getCreateTime());
|
||||
case USER_COL:
|
||||
|
|
|
@ -19,8 +19,8 @@ import java.awt.Font;
|
|||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.Objects;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
@ -35,8 +35,6 @@ import utilities.util.reflection.ReflectionUtilities;
|
|||
*/
|
||||
public class SystemUtilities {
|
||||
|
||||
private final static String DATE_TIME_FORMAT = "MMM d yyyy HH:mm:ss";
|
||||
|
||||
private static String userName;
|
||||
|
||||
/**
|
||||
|
@ -168,32 +166,6 @@ public class SystemUtilities {
|
|||
return font.deriveFont((float) FONT_SIZE_OVERRIDE_VALUE.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the current date/time using default DATE/TIME format
|
||||
* @return the current date/time using default DATE/TIME format
|
||||
*/
|
||||
public static String getDateTime() {
|
||||
return getDateTime(DATE_TIME_FORMAT);
|
||||
}
|
||||
|
||||
public static String currentTimeStamp() {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("dd.MMM.yyyy_HH.mm.ss");
|
||||
return formatter.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the current date/time using specified DATE/TIME format
|
||||
*
|
||||
* @param dateTimeFormat the format for the time
|
||||
* @return the formatted date
|
||||
*/
|
||||
public static String getDateTime(String dateTimeFormat) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat(dateTimeFormat, Locale.getDefault());
|
||||
formatter.setTimeZone(TimeZone.getDefault());
|
||||
|
||||
return formatter.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the system is running during a test.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue