Selaa lähdekoodia

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.
Timothy Flynn 1 vuosi sitten
vanhempi
commit
5ddfcfd07e

+ 1 - 0
Meta/gn/secondary/Userland/Libraries/LibCore/BUILD.gn

@@ -156,6 +156,7 @@ shared_library("LibCore") {
     "//Meta/gn/build/libs/crypt",
     "//Meta/gn/build/libs/crypt",
     "//Meta/gn/build/libs/pthread",
     "//Meta/gn/build/libs/pthread",
     "//Userland/Libraries/LibSystem",
     "//Userland/Libraries/LibSystem",
+    "//Userland/Libraries/LibTimeZone",
     "//Userland/Libraries/LibURL",
     "//Userland/Libraries/LibURL",
   ]
   ]
 }
 }

+ 2 - 6
Meta/gn/secondary/Userland/Libraries/LibTimeZone/BUILD.gn

@@ -69,16 +69,12 @@ source_set("LibTimeZone") {
     "$target_gen_dir/..",
     "$target_gen_dir/..",
   ]
   ]
   sources = [
   sources = [
-    "DateTime.cpp",
-    "DateTime.h",
     "Forward.h",
     "Forward.h",
     "TimeZone.cpp",
     "TimeZone.cpp",
     "TimeZone.h",
     "TimeZone.h",
   ]
   ]
-  deps = [
-    "//AK",
-    "//Userland/Libraries/LibCore",
-  ]
+  deps = [ "//AK" ]
+
   if (enable_timezone_database_download) {
   if (enable_timezone_database_download) {
     deps += [ ":generate_timezone_sources" ]
     deps += [ ":generate_timezone_sources" ]
     sources += get_target_outputs(":generate_timezone_sources")
     sources += get_target_outputs(":generate_timezone_sources")

+ 1 - 1
Userland/Libraries/LibCore/CMakeLists.txt

@@ -70,7 +70,7 @@ else()
 endif()
 endif()
 
 
 serenity_lib(LibCore core)
 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)
 if (APPLE)
     target_link_libraries(LibCore PUBLIC "-framework CoreFoundation")
     target_link_libraries(LibCore PUBLIC "-framework CoreFoundation")

+ 25 - 3
Userland/Libraries/LibCore/DateTime.cpp

@@ -11,14 +11,36 @@
 #include <AK/StringBuilder.h>
 #include <AK/StringBuilder.h>
 #include <AK/Time.h>
 #include <AK/Time.h>
 #include <LibCore/DateTime.h>
 #include <LibCore/DateTime.h>
-#include <LibTimeZone/DateTime.h>
+#include <LibTimeZone/TimeZone.h>
 #include <errno.h>
 #include <errno.h>
 #include <time.h>
 #include <time.h>
 
 
 namespace Core {
 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()
 DateTime DateTime::now()
 {
 {

+ 0 - 1
Userland/Libraries/LibTimeZone/CMakeLists.txt

@@ -2,7 +2,6 @@ include(${SerenityOS_SOURCE_DIR}/Meta/CMake/time_zone_data.cmake)
 
 
 set(SOURCES
 set(SOURCES
     ${TIME_ZONE_DATA_SOURCES}
     ${TIME_ZONE_DATA_SOURCES}
-    DateTime.cpp
     TimeZone.cpp
     TimeZone.cpp
 )
 )
 set(GENERATED_SOURCES ${CURRENT_LIB_GENERATED})
 set(GENERATED_SOURCES ${CURRENT_LIB_GENERATED})

+ 0 - 38
Userland/Libraries/LibTimeZone/DateTime.cpp

@@ -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);
-}
-
-}

+ 0 - 19
Userland/Libraries/LibTimeZone/DateTime.h

@@ -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);
-
-}