Skip to content

Commit

Permalink
savedatadialog_ui: Use fmt::localtime instead of formatting std::chro…
Browse files Browse the repository at this point in the history
…no::local_time (shadps4-emu#1574)
  • Loading branch information
squidbus authored Nov 22, 2024
1 parent c71385e commit 15d6b09
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions src/core/libraries/save_data/dialog/savedatadialog_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,6 @@
#include "imgui/imgui_std.h"
#include "savedatadialog_ui.h"

#ifdef __APPLE__
#include <date/tz.h>

// Need to make a copy of the formatter for std::chrono::local_time for use with date::local_time
template <typename Duration, typename Char>
struct fmt::formatter<date::local_time<Duration>, Char> : formatter<std::tm, Char> {
FMT_CONSTEXPR formatter() {
this->format_str_ = fmt::detail::string_literal<Char, '%', 'F', ' ', '%', 'T'>();
}

template <typename FormatContext>
auto format(date::local_time<Duration> val, FormatContext& ctx) const -> decltype(ctx.out()) {
using period = typename Duration::period;
if (period::num == 1 && period::den == 1 &&
!std::is_floating_point<typename Duration::rep>::value) {
return formatter<std::tm, Char>::format(
localtime(fmt::detail::to_time_t(date::current_zone()->to_sys(val))), ctx);
}
auto epoch = val.time_since_epoch();
auto subsecs = fmt::detail::duration_cast<Duration>(
epoch - fmt::detail::duration_cast<std::chrono::seconds>(epoch));
return formatter<std::tm, Char>::do_format(
localtime(fmt::detail::to_time_t(date::current_zone()->to_sys(val))), ctx, &subsecs);
}
};
#endif

using namespace ImGui;
using namespace Libraries::CommonDialog;
using Common::ElfInfo;
Expand Down Expand Up @@ -125,12 +98,9 @@ SaveDialogState::SaveDialogState(const OrbisSaveDataDialogParam& param) {
param_sfo.Open(param_sfo_path);

auto last_write = param_sfo.GetLastWrite();
#ifdef __APPLE__
auto t = date::zoned_time{date::current_zone(), last_write};
#else
auto t = std::chrono::zoned_time{std::chrono::current_zone(), last_write};
#endif
std::string date_str = fmt::format("{:%d %b, %Y %R}", t.get_local_time());
std::string date_str =
fmt::format("{:%d %b, %Y %R}",
fmt::localtime(std::chrono::system_clock::to_time_t(last_write)));

size_t size = Common::FS::GetDirectorySize(dir_path);
std::string size_str = SpaceSizeToString(size);
Expand Down

0 comments on commit 15d6b09

Please sign in to comment.