Skip to content

Commit

Permalink
fix(date): convert timestamp in format date
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Del Pino <idelpino@teclib.com>
  • Loading branch information
Ivan Del Pino authored and ajsb85 committed Oct 5, 2018
1 parent b0a50f3 commit 6b5b3c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 14 additions & 1 deletion inventory/src/main/java/org/flyve/inventory/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Scanner;

Expand Down Expand Up @@ -369,6 +372,17 @@ private static String removeBracket(String str) {
return str.replaceAll("\\[", "").replaceAll("]", "");
}

/** Convert timestamp in a formatted date pattern
* @param time timestamp
* @param pattern string value
* @return converted time
*/
public static String convertTime(long time, String pattern){
Date date = new Date(time);
Format format = new SimpleDateFormat(pattern, Locale.getDefault());
return format.format(date);
}

public static String loadJSONFromAsset(Context context, String name) {
String json;
try {
Expand All @@ -385,7 +399,6 @@ public static String loadJSONFromAsset(Context context, String name) {
return json;
}


/* Checks if external storage is available for read and write */
private static boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import org.flyve.inventory.CommonErrorType;
import org.flyve.inventory.FlyveLog;
import org.flyve.inventory.Utils;

import java.io.File;
import java.util.List;
Expand Down Expand Up @@ -154,7 +155,7 @@ public String getInstallDate(ApplicationInfo p) {

try {
PackageInfo pi = packageManager.getPackageInfo(p.packageName, PackageManager.GET_META_DATA);
mInstalled = String.valueOf(pi.firstInstallTime);
mInstalled = Utils.convertTime(pi.firstInstallTime, "dd/MM/yyyy");
} catch (Exception ex) {
FlyveLog.e(FlyveLog.getMessage(context, CommonErrorType.SOFTWARE_INSTALL_DATE, ex.getMessage()));
}
Expand Down

0 comments on commit 6b5b3c5

Please sign in to comment.