Skip to content

Commit

Permalink
Use ISO 8601 dates in CSV export
Browse files Browse the repository at this point in the history
They are more easily readable

Closes #318
  • Loading branch information
emanuele-f committed Dec 25, 2023
1 parent e0112ea commit 74c2aac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/com/emanuelef/remote_capture/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,28 @@ public static String formatEpochFull(Context context, long epoch) {
return fmt.format(new Date(epoch * 1000));
}

public static String formatMillisIso8601(Context context, long millis) {
Locale locale = getPrimaryLocale(context);

String pattern;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
else
pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";

DateFormat fmt = new SimpleDateFormat(pattern, locale);
String rv = fmt.format(new Date(millis));

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N) {
// convert RFC 822 (+0100) -> ISO 8601 timezone (+01:00)
int l = rv.length();
if ((l > 5) && (rv.charAt(l - 5) == '+'))
rv = rv.substring(0, l - 2) + ":" + rv.substring(l - 2);
}

return rv;
}

public static String formatEpochMillis(Context context, long millis) {
Locale locale = getPrimaryLocale(context);
DateFormat fmt = new SimpleDateFormat("MM/dd/yy HH:mm:ss.SSS", locale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ public String dumpConnectionsCsv() {
builder.append(conn.rcvd_bytes); builder.append(",");
builder.append(conn.sent_pkts); builder.append(",");
builder.append(conn.rcvd_pkts); builder.append(",");
builder.append(conn.first_seen); builder.append(",");
builder.append(conn.last_seen);
builder.append(Utils.formatMillisIso8601(mContext, conn.first_seen)); builder.append(",");
builder.append(Utils.formatMillisIso8601(mContext, conn.last_seen));

if(malwareDetection) {
builder.append(",");
Expand Down

0 comments on commit 74c2aac

Please sign in to comment.