statustime: Only update when the minute changes.

This commit is contained in:
tastytea 2021-08-14 18:59:59 +02:00
parent 194212dbaa
commit 2c1484587f
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 7 additions and 2 deletions

View File

@ -13,6 +13,8 @@ int main()
{
using fmt::format;
using std::cout;
using clock = std::chrono::system_clock;
using std::chrono::minutes;
using namespace std::chrono_literals;
// Set explicitly, because LC_TIME is en_DK.UTF-8.
@ -22,12 +24,15 @@ int main()
{
while (true)
{
const auto now{clock::now()};
cout << format(R"(<b><span color="orange">{0:%A}</span></b>, )"
R"({0:%Y-%m-%d} )"
R"(<span color="lightcyan">{0:%H:%M}</span>)",
std::chrono::system_clock::now())
now)
<< std::endl; // NOTE: Don't forget that we need to flush! 😊
std::this_thread::sleep_for(1s);
const auto next_minute{std::chrono::floor<minutes>(now + 1min)};
std::this_thread::sleep_until(next_minute);
}
}
catch (const std::exception &e)