From 6b83360e766da19172888e6d9b66fe29b46aa5e1 Mon Sep 17 00:00:00 2001 From: Arthur Eigenbrot Date: Sat, 29 Jan 2022 11:29:57 -0700 Subject: [PATCH] Add "{m}" battery format-time option for zero-pad minutes --- man/waybar-battery.5.scd | 3 ++- src/modules/battery.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index e99ca34..1ddd4d6 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -114,9 +114,10 @@ The *battery* module displays the current capacity and state (eg. charging) of y The *battery* module allows you to define how time should be formatted via *format-time*. -The two arguments are: +The three arguments are: *{H}*: Hours *{M}*: Minutes +*{m}*: Zero-padded minutes # CUSTOM FORMATS diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 60194f0..bd8583c 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -308,7 +308,8 @@ const std::string waybar::modules::Battery::formatTimeRemaining(float hoursRemai if (config_["format-time"].isString()) { format = config_["format-time"].asString(); } - return fmt::format(format, fmt::arg("H", full_hours), fmt::arg("M", minutes)); + std::string zero_pad_minutes = fmt::format("{:02d}", minutes); + return fmt::format(format, fmt::arg("H", full_hours), fmt::arg("M", minutes), fmt::arg("m", zero_pad_minutes)); } auto waybar::modules::Battery::update() -> void {