Everywhere: Replace DateTime::to_string() with UnixDateTime::to_string()

Replace LibCore::DateTime::to_string() with
AK::UnixDateTime::to_string().
Remove unncessary #include <LibCore/DateTime.h>.
This commit is contained in:
Tomasz Strejczek 2025-06-19 21:05:42 +02:00 committed by Andrew Kaster
parent 8f8e51b1fc
commit 6fb2be96bf
Notes: github-actions[bot] 2025-06-20 00:44:11 +00:00
13 changed files with 25 additions and 30 deletions

View file

@ -7,7 +7,6 @@
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <AK/IPv4Address.h> #include <AK/IPv4Address.h>
#include <LibCore/DateTime.h>
#include <LibCrypto/ASN1/ASN1.h> #include <LibCrypto/ASN1/ASN1.h>
#include <LibCrypto/ASN1/DER.h> #include <LibCrypto/ASN1/DER.h>
#include <LibCrypto/Certificate/Certificate.h> #include <LibCrypto/Certificate/Certificate.h>

View file

@ -15,7 +15,7 @@
#include <AK/Random.h> #include <AK/Random.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/TemporaryChange.h> #include <AK/TemporaryChange.h>
#include <LibCore/DateTime.h> #include <AK/Time.h>
#include <LibCore/Promise.h> #include <LibCore/Promise.h>
#include <LibCore/Socket.h> #include <LibCore/Socket.h>
#include <LibCore/Timer.h> #include <LibCore/Timer.h>
@ -83,7 +83,7 @@ public:
if (!m_valid) if (!m_valid)
return; return;
auto now = Core::DateTime::now(); auto now = AK::UnixDateTime::now();
for (size_t i = 0; i < m_cached_records.size();) { for (size_t i = 0; i < m_cached_records.size();) {
auto& record = m_cached_records[i]; auto& record = m_cached_records[i];
if (record.expiration.has_value() && record.expiration.value() < now) { if (record.expiration.has_value() && record.expiration.value() < now) {
@ -103,7 +103,7 @@ public:
void add_record(Messages::ResourceRecord record) void add_record(Messages::ResourceRecord record)
{ {
m_valid = true; m_valid = true;
auto expiration = record.ttl > 0 ? Optional<Core::DateTime>(Core::DateTime::from_timestamp(Core::DateTime::now().timestamp() + record.ttl)) : OptionalNone(); auto expiration = record.ttl > 0 ? Optional<AK::UnixDateTime>(AK::UnixDateTime::now() + AK::Duration::from_seconds(record.ttl)) : OptionalNone();
m_cached_records.append({ move(record), move(expiration) }); m_cached_records.append({ move(record), move(expiration) });
} }
@ -186,7 +186,7 @@ private:
struct RecordWithExpiration { struct RecordWithExpiration {
Messages::ResourceRecord record; Messages::ResourceRecord record;
Optional<Core::DateTime> expiration; Optional<AK::UnixDateTime> expiration;
}; };
Vector<RecordWithExpiration> m_cached_records; Vector<RecordWithExpiration> m_cached_records;

View file

@ -9,7 +9,6 @@
*/ */
#include <AK/Time.h> #include <AK/Time.h>
#include <LibCore/DateTime.h>
#include <LibJS/Runtime/AbstractOperations.h> #include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Date.h> #include <LibJS/Runtime/Date.h>
#include <LibJS/Runtime/DateConstructor.h> #include <LibJS/Runtime/DateConstructor.h>

View file

@ -11,7 +11,6 @@
#include <AK/DateConstants.h> #include <AK/DateConstants.h>
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/TypeCasts.h> #include <AK/TypeCasts.h>
#include <LibCore/DateTime.h>
#include <LibCrypto/BigInt/UnsignedBigInteger.h> #include <LibCrypto/BigInt/UnsignedBigInteger.h>
#include <LibJS/Runtime/AbstractOperations.h> #include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/BigInt.h> #include <LibJS/Runtime/BigInt.h>

View file

@ -6,7 +6,6 @@
*/ */
#include "Cookie.h" #include "Cookie.h"
#include <LibCore/DateTime.h>
#include <LibIPC/Decoder.h> #include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h> #include <LibIPC/Encoder.h>
@ -14,9 +13,7 @@ namespace Web::Cookie {
static String time_to_string(UnixDateTime const& time) static String time_to_string(UnixDateTime const& time)
{ {
// FIXME: This roundabout formatting should not be necessary; it also loses precision. return MUST(time.to_string("%Y-%m-%d %H:%M:%S %Z"sv));
auto local_time = Core::DateTime::from_timestamp(time.seconds_since_epoch());
return MUST(local_time.to_string("%Y-%m-%d %H:%M:%S %Z"sv));
} }
String Cookie::creation_time_to_string() const String Cookie::creation_time_to_string() const

View file

@ -15,7 +15,9 @@
#include <AK/InsertionSort.h> #include <AK/InsertionSort.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/TemporaryChange.h> #include <AK/TemporaryChange.h>
#include <AK/Time.h>
#include <AK/Utf8View.h> #include <AK/Utf8View.h>
#include <LibCore/DateTime.h>
#include <LibCore/Timer.h> #include <LibCore/Timer.h>
#include <LibGC/RootVector.h> #include <LibGC/RootVector.h>
#include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Array.h>
@ -373,8 +375,12 @@ WebIDL::ExceptionOr<GC::Ref<Document>> Document::create_and_initialize(Type type
document->m_window = window; document->m_window = window;
// NOTE: Non-standard: Pull out the Last-Modified header for use in the lastModified property. // NOTE: Non-standard: Pull out the Last-Modified header for use in the lastModified property.
if (auto maybe_last_modified = navigation_params.response->header_list()->get("Last-Modified"sv.bytes()); maybe_last_modified.has_value()) if (auto maybe_last_modified = navigation_params.response->header_list()->get("Last-Modified"sv.bytes()); maybe_last_modified.has_value()) {
document->m_last_modified = Core::DateTime::parse("%a, %d %b %Y %H:%M:%S %Z"sv, maybe_last_modified.value()); auto last_modified_datetime = Core::DateTime::parse("%a, %d %b %Y %H:%M:%S %Z"sv, maybe_last_modified.value());
document->m_last_modified = last_modified_datetime.has_value()
? AK::UnixDateTime::from_seconds_since_epoch(last_modified_datetime.value().timestamp())
: Optional<AK::UnixDateTime>();
}
// NOTE: Non-standard: Pull out the Content-Language header to determine the document's language. // NOTE: Non-standard: Pull out the Content-Language header to determine the document's language.
if (auto maybe_http_content_language = navigation_params.response->header_list()->get("Content-Language"sv.bytes()); maybe_http_content_language.has_value()) { if (auto maybe_http_content_language = navigation_params.response->header_list()->get("Content-Language"sv.bytes()); maybe_http_content_language.has_value()) {
@ -3070,7 +3076,7 @@ String Document::last_modified() const
if (m_last_modified.has_value()) if (m_last_modified.has_value())
return MUST(m_last_modified.value().to_string(format_string)); return MUST(m_last_modified.value().to_string(format_string));
return MUST(Core::DateTime::now().to_string(format_string)); return MUST(AK::UnixDateTime::now().to_string(format_string));
} }
Page& Document::page() Page& Document::page()

View file

@ -15,7 +15,6 @@
#include <AK/String.h> #include <AK/String.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <AK/WeakPtr.h> #include <AK/WeakPtr.h>
#include <LibCore/DateTime.h>
#include <LibCore/Forward.h> #include <LibCore/Forward.h>
#include <LibJS/Console.h> #include <LibJS/Console.h>
#include <LibJS/Forward.h> #include <LibJS/Forward.h>
@ -1201,7 +1200,7 @@ private:
ShadowRoot::DocumentShadowRootList m_shadow_roots; ShadowRoot::DocumentShadowRootList m_shadow_roots;
Optional<Core::DateTime> m_last_modified; Optional<AK::UnixDateTime> m_last_modified;
u64 m_dom_tree_version { 0 }; u64 m_dom_tree_version { 0 };
u64 m_character_data_version { 0 }; u64 m_character_data_version { 0 };

View file

@ -11,7 +11,6 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <LibCore/DateTime.h>
#include <LibJS/Runtime/Date.h> #include <LibJS/Runtime/Date.h>
#include <LibJS/Runtime/NativeFunction.h> #include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/RegExpObject.h> #include <LibJS/Runtime/RegExpObject.h>
@ -2326,8 +2325,8 @@ static String convert_number_to_date_string(double input)
// The algorithm to convert a number to a string, given a number input, is as follows: Return a valid // The algorithm to convert a number to a string, given a number input, is as follows: Return a valid
// date string that represents the date that, in UTC, is current input milliseconds after midnight UTC // date string that represents the date that, in UTC, is current input milliseconds after midnight UTC
// on the morning of 1970-01-01 (the time represented by the value "1970-01-01T00:00:00.0Z"). // on the morning of 1970-01-01 (the time represented by the value "1970-01-01T00:00:00.0Z").
auto date = Core::DateTime::from_timestamp(input / 1000.); auto date = AK::UnixDateTime::from_seconds_since_epoch(input / 1000.);
return MUST(date.to_string("%Y-%m-%d"sv, Core::DateTime::LocalTime::No)); return MUST(date.to_string("%Y-%m-%d"sv));
} }
// https://html.spec.whatwg.org/multipage/input.html#time-state-(type=time):concept-input-value-number-string // https://html.spec.whatwg.org/multipage/input.html#time-state-(type=time):concept-input-value-number-string

View file

@ -7,7 +7,6 @@
#include <AK/NumberFormat.h> #include <AK/NumberFormat.h>
#include <AK/QuickSort.h> #include <AK/QuickSort.h>
#include <AK/SourceGenerator.h> #include <AK/SourceGenerator.h>
#include <LibCore/DateTime.h>
#include <LibCore/Directory.h> #include <LibCore/Directory.h>
#include <LibCore/Resource.h> #include <LibCore/Resource.h>
#include <LibCore/System.h> #include <LibCore/System.h>
@ -65,7 +64,7 @@ ErrorOr<String> load_file_directory_page(URL::URL const& url)
contents.appendff("<td><span class=\"{}\"></span></td>", is_directory ? "folder" : "file"); contents.appendff("<td><span class=\"{}\"></span></td>", is_directory ? "folder" : "file");
contents.appendff("<td><a href=\"file://{}\">{}</a></td><td>&nbsp;</td>", path, name); contents.appendff("<td><a href=\"file://{}\">{}</a></td><td>&nbsp;</td>", path, name);
contents.appendff("<td>{:10}</td><td>&nbsp;</td>", is_directory ? "-"_string : human_readable_size(st.st_size)); contents.appendff("<td>{:10}</td><td>&nbsp;</td>", is_directory ? "-"_string : human_readable_size(st.st_size));
contents.appendff("<td>{}</td>", Core::DateTime::from_timestamp(st.st_mtime).to_byte_string()); contents.appendff("<td>{}</td>", AK::UnixDateTime::from_seconds_since_epoch(st.st_mtime).to_byte_string());
contents.append("</tr>\n"sv); contents.append("</tr>\n"sv);
} }
} }

View file

@ -6,7 +6,6 @@
*/ */
#include <AK/Debug.h> #include <AK/Debug.h>
#include <LibCore/DateTime.h>
#include <LibCore/Directory.h> #include <LibCore/Directory.h>
#include <LibCore/MimeData.h> #include <LibCore/MimeData.h>
#include <LibCore/Resource.h> #include <LibCore/Resource.h>
@ -146,8 +145,8 @@ static HTTP::HeaderMap response_headers_for_file(StringView path, Optional<time_
response_headers.set("Content-Type"sv, mime_type); response_headers.set("Content-Type"sv, mime_type);
if (modified_time.has_value()) { if (modified_time.has_value()) {
auto const datetime = Core::DateTime::from_timestamp(modified_time.value()); auto const datetime = AK::UnixDateTime::from_seconds_since_epoch(modified_time.value());
response_headers.set("Last-Modified"sv, datetime.to_byte_string("%a, %d %b %Y %H:%M:%S GMT"sv, Core::DateTime::LocalTime::No)); response_headers.set("Last-Modified"sv, datetime.to_byte_string("%a, %d %b %Y %H:%M:%S GMT"sv));
} }
return response_headers; return response_headers;

View file

@ -16,7 +16,7 @@
#include <AK/Span.h> #include <AK/Span.h>
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <LibCore/DateTime.h> #include <AK/Time.h>
#include <LibHTTP/HttpResponse.h> #include <LibHTTP/HttpResponse.h>
#include <LibWeb/WebDriver/Client.h> #include <LibWeb/WebDriver/Client.h>
@ -354,7 +354,7 @@ ErrorOr<void, Client::WrappedError> Client::send_error_response(HTTP::HttpReques
void Client::log_response(HTTP::HttpRequest const& request, unsigned code) void Client::log_response(HTTP::HttpRequest const& request, unsigned code)
{ {
outln("{} :: {:03d} :: {} {}", Core::DateTime::now().to_byte_string(), code, request.method_name(), request.resource()); outln("{} :: {:03d} :: {} {}", AK::UnixDateTime::now().to_byte_string(), code, request.method_name(), request.resource());
} }
} }

View file

@ -12,7 +12,6 @@
#include <AK/String.h> #include <AK/String.h>
#include <AK/StringView.h> #include <AK/StringView.h>
#include <AK/Traits.h> #include <AK/Traits.h>
#include <LibCore/DateTime.h>
#include <LibCore/Timer.h> #include <LibCore/Timer.h>
#include <LibURL/Forward.h> #include <LibURL/Forward.h>
#include <LibWeb/Cookie/Cookie.h> #include <LibWeb/Cookie/Cookie.h>

View file

@ -6,7 +6,7 @@
#include <AK/Error.h> #include <AK/Error.h>
#include <AK/String.h> #include <AK/String.h>
#include <LibCore/DateTime.h> #include <AK/Time.h>
#include <LibCore/StandardPaths.h> #include <LibCore/StandardPaths.h>
#include <LibCore/Timer.h> #include <LibCore/Timer.h>
#include <LibGfx/ImageFormats/PNGWriter.h> #include <LibGfx/ImageFormats/PNGWriter.h>
@ -678,7 +678,7 @@ static ErrorOr<LexicalPath> save_screenshot(Gfx::Bitmap const* bitmap)
if (!bitmap) if (!bitmap)
return Error::from_string_literal("Failed to take a screenshot"); return Error::from_string_literal("Failed to take a screenshot");
auto file = Core::DateTime::now().to_byte_string("screenshot-%Y-%m-%d-%H-%M-%S.png"sv); auto file = AK::UnixDateTime::now().to_byte_string("screenshot-%Y-%m-%d-%H-%M-%S.png"sv);
auto path = TRY(Application::the().path_for_downloaded_file(file)); auto path = TRY(Application::the().path_for_downloaded_file(file));
auto encoded = TRY(Gfx::PNGWriter::encode(*bitmap)); auto encoded = TRY(Gfx::PNGWriter::encode(*bitmap));
@ -778,7 +778,7 @@ ErrorOr<LexicalPath> ViewImplementation::dump_gc_graph()
auto gc_graph_json = TRY(promise->await()); auto gc_graph_json = TRY(promise->await());
LexicalPath path { Core::StandardPaths::tempfile_directory() }; LexicalPath path { Core::StandardPaths::tempfile_directory() };
path = path.append(TRY(Core::DateTime::now().to_string("gc-graph-%Y-%m-%d-%H-%M-%S.json"sv))); path = path.append(TRY(AK::UnixDateTime::now().to_string("gc-graph-%Y-%m-%d-%H-%M-%S.json"sv)));
auto dump_file = TRY(Core::File::open(path.string(), Core::File::OpenMode::Write)); auto dump_file = TRY(Core::File::open(path.string(), Core::File::OpenMode::Write));
TRY(dump_file->write_until_depleted(gc_graph_json.bytes())); TRY(dump_file->write_until_depleted(gc_graph_json.bytes()));