[Help] Battery charge/discharge time formatting (e.g. "9h 23m")

Hi everyone! I’m trying to customize a battery status display on my KWGT widget and need help formatting the charging/discharging time.

KWGT provides this formula:

$if(bi(charging) = 0, Discharged, Full)$ $if(bi(charging) = 0 | bi(level) < 100, " in " + tf(bi(fullempty) - dp()))$

It works functionally, but the result looks like:
“Discharged in 9 hours”
What I really need is a more compact format like:
“9h 23m” — without any extra words.

I want it to dynamically adapt too — for example, if hours = 0, only show minutes, and vice versa.

Any idea how I can achieve this with KWGT formulas?

Thanks in advance!

Hi there,

Try this code snippet:

$if(
  bi(charging)=0,Discharged,Full
)$$if(
  bi(charging)=0 | bi(level)<100,
  " in " + if(
    tf(bi(fullempty)-dp(),"h")>0,
    tf(bi(fullempty)-dp(),"h'h' ")
  ) + if(
    tf(bi(fullempty)-dp(),"m")>0,
    tf(bi(fullempty)-dp(),"m'm'")
  )
)$

I hope this would help.

Should you found in any replies a solution to your issue, please kindly mark it as the Solution. This would help others with the similar issue.
:smiling_face::+1:

3 Likes