mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 16:19:23 +00:00
LibCore: Add a primitive comparison function to DateTime
This should go away when we get the ability to parse strings to DateTime's.
This commit is contained in:
parent
3df3ab4598
commit
d051fffe25
Notes:
sideshowbarker
2024-07-19 06:55:17 +09:00
Author: https://github.com/alimpfard
Commit: d051fffe25
Pull-request: https://github.com/SerenityOS/serenity/pull/2135
Reviewed-by: https://github.com/awesomekling
2 changed files with 10 additions and 0 deletions
|
@ -280,6 +280,12 @@ String DateTime::to_string(const String& format) const
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DateTime::is_before(const String& other) const
|
||||||
|
{
|
||||||
|
auto now_string = String::format("%04d%02d%02d%02d%02d%02dZ", year(), month(), weekday(), hour(), minute(), second());
|
||||||
|
return __builtin_strcasecmp(now_string.characters(), other.characters()) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
const LogStream& operator<<(const LogStream& stream, const DateTime& value)
|
const LogStream& operator<<(const LogStream& stream, const DateTime& value)
|
||||||
{
|
{
|
||||||
return stream << value.to_string();
|
return stream << value.to_string();
|
||||||
|
|
|
@ -54,6 +54,10 @@ public:
|
||||||
static DateTime now();
|
static DateTime now();
|
||||||
static DateTime from_timestamp(time_t);
|
static DateTime from_timestamp(time_t);
|
||||||
|
|
||||||
|
// FIXME: This should be replaced with a proper comparison
|
||||||
|
// operator when we get the equivalent of strptime
|
||||||
|
bool is_before(const String&) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
time_t m_timestamp { 0 };
|
time_t m_timestamp { 0 };
|
||||||
unsigned m_year { 0 };
|
unsigned m_year { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue