Repository: conan-io/conan-center-index

Issue:
[package] date/2.4.1: broken when migrated from bincrafters
Earlier, there used to be a conan package for a very popular date.h library (https://github.com/HowardHinnant/date):
date/2.4.1@bincrafters/stable

That conan package worked fine and included the time zone information.

The bincrafters' date package was obsoleted some 6 months ago:
https://github.com/bincrafters/conan-date

However, the new date package at:
https://conan.io/center/date/2.4.1/
(revision 1ca181b0a69ae13731469324fac)

breaks the "contract" of the bincrafter's package -- the time zone information is not included. This is very unfortunate -- most people use tz.h library together with date.h.

Could you please add the time zone information or help me with a hint or two where to start in order to add time zone information to date/2.4.1 package on conan center? Or is there a tz.h package that I am maybe not aware of?

Thanks a lot for your help!


Discussion:

Resolving patch:
diff --git a/recipes/date/all/conanfile.py b/recipes/date/all/conanfile.py
--- a/recipes/date/all/conanfile.py
+++ b/recipes/date/all/conanfile.py
@@ -1,5 +1,5 @@
 import os
-from conans import ConanFile, tools
+from conans import ConanFile, CMake, tools
 
 
 class DateConan(ConanFile):
@@ -7,23 +7,85 @@ class DateConan(ConanFile):
     url = "https://github.com/conan-io/conan-center-index"
     homepage = "https://github.com/HowardHinnant/date"
     description = "A date and time library based on the C++11/14/17 <chrono> header"
-    topics = ("date", "datetime", "timezone", "calendar", "time", "iana-database")
+    topics = ("date", "datetime", "timezone",
+              "calendar", "time", "iana-database")
     license = "MIT"
-    exports_sources = ["patches/*"]
-    no_copy_source = True
+    exports_sources = ["patches/*", "CMakeLists.txt"]
+    settings = "os", "arch", "compiler", "build_type"
+    generators = "cmake",
+    options = {"shared": [True, False],
+               "fPIC": [True, False],
+               "use_system_tz_db": [True, False],
+               "use_tz_db_in_dot": [True, False]}
+    default_options = {"shared": False,
+                       "fPIC": True,
+                       "use_system_tz_db": False,
+                       "use_tz_db_in_dot": False}
+
+    _cmake = None
 
     @property
     def _source_subfolder(self):
-        return os.path.join(self.source_folder, "source_subfolder")
+        return "source_subfolder"
+    @property
+    def _build_subfolder(self):
+        return "build_subfolder"
+
+    def _configure_cmake(self):
+        if self._cmake:
+            return self._cmake
+        cmake = CMake(self)
+        cmake.definitions["ENABLE_DATE_TESTING"] = False
+        cmake.definitions["USE_SYSTEM_TZ_DB"] = self.options.use_system_tz_db
+        cmake.definitions["USE_TZ_DB_IN_DOT"] = self.options.use_tz_db_in_dot
+        cmake.configure()
+
+        self._cmake = cmake
+        return self._cmake
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.settings.compiler.cppstd:
+            tools.check_min_cppstd(self, "11")
+
+    def requirements(self):
+        if not self.options.use_system_tz_db:
+            self.requires("libcurl/7.69.1")
 
     def source(self):
         tools.get(**self.conan_data["sources"][self.version])
         extracted_dir = self.name + "-" + self.version
         os.rename(extracted_dir, self._source_subfolder)
+
+    def build(self):
         for patch in self.conan_data["patches"][self.version]:
             tools.patch(**patch)
+        cmake = self._configure_cmake()
+        cmake.build()
 
     def package(self):
-        self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
-        self.copy(pattern="date.h", dst=os.path.join("include", "date"),
-                  src=os.path.join(self._source_subfolder, "include", "date"))
+        self.copy(pattern="LICENSE.txt", dst="licenses",
+                  src=self._source_subfolder)
+        cmake = self._configure_cmake()
+        cmake.install()
+        tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
+        tools.rmdir(os.path.join(self.package_folder, "CMake"))
+
+    def package_info(self):
+        self.cpp_info.libs = tools.collect_libs(self)
+        if self.settings.os == "Linux":
+            self.cpp_info.system_libs.append("pthread")
+
+        if self.options.use_system_tz_db and not self.settings.os == "Windows":
+            use_os_tzdb = 1
+        else:
+            use_os_tzdb = 0
+
+        defines = ["USE_OS_TZDB={}".format(use_os_tzdb)]
+        if self.settings.os == "Windows" and self.options.shared:
+            defines.append("DATE_USE_DLL=1")
+
+        self.cpp_info.defines.extend(defines)


Test patch:
diff --git a/recipes/date/all/test_package/CMakeLists.txt b/recipes/date/all/test_package/CMakeLists.txt
--- a/recipes/date/all/test_package/CMakeLists.txt
+++ b/recipes/date/all/test_package/CMakeLists.txt
@@ -1,11 +1,9 @@
-project(test_package)
 cmake_minimum_required(VERSION 2.8.11)
-
-set(CMAKE_VERBOSE_MAKEFILE ON)
+project(test_package)
 
 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
 conan_basic_setup()
 
 add_executable(${PROJECT_NAME} test_package.cpp)
 target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
-set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
\ No newline at end of file
+set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
diff --git a/recipes/date/all/test_package/test_package.cpp b/recipes/date/all/test_package/test_package.cpp
--- a/recipes/date/all/test_package/test_package.cpp
+++ b/recipes/date/all/test_package/test_package.cpp
@@ -3,6 +3,7 @@
 #include <chrono>
 
 #include "date/date.h"
+#include "date/tz.h"
 
 int main() {
     using namespace std::chrono;
@@ -14,5 +15,13 @@ int main() {
     std::cout << date2 << '\n';
     auto date3 = 22_d/March/2015;
     std::cout << date3 << '\n';
+
+    try {
+        auto tz = date::current_zone()->name();
+        std::cout << "timezone: " << tz << std::endl;
+    } catch (const std::exception & e) {
+         std::cout << "exception caught " << e.what() << std::endl;
+    }
+
     return EXIT_SUCCESS;
 }