updates/fixes

This commit is contained in:
Mars 2024-07-31 00:07:40 -04:00
parent 3ebbb2b3ec
commit 3f4b24c259
Signed by: pupbrained
GPG key ID: 0FF5B8826803F895
5 changed files with 61 additions and 33 deletions

View file

@ -1,6 +1,8 @@
#include <ctime>
#include <fmt/chrono.h>
#include <fmt/core.h>
#include <fmt/format.h>
#include <string>
#include "config/config.h"
#include "os/os.h"
@ -12,26 +14,30 @@ struct BytesToGiB {
constexpr u64 GIB = 1'073'741'824;
template <>
struct fmt::formatter<BytesToGiB> : formatter<double> {
struct fmt::formatter<BytesToGiB> : fmt::formatter<double> {
template <typename FmtCtx>
fn format(const BytesToGiB BTG, FmtCtx& ctx) -> typename FmtCtx::iterator {
typename FmtCtx::iterator out =
formatter<double>::format(static_cast<double>(BTG.value) / GIB, ctx);
*out++ = 'G';
*out++ = 'i';
*out++ = 'B';
constexpr auto format(const BytesToGiB& BTG, FmtCtx& ctx) const -> typename FmtCtx::iterator {
auto out = fmt::formatter<double>::format(static_cast<double>(BTG.value) / GIB, ctx);
*out++ = 'G';
*out++ = 'i';
*out++ = 'B';
return out;
}
};
fn GetDate() -> string {
const std::tm localTime = fmt::localtime(time(nullptr));
fn GetDate() -> std::string {
// Get current local time
std::time_t now = std::time(nullptr);
std::tm localTime = *std::localtime(&now);
string date = fmt::format("{:%e}", localTime);
// Format the date using fmt::format
std::string date = fmt::format("{:%e}", localTime);
// Remove leading whitespace
if (!date.empty() && std::isspace(date.front()))
date.erase(date.begin());
// Append appropriate suffix for the date
if (date == "1" || date == "21" || date == "31")
date += "st";
else if (date == "2" || date == "22")
@ -41,7 +47,7 @@ fn GetDate() -> string {
else
date += "th";
return fmt::format("{:%B} {}, {:%-I:%0M %p}", localTime, date, localTime);
return fmt::format("{:%B} {}", localTime, date);
}
fn main() -> i32 {
@ -68,7 +74,7 @@ fn main() -> i32 {
fmt::println("Hello {}!", name);
fmt::println("Today is: {}", date);
fmt::println("Installed RAM: {:.2f}", BytesToGiB(memInfo));
fmt::println("{}", osVersion);
fmt::println("OS: {}", osVersion);
if (weather.enabled)
fmt::println("It is {}°F in {}", std::lround(weatherInfo.main.temp), weatherInfo.name);