mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-06 09:36:08 +00:00
LibCore: Make DateTime more easily debuggable
In particular, implement operator== and AK::Formatter.
This commit is contained in:
parent
44ab11fdab
commit
e8ce0f0eba
Notes:
sideshowbarker
2024-07-17 04:41:05 +09:00
Author: https://github.com/BenWiederhake
Commit: e8ce0f0eba
Pull-request: https://github.com/SerenityOS/serenity/pull/16743
Reviewed-by: https://github.com/gmta ✅
1 changed files with 14 additions and 0 deletions
|
@ -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<>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue