MCPcopy Create free account
hub / github.com/Alexays/Waybar / formatTimeRemaining

Method formatTimeRemaining

src/modules/battery.cpp:660–675  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

658}
659
660const std::string waybar::modules::Battery::formatTimeRemaining(float hoursRemaining) {
661 hoursRemaining = std::fabs(hoursRemaining);
662 uint16_t full_hours = static_cast<uint16_t>(hoursRemaining);
663 uint16_t minutes = static_cast<uint16_t>(60 * (hoursRemaining - full_hours));
664 auto format = std::string("{H} h {M} min");
665 if (full_hours == 0 && minutes == 0) {
666 // Migh as well not show "0h 0min"
667 return "";
668 }
669 if (config_["format-time"].isString()) {
670 format = config_["format-time"].asString();
671 }
672 std::string zero_pad_minutes = fmt::format("{:02d}", minutes);
673 return fmt::format(fmt::runtime(format), fmt::arg("H", full_hours), fmt::arg("M", minutes),
674 fmt::arg("m", zero_pad_minutes));
675}
676
677auto waybar::modules::Battery::update() -> void {
678#if defined(__linux__)

Callers

nothing calls this directly

Calls 1

formatFunction · 0.85

Tested by

no test coverage detected