From 74c2aaca9f58277ea812d02dae1d40784fcb82ee Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Mon, 25 Dec 2023 19:30:07 +0100 Subject: [PATCH] Use ISO 8601 dates in CSV export They are more easily readable Closes #318 --- .../com/emanuelef/remote_capture/Utils.java | 22 +++++++++++++++++++ .../adapters/ConnectionsAdapter.java | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/emanuelef/remote_capture/Utils.java b/app/src/main/java/com/emanuelef/remote_capture/Utils.java index 478bc7748..c2604e35a 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/Utils.java +++ b/app/src/main/java/com/emanuelef/remote_capture/Utils.java @@ -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); diff --git a/app/src/main/java/com/emanuelef/remote_capture/adapters/ConnectionsAdapter.java b/app/src/main/java/com/emanuelef/remote_capture/adapters/ConnectionsAdapter.java index 707c64f60..a9e0c74b5 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/adapters/ConnectionsAdapter.java +++ b/app/src/main/java/com/emanuelef/remote_capture/adapters/ConnectionsAdapter.java @@ -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(",");