Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

LSC readout Time to empty/full with seconds/mins/days/years #86

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -928,18 +928,16 @@ public String[] getInfoData() {
if (avgIn > avgOut) {
// Calculate time to full if charging
if (avgIn != 0) {
double timeToFull = (capacity.longValue() - stored.longValue()) / avgIn / 60;
ll.add("Time to Full: " + nf.format(timeToFull) + " minutes");
} else {
ll.add("Completely full");
double timeToFull = (capacity.longValue() - stored.longValue()) / avgIn;
String timeToFullString = formatTime(timeToFull);
ll.add("Time to Full: " + timeToFullString);
}
} else {
// Calculate time to empty if discharging
if (avgOut != 0) {
double timeToEmpty = stored.longValue() / avgOut / 60;
ll.add("Time to Empty: " + nf.format(timeToEmpty) + " minutes");
} else {
ll.add("Completely empty");
double timeToEmpty = stored.longValue() / avgOut;
String timeToEmptyString = formatTime(timeToEmpty);
ll.add("Time to Empty: " + timeToEmptyString);
}
}
ll.add(
Expand Down Expand Up @@ -982,6 +980,23 @@ public String[] getInfoData() {
return ll.toArray(a);
}

// Method to format time in seconds, minutes, days, and years
private String formatTime(double time) {
if (time < 1) {
return "Completely " + (time < 0 ? "empty" : "full");
} else if (time < 60) {
return String.format("%.2f seconds", time);
} else if (time < 3600) {
return String.format("%.2f minutes", time / 60);
} else if (time < 86400) {
return String.format("%.2f hours", time / 3600);
} else if (time < 31536000) {
return String.format("%.2f days", time / 86400);
} else {
return String.format("%.2f years", time / 31536000);
}
}

@Override
public void saveNBTData(NBTTagCompound nbt) {
nbt = (nbt == null) ? new NBTTagCompound() : nbt;
Expand Down