Format commit timestamp in local time

This commit is contained in:
Melledy
2023-12-16 01:29:19 -08:00
parent 1afb594fdc
commit 2b5141882e
2 changed files with 18 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
package emu.lunarcore;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import emu.lunarcore.plugin.PluginManager;
import org.jline.reader.EndOfFileException;
@@ -210,26 +212,33 @@ public class LunarCore {
} catch (Exception e) {
// Ignored
}
return "";
}
private static String getGitHash() {
// Use a string builder in case one of the build config fields are missing
StringBuilder builder = new StringBuilder();
// Safely get the build config class without errors even if it hasnt been generated yet
try {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Class<?> buildConfig = Class.forName(LunarCore.class.getPackageName() + ".BuildConfig");
String hash = buildConfig.getField("GIT_HASH").get(null).toString();
String date = buildConfig.getField("GIT_HASH_TIME").get(null).toString();
builder.append(hash);
if (date == null || date.isEmpty()) {
return hash;
}
return hash + " (" + date + ")";
long timestamp = buildConfig.getField("COMMIT_TIMESTAMP").getLong(null);
builder.append(" (" + sf.format(new Date(timestamp * 1000)) + ")");
} catch (Exception e) {
// Ignored
}
return "Unknown";
if (builder.isEmpty()) {
return "Unknown";
} else {
return builder.toString();
}
}
// Server console