mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
LibCore/DateTime: Add a helper for setting the time individually
This commit is contained in:
parent
8e77c72a5c
commit
251e5fb074
Notes:
sideshowbarker
2024-07-17 05:23:40 +09:00
Author: https://github.com/david072 Commit: https://github.com/SerenityOS/serenity/commit/251e5fb074 Pull-request: https://github.com/SerenityOS/serenity/pull/21976 Issue: https://github.com/SerenityOS/serenity/issues/21713 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/AtkinsSJ
2 changed files with 6 additions and 0 deletions
|
@ -90,6 +90,11 @@ void DateTime::set_time(int year, int month, int day, int hour, int minute, int
|
|||
m_second = tm.tm_sec;
|
||||
}
|
||||
|
||||
void DateTime::set_time_only(int hour, int minute, Optional<int> second)
|
||||
{
|
||||
set_time(year(), month(), day(), hour, minute, second.has_value() ? second.release_value() : this->second());
|
||||
}
|
||||
|
||||
ErrorOr<String> DateTime::to_string(StringView format) const
|
||||
{
|
||||
struct tm tm;
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
bool is_leap_year() const;
|
||||
|
||||
void set_time(int year, int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0);
|
||||
void set_time_only(int hour, int minute, Optional<int> second = {});
|
||||
ErrorOr<String> to_string(StringView format = "%Y-%m-%d %H:%M:%S"sv) const;
|
||||
ByteString to_byte_string(StringView format = "%Y-%m-%d %H:%M:%S"sv) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue