Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Setting the binary tzdb directory path at runtime #639

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 35 additions & 25 deletions include/date/tz.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@
# define USE_OS_TZDB 0
#endif

#ifndef USE_BINARY_TZDB
# define USE_BINARY_TZDB USE_OS_TZDB
#endif

#if (!USE_BINARY_TZDB) && (USE_OS_TZDB)
# define error "If USE_OS_TZDB is used, then USE_BINARY_TZDB must also be used."
#endif

#ifndef HAS_REMOTE_API
# if USE_OS_TZDB == 0
# if USE_BINARY_TZDB == 0
# ifdef _WIN32
# define HAS_REMOTE_API 0
# else
Expand All @@ -64,8 +72,8 @@
# pragma clang diagnostic ignored "-Wconstant-logical-operand"
#endif

static_assert(!(USE_OS_TZDB && HAS_REMOTE_API),
"USE_OS_TZDB and HAS_REMOTE_API can not be used together");
static_assert(!(USE_BINARY_TZDB && HAS_REMOTE_API),
"USE_BINARY_TZDB and HAS_REMOTE_API can not be used together");

#ifdef __clang__
# pragma clang diagnostic pop
Expand All @@ -82,9 +90,9 @@ static_assert(HAS_REMOTE_API == 0 ? AUTO_DOWNLOAD == 0 : true,
# define USE_SHELL_API 1
#endif

#if USE_OS_TZDB
#if USE_OS_TZDB || USE_BINARY_TZDB
# ifdef _WIN32
# error "USE_OS_TZDB can not be used on Windows"
# error "USE_OS_TZDB and USE_BINARY_TZDB can not be used on Windows"
# endif
#endif

Expand Down Expand Up @@ -764,13 +772,13 @@ operator!=(const zoned_time<Duration1, TimeZonePtr>& x,

namespace detail
{
# if USE_OS_TZDB
# if USE_BINARY_TZDB
struct transition;
struct expanded_ttinfo;
# else // !USE_OS_TZDB
# else // !USE_BINARY_TZDB
struct zonelet;
class Rule;
# endif // !USE_OS_TZDB
# endif // !USE_BINARY_TZDB
}

#endif // !defined(_MSC_VER) || (_MSC_VER >= 1900)
Expand All @@ -779,12 +787,12 @@ class time_zone
{
private:
std::string name_;
#if USE_OS_TZDB
#if USE_BINARY_TZDB
std::vector<detail::transition> transitions_;
std::vector<detail::expanded_ttinfo> ttinfos_;
#else // !USE_OS_TZDB
#else // !USE_BINARY_TZDB
std::vector<detail::zonelet> zonelets_;
#endif // !USE_OS_TZDB
#endif // !USE_BINARY_TZDB
std::unique_ptr<std::once_flag> adjusted_;

public:
Expand Down Expand Up @@ -819,9 +827,9 @@ class time_zone
friend bool operator< (const time_zone& x, const time_zone& y) NOEXCEPT;
friend DATE_API std::ostream& operator<<(std::ostream& os, const time_zone& z);

#if !USE_OS_TZDB
#if !USE_BINARY_TZDB
DATE_API void add(const std::string& s);
#endif // !USE_OS_TZDB
#endif // !USE_BINARY_TZDB

private:
DATE_API sys_info get_info_impl(sys_seconds tp) const;
Expand All @@ -834,7 +842,7 @@ class time_zone
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
to_sys_impl(local_time<Duration> tp, choose, std::true_type) const;

#if USE_OS_TZDB
#if USE_BINARY_TZDB
DATE_API void init() const;
DATE_API void init_impl();
DATE_API sys_info
Expand All @@ -844,11 +852,11 @@ class time_zone
DATE_API void
load_data(std::istream& inf, std::int32_t tzh_leapcnt, std::int32_t tzh_timecnt,
std::int32_t tzh_typecnt, std::int32_t tzh_charcnt);
#else // !USE_OS_TZDB
#else // !USE_BINARY_TZDB
DATE_API sys_info get_info_impl(sys_seconds tp, int timezone) const;
DATE_API void adjust_infos(const std::vector<detail::Rule>& rules);
DATE_API void parse_info(std::istream& in);
#endif // !USE_OS_TZDB
#endif // !USE_BINARY_TZDB
};

#if defined(_MSC_VER) && (_MSC_VER < 1900)
Expand Down Expand Up @@ -958,7 +966,7 @@ time_zone::to_sys_impl(local_time<Duration> tp, choose, std::true_type) const
return sys_time<Duration>{tp.time_since_epoch()} - i.first.offset;
}

#if !USE_OS_TZDB
#if !USE_BINARY_TZDB

class time_zone_link
{
Expand All @@ -984,15 +992,15 @@ inline bool operator> (const time_zone_link& x, const time_zone_link& y) {return
inline bool operator<=(const time_zone_link& x, const time_zone_link& y) {return !(y < x);}
inline bool operator>=(const time_zone_link& x, const time_zone_link& y) {return !(x < y);}

#endif // !USE_OS_TZDB
#endif // !USE_BINARY_TZDB

class leap_second
{
private:
sys_seconds date_;

public:
#if USE_OS_TZDB
#if USE_BINARY_TZDB
DATE_API explicit leap_second(const sys_seconds& s, detail::undocumented);
#else
DATE_API explicit leap_second(const std::string& s, detail::undocumented);
Expand Down Expand Up @@ -1151,11 +1159,11 @@ struct tzdb
{
std::string version = "unknown";
std::vector<time_zone> zones;
#if !USE_OS_TZDB
#if !USE_BINARY_TZDB
std::vector<time_zone_link> links;
#endif
std::vector<leap_second> leap_seconds;
#if !USE_OS_TZDB
#if !USE_BINARY_TZDB
std::vector<detail::Rule> rules;
#endif
#ifdef _WIN32
Expand Down Expand Up @@ -1294,12 +1302,14 @@ tzdb_list::cend() const NOEXCEPT

DATE_API tzdb_list& get_tzdb_list();

#if !USE_OS_TZDB

#if USE_BINARY_TZDB
# if !USE_OS_TZDB
DATE_API void set_tz_dir(const std::string& tz_dir);
# endif // !USE_OS_TZDB
#else // !USE_BINARY_TZDB
DATE_API const tzdb& reload_tzdb();
DATE_API void set_install(const std::string& install);

#endif // !USE_OS_TZDB
#endif // USE_BINARY_TZDB

#if HAS_REMOTE_API

Expand Down
6 changes: 3 additions & 3 deletions include/date/tz_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace date
namespace detail
{

#if !USE_OS_TZDB
#if !USE_BINARY_TZDB

enum class tz {utc, local, standard};

Expand Down Expand Up @@ -256,7 +256,7 @@ struct zonelet
zonelet& operator=(const zonelet&) = delete;
};

#else // USE_OS_TZDB
#else // USE_BINARY_TZDB

struct ttinfo
{
Expand Down Expand Up @@ -303,7 +303,7 @@ struct transition
}
};

#endif // USE_OS_TZDB
#endif // USE_BINARY_TZDB

} // namespace detail

Expand Down
Loading