mirror of
https://github.com/HowardHinnant/date.git
synced 2024-12-28 01:04:54 +08:00
Rename TZ_DB to tzdb
* Bring into alignment with proposal * TZ_DB alias left behind for backwards compatibility
This commit is contained in:
parent
22a229af91
commit
3acb299f3f
@ -1163,7 +1163,7 @@ struct timezone_mapping
|
|||||||
|
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
struct TZ_DB
|
struct tzdb
|
||||||
{
|
{
|
||||||
std::string version = "unknown";
|
std::string version = "unknown";
|
||||||
std::vector<time_zone> zones;
|
std::vector<time_zone> zones;
|
||||||
@ -1179,14 +1179,14 @@ struct TZ_DB
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::vector<detail::timezone_mapping> mappings;
|
std::vector<detail::timezone_mapping> mappings;
|
||||||
#endif
|
#endif
|
||||||
TZ_DB* next = nullptr;
|
tzdb* next = nullptr;
|
||||||
|
|
||||||
TZ_DB() = default;
|
tzdb() = default;
|
||||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
|
#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
|
||||||
TZ_DB(TZ_DB&&) = default;
|
tzdb(tzdb&&) = default;
|
||||||
TZ_DB& operator=(TZ_DB&&) = default;
|
tzdb& operator=(tzdb&&) = default;
|
||||||
#else // defined(_MSC_VER) && (_MSC_VER < 1900)
|
#else // defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||||
TZ_DB(TZ_DB&& src)
|
tzdb(tzdb&& src)
|
||||||
: version(std::move(src.version))
|
: version(std::move(src.version))
|
||||||
, zones(std::move(src.zones))
|
, zones(std::move(src.zones))
|
||||||
, links(std::move(src.links))
|
, links(std::move(src.links))
|
||||||
@ -1195,7 +1195,7 @@ struct TZ_DB
|
|||||||
, mappings(std::move(src.mappings))
|
, mappings(std::move(src.mappings))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
TZ_DB& operator=(TZ_DB&& src)
|
tzdb& operator=(tzdb&& src)
|
||||||
{
|
{
|
||||||
version = std::move(src.version);
|
version = std::move(src.version);
|
||||||
zones = std::move(src.zones);
|
zones = std::move(src.zones);
|
||||||
@ -1215,22 +1215,24 @@ struct TZ_DB
|
|||||||
const time_zone* current_zone() const;
|
const time_zone* current_zone() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
DATE_API std::ostream&
|
using TZ_DB = tzdb;
|
||||||
operator<<(std::ostream& os, const TZ_DB& db);
|
|
||||||
|
|
||||||
DATE_API const TZ_DB& get_tzdb();
|
DATE_API std::ostream&
|
||||||
|
operator<<(std::ostream& os, const tzdb& db);
|
||||||
|
|
||||||
|
DATE_API const tzdb& get_tzdb();
|
||||||
|
|
||||||
class tzdb_list
|
class tzdb_list
|
||||||
{
|
{
|
||||||
std::atomic<TZ_DB*> head_{nullptr};
|
std::atomic<tzdb*> head_{nullptr};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~tzdb_list();
|
~tzdb_list();
|
||||||
tzdb_list() = default;
|
tzdb_list() = default;
|
||||||
tzdb_list(tzdb_list&& x) noexcept;
|
tzdb_list(tzdb_list&& x) noexcept;
|
||||||
|
|
||||||
const TZ_DB& front() const noexcept {return *head_;}
|
const tzdb& front() const noexcept {return *head_;}
|
||||||
TZ_DB& front() noexcept {return *head_;}
|
tzdb& front() noexcept {return *head_;}
|
||||||
|
|
||||||
class const_iterator;
|
class const_iterator;
|
||||||
|
|
||||||
@ -1244,19 +1246,19 @@ public:
|
|||||||
|
|
||||||
struct undocumented_helper;
|
struct undocumented_helper;
|
||||||
private:
|
private:
|
||||||
void push_front(TZ_DB* tzdb) noexcept;
|
void push_front(tzdb* tzdb) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
class tzdb_list::const_iterator
|
class tzdb_list::const_iterator
|
||||||
{
|
{
|
||||||
TZ_DB* p_ = nullptr;
|
tzdb* p_ = nullptr;
|
||||||
|
|
||||||
explicit const_iterator(TZ_DB* p) noexcept : p_{p} {}
|
explicit const_iterator(tzdb* p) noexcept : p_{p} {}
|
||||||
public:
|
public:
|
||||||
const_iterator() = default;
|
const_iterator() = default;
|
||||||
|
|
||||||
using iterator_category = std::forward_iterator_tag;
|
using iterator_category = std::forward_iterator_tag;
|
||||||
using value_type = TZ_DB;
|
using value_type = tzdb;
|
||||||
using reference = const value_type&;
|
using reference = const value_type&;
|
||||||
using pointer = const value_type*;
|
using pointer = const value_type*;
|
||||||
using difference_type = std::ptrdiff_t;
|
using difference_type = std::ptrdiff_t;
|
||||||
@ -1312,8 +1314,8 @@ DATE_API tzdb_list& get_tzdb_list();
|
|||||||
|
|
||||||
#if !USE_OS_TZDB
|
#if !USE_OS_TZDB
|
||||||
|
|
||||||
DATE_API const TZ_DB& reload_tzdb();
|
DATE_API const tzdb& reload_tzdb();
|
||||||
DATE_API void set_install(const std::string& install);
|
DATE_API void set_install(const std::string& install);
|
||||||
|
|
||||||
#endif // !USE_OS_TZDB
|
#endif // !USE_OS_TZDB
|
||||||
|
|
||||||
|
32
src/tz.cpp
32
src/tz.cpp
@ -359,11 +359,11 @@ struct undocumented {explicit undocumented() = default;};
|
|||||||
static_assert(min_year <= max_year, "Configuration error");
|
static_assert(min_year <= max_year, "Configuration error");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static std::unique_ptr<TZ_DB> init_tzdb();
|
static std::unique_ptr<tzdb> init_tzdb();
|
||||||
|
|
||||||
tzdb_list::~tzdb_list()
|
tzdb_list::~tzdb_list()
|
||||||
{
|
{
|
||||||
const TZ_DB* ptr = head_;
|
const tzdb* ptr = head_;
|
||||||
head_ = nullptr;
|
head_ = nullptr;
|
||||||
while (ptr != nullptr)
|
while (ptr != nullptr)
|
||||||
{
|
{
|
||||||
@ -379,7 +379,7 @@ tzdb_list::tzdb_list(tzdb_list&& x) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tzdb_list::push_front(TZ_DB* tzdb) noexcept
|
tzdb_list::push_front(tzdb* tzdb) noexcept
|
||||||
{
|
{
|
||||||
tzdb->next = head_;
|
tzdb->next = head_;
|
||||||
head_ = tzdb;
|
head_ = tzdb;
|
||||||
@ -396,7 +396,7 @@ tzdb_list::erase_after(const_iterator p) noexcept
|
|||||||
|
|
||||||
struct tzdb_list::undocumented_helper
|
struct tzdb_list::undocumented_helper
|
||||||
{
|
{
|
||||||
static void push_front(tzdb_list& db_list, TZ_DB* tzdb) noexcept
|
static void push_front(tzdb_list& db_list, tzdb* tzdb) noexcept
|
||||||
{
|
{
|
||||||
db_list.push_front(tzdb);
|
db_list.push_front(tzdb);
|
||||||
}
|
}
|
||||||
@ -2573,10 +2573,10 @@ get_version()
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
static
|
static
|
||||||
std::unique_ptr<TZ_DB>
|
std::unique_ptr<tzdb>
|
||||||
init_tzdb()
|
init_tzdb()
|
||||||
{
|
{
|
||||||
std::unique_ptr<TZ_DB> db(new TZ_DB);
|
std::unique_ptr<tzdb> db(new tzdb);
|
||||||
|
|
||||||
//Iterate through folders
|
//Iterate through folders
|
||||||
std::queue<std::string> subfolders;
|
std::queue<std::string> subfolders;
|
||||||
@ -3280,7 +3280,7 @@ get_version(const std::string& path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
std::unique_ptr<TZ_DB>
|
std::unique_ptr<tzdb>
|
||||||
init_tzdb()
|
init_tzdb()
|
||||||
{
|
{
|
||||||
using namespace date;
|
using namespace date;
|
||||||
@ -3288,7 +3288,7 @@ init_tzdb()
|
|||||||
const std::string path = install + folder_delimiter;
|
const std::string path = install + folder_delimiter;
|
||||||
std::string line;
|
std::string line;
|
||||||
bool continue_zone = false;
|
bool continue_zone = false;
|
||||||
std::unique_ptr<TZ_DB> db(new TZ_DB);
|
std::unique_ptr<tzdb> db(new tzdb);
|
||||||
|
|
||||||
#if AUTO_DOWNLOAD
|
#if AUTO_DOWNLOAD
|
||||||
if (!file_exists(install))
|
if (!file_exists(install))
|
||||||
@ -3405,7 +3405,7 @@ init_tzdb()
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TZ_DB&
|
const tzdb&
|
||||||
reload_tzdb()
|
reload_tzdb()
|
||||||
{
|
{
|
||||||
#if AUTO_DOWNLOAD
|
#if AUTO_DOWNLOAD
|
||||||
@ -3419,7 +3419,7 @@ reload_tzdb()
|
|||||||
|
|
||||||
#endif // !USE_OS_TZDB
|
#endif // !USE_OS_TZDB
|
||||||
|
|
||||||
const TZ_DB&
|
const tzdb&
|
||||||
get_tzdb()
|
get_tzdb()
|
||||||
{
|
{
|
||||||
return get_tzdb_list().front();
|
return get_tzdb_list().front();
|
||||||
@ -3427,9 +3427,9 @@ get_tzdb()
|
|||||||
|
|
||||||
const time_zone*
|
const time_zone*
|
||||||
#if HAS_STRING_VIEW
|
#if HAS_STRING_VIEW
|
||||||
TZ_DB::locate_zone(std::string_view tz_name) const
|
tzdb::locate_zone(std::string_view tz_name) const
|
||||||
#else
|
#else
|
||||||
TZ_DB::locate_zone(const std::string& tz_name) const
|
tzdb::locate_zone(const std::string& tz_name) const
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
auto zi = std::lower_bound(zones.begin(), zones.end(), tz_name,
|
auto zi = std::lower_bound(zones.begin(), zones.end(), tz_name,
|
||||||
@ -3482,7 +3482,7 @@ locate_zone(const std::string& tz_name)
|
|||||||
#if USE_OS_TZDB
|
#if USE_OS_TZDB
|
||||||
|
|
||||||
std::ostream&
|
std::ostream&
|
||||||
operator<<(std::ostream& os, const TZ_DB& db)
|
operator<<(std::ostream& os, const tzdb& db)
|
||||||
{
|
{
|
||||||
os << "Version: " << db.version << "\n\n";
|
os << "Version: " << db.version << "\n\n";
|
||||||
for (const auto& x : db.zones)
|
for (const auto& x : db.zones)
|
||||||
@ -3498,7 +3498,7 @@ operator<<(std::ostream& os, const TZ_DB& db)
|
|||||||
#else // !USE_OS_TZDB
|
#else // !USE_OS_TZDB
|
||||||
|
|
||||||
std::ostream&
|
std::ostream&
|
||||||
operator<<(std::ostream& os, const TZ_DB& db)
|
operator<<(std::ostream& os, const tzdb& db)
|
||||||
{
|
{
|
||||||
os << "Version: " << db.version << '\n';
|
os << "Version: " << db.version << '\n';
|
||||||
std::string title("--------------------------------------------"
|
std::string title("--------------------------------------------"
|
||||||
@ -3579,7 +3579,7 @@ getTimeZoneKeyName()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const time_zone*
|
const time_zone*
|
||||||
TZ_DB::current_zone() const
|
tzdb::current_zone() const
|
||||||
{
|
{
|
||||||
std::string win_tzid = getTimeZoneKeyName();
|
std::string win_tzid = getTimeZoneKeyName();
|
||||||
std::string standard_tzid;
|
std::string standard_tzid;
|
||||||
@ -3597,7 +3597,7 @@ TZ_DB::current_zone() const
|
|||||||
#else // !_WIN32
|
#else // !_WIN32
|
||||||
|
|
||||||
const time_zone*
|
const time_zone*
|
||||||
TZ_DB::current_zone() const
|
tzdb::current_zone() const
|
||||||
{
|
{
|
||||||
// On some OS's a file called /etc/localtime may
|
// On some OS's a file called /etc/localtime may
|
||||||
// exist and it may be either a real file
|
// exist and it may be either a real file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user