Merge pull request #2917 from GermanBluefox/patch-3
Show time string instead of ms in JSON structures
This commit is contained in:
commit
20e7020b07
|
@ -9,6 +9,9 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Date;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.text.DateFormat;
|
||||
|
||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||
|
||||
|
@ -84,6 +87,7 @@ public class JSONFormatter {
|
|||
|
||||
private String visit(final Object object, final int indent) throws JSONException {
|
||||
String ret = "";
|
||||
Long n;
|
||||
if (object instanceof JSONArray) {
|
||||
ret += visit((JSONArray) object, indent);
|
||||
} else if (object instanceof JSONObject) {
|
||||
|
@ -92,7 +96,19 @@ public class JSONFormatter {
|
|||
if (object instanceof String) {
|
||||
ret += write("\"" + ((String) object).replace("<", "<").replace(">", ">") + "\"", indent);
|
||||
} else {
|
||||
ret += write(String.valueOf(object), indent);
|
||||
// try to detect Date as milliseconds
|
||||
if (object instanceof Long) {
|
||||
n = (Long) object;
|
||||
if (n > 1580000000000L && n < 2000000000000L) { // from 2020.01.26 to 2033.05.18 it is with high probability a date object
|
||||
Date date = new Date(n);
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
ret += write(formatter.format(date), indent);
|
||||
} else {
|
||||
ret += write(String.valueOf(object), indent);
|
||||
}
|
||||
} else {
|
||||
ret += write(String.valueOf(object), indent);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -107,4 +123,4 @@ public class JSONFormatter {
|
|||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue