From 985db495bea64e8f91b7ef962e8aae1fd17a8790 Mon Sep 17 00:00:00 2001 From: david072 Date: Fri, 17 Nov 2023 19:23:43 +0100 Subject: [PATCH] LibCore/DateTime: Add helper for setting only the date from another date --- Userland/Libraries/LibCore/DateTime.cpp | 5 +++++ Userland/Libraries/LibCore/DateTime.h | 1 + 2 files changed, 6 insertions(+) diff --git a/Userland/Libraries/LibCore/DateTime.cpp b/Userland/Libraries/LibCore/DateTime.cpp index 4f4cd1c389..004251d31a 100644 --- a/Userland/Libraries/LibCore/DateTime.cpp +++ b/Userland/Libraries/LibCore/DateTime.cpp @@ -95,6 +95,11 @@ void DateTime::set_time_only(int hour, int minute, Optional second) set_time(year(), month(), day(), hour, minute, second.has_value() ? second.release_value() : this->second()); } +void DateTime::set_date(Core::DateTime const& other) +{ + set_time(other.year(), other.month(), other.day(), hour(), minute(), second()); +} + ErrorOr DateTime::to_string(StringView format) const { struct tm tm; diff --git a/Userland/Libraries/LibCore/DateTime.h b/Userland/Libraries/LibCore/DateTime.h index bee7cc1b43..63d053777b 100644 --- a/Userland/Libraries/LibCore/DateTime.h +++ b/Userland/Libraries/LibCore/DateTime.h @@ -32,6 +32,7 @@ public: 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 second = {}); + void set_date(Core::DateTime const& other); ErrorOr 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;