mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 12:49:19 +00:00
LibCore+LibTimeZone: Move TZDB utilities from LibTimeZone to LibCore
We had weakly defined a couple utilities needed by Core::DateTime when LibCore was unable to depend on LibTimeZone. This is no longer the case.
This commit is contained in:
parent
9b1b91f98a
commit
5ddfcfd07e
Notes:
sideshowbarker
2024-07-16 19:42:24 +09:00
Author: https://github.com/trflynn89
Commit: 5ddfcfd07e
Pull-request: https://github.com/SerenityOS/serenity/pull/23717
Issue: https://github.com/SerenityOS/serenity/issues/23625
Reviewed-by: https://github.com/ADKaster ✅
7 changed files with 29 additions and 68 deletions
|
@ -156,6 +156,7 @@ shared_library("LibCore") {
|
|||
"//Meta/gn/build/libs/crypt",
|
||||
"//Meta/gn/build/libs/pthread",
|
||||
"//Userland/Libraries/LibSystem",
|
||||
"//Userland/Libraries/LibTimeZone",
|
||||
"//Userland/Libraries/LibURL",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -69,16 +69,12 @@ source_set("LibTimeZone") {
|
|||
"$target_gen_dir/..",
|
||||
]
|
||||
sources = [
|
||||
"DateTime.cpp",
|
||||
"DateTime.h",
|
||||
"Forward.h",
|
||||
"TimeZone.cpp",
|
||||
"TimeZone.h",
|
||||
]
|
||||
deps = [
|
||||
"//AK",
|
||||
"//Userland/Libraries/LibCore",
|
||||
]
|
||||
deps = [ "//AK" ]
|
||||
|
||||
if (enable_timezone_database_download) {
|
||||
deps += [ ":generate_timezone_sources" ]
|
||||
sources += get_target_outputs(":generate_timezone_sources")
|
||||
|
|
|
@ -70,7 +70,7 @@ else()
|
|||
endif()
|
||||
|
||||
serenity_lib(LibCore core)
|
||||
target_link_libraries(LibCore PRIVATE LibCoreMinimal LibCrypt LibSystem LibURL)
|
||||
target_link_libraries(LibCore PRIVATE LibCoreMinimal LibCrypt LibSystem LibTimeZone LibURL)
|
||||
|
||||
if (APPLE)
|
||||
target_link_libraries(LibCore PUBLIC "-framework CoreFoundation")
|
||||
|
|
|
@ -11,14 +11,36 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Time.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <LibTimeZone/DateTime.h>
|
||||
#include <LibTimeZone/TimeZone.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
Optional<StringView> __attribute__((weak)) parse_time_zone_name(GenericLexer&) { return {}; }
|
||||
void __attribute__((weak)) apply_time_zone_offset(StringView, UnixDateTime&) { }
|
||||
static Optional<StringView> parse_time_zone_name(GenericLexer& lexer)
|
||||
{
|
||||
auto start_position = lexer.tell();
|
||||
|
||||
Optional<StringView> canonicalized_time_zone;
|
||||
|
||||
lexer.ignore_until([&](auto) {
|
||||
auto time_zone = lexer.input().substring_view(start_position, lexer.tell() - start_position + 1);
|
||||
|
||||
canonicalized_time_zone = TimeZone::canonicalize_time_zone(time_zone);
|
||||
return canonicalized_time_zone.has_value();
|
||||
});
|
||||
|
||||
if (canonicalized_time_zone.has_value())
|
||||
lexer.ignore();
|
||||
|
||||
return canonicalized_time_zone;
|
||||
}
|
||||
|
||||
static void apply_time_zone_offset(StringView time_zone, UnixDateTime& time)
|
||||
{
|
||||
if (auto offset = TimeZone::get_time_zone_offset(time_zone, time); offset.has_value())
|
||||
time -= Duration::from_seconds(offset->seconds);
|
||||
}
|
||||
|
||||
DateTime DateTime::now()
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@ include(${SerenityOS_SOURCE_DIR}/Meta/CMake/time_zone_data.cmake)
|
|||
|
||||
set(SOURCES
|
||||
${TIME_ZONE_DATA_SOURCES}
|
||||
DateTime.cpp
|
||||
TimeZone.cpp
|
||||
)
|
||||
set(GENERATED_SOURCES ${CURRENT_LIB_GENERATED})
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/GenericLexer.h>
|
||||
#include <LibTimeZone/DateTime.h>
|
||||
#include <LibTimeZone/TimeZone.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
Optional<StringView> parse_time_zone_name(GenericLexer& lexer)
|
||||
{
|
||||
auto start_position = lexer.tell();
|
||||
|
||||
Optional<StringView> canonicalized_time_zone;
|
||||
|
||||
lexer.ignore_until([&](auto) {
|
||||
auto time_zone = lexer.input().substring_view(start_position, lexer.tell() - start_position + 1);
|
||||
|
||||
canonicalized_time_zone = TimeZone::canonicalize_time_zone(time_zone);
|
||||
return canonicalized_time_zone.has_value();
|
||||
});
|
||||
|
||||
if (canonicalized_time_zone.has_value())
|
||||
lexer.ignore();
|
||||
|
||||
return canonicalized_time_zone;
|
||||
}
|
||||
|
||||
void apply_time_zone_offset(StringView time_zone, UnixDateTime& time)
|
||||
{
|
||||
if (auto offset = TimeZone::get_time_zone_offset(time_zone, time); offset.has_value())
|
||||
time -= Duration::from_seconds(offset->seconds);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Time.h>
|
||||
|
||||
// This file contains definitions of Core::DateTime methods which require TZDB data.
|
||||
namespace Core {
|
||||
|
||||
Optional<StringView> parse_time_zone_name(GenericLexer&);
|
||||
void apply_time_zone_offset(StringView time_zone, UnixDateTime& time);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue