summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2022-09-12 13:26:02 +0200
committerAndreas Kling <kling@serenityos.org>2022-12-31 23:21:17 +0100
commite8ce0f0eba162ccd6da41fc61e286a1b1527fd82 (patch)
treebacf6be7441033fe47431e7f11191f4c8667e3cb
parent44ab11fdab636bfe98a9f25b8180d7915b6c7f07 (diff)
downloadserenity-e8ce0f0eba162ccd6da41fc61e286a1b1527fd82.zip
LibCore: Make DateTime more easily debuggable
In particular, implement operator== and AK::Formatter.
-rw-r--r--Userland/Libraries/LibCore/DateTime.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/DateTime.h b/Userland/Libraries/LibCore/DateTime.h
index e605d1f1d9..3c8879034f 100644
--- a/Userland/Libraries/LibCore/DateTime.h
+++ b/Userland/Libraries/LibCore/DateTime.h
@@ -39,6 +39,7 @@ public:
static Optional<DateTime> parse(StringView format, DeprecatedString const& string);
bool operator<(DateTime const& other) const { return m_timestamp < other.m_timestamp; }
+ bool operator==(DateTime const& other) const { return m_timestamp == other.m_timestamp; }
private:
time_t m_timestamp { 0 };
@@ -52,6 +53,19 @@ private:
}
+namespace AK {
+template<>
+struct Formatter<Core::DateTime> : StandardFormatter {
+ ErrorOr<void> format(FormatBuilder& builder, Core::DateTime const& value)
+ {
+ // Can't use DateTime::to_string() here: It doesn't propagate allocation failure.
+ return builder.builder().try_appendff("{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}"sv,
+ value.year(), value.month(), value.day(),
+ value.hour(), value.minute(), value.second());
+ }
+};
+}
+
namespace IPC {
template<>