[time.zone.db] (original) (raw)

30 Time library [time]

30.11 Time zones [time.zone]

30.11.2 Time zone database [time.zone.db]

30.11.2.1 Class tzdb [time.zone.db.tzdb]

namespace std::chrono { struct tzdb { string version; vector<time_zone> zones; vector<time_zone_link> links; vector<leap_second> leap_seconds;const time_zone* locate_zone(string_view tz_name) const;const time_zone* current_zone() const;};}

Each vector in a tzdb object is sorted to enable fast lookup.

const time_zone* locate_zone(string_view tz_name) const;

Returns:

[Note 1:

A time_zone_link specifies an alternative name for a time_zone.

— _end note_]

Throws: If a const time_zone* cannot be found as described in the Returns: element, throws a runtime_error.

[Note 2:

On non-exceptional return, the return value is always a pointer to a valid time_zone.

— _end note_]

const time_zone* current_zone() const;

Returns: A pointer to the time zone which the computer has set as its local time zone.

30.11.2.2 Class tzdb_list [time.zone.db.list]

namespace std::chrono { class tzdb_list { public: tzdb_list(const tzdb_list&) = delete; tzdb_list& operator=(const tzdb_list&) = delete;class const_iterator;const tzdb& front() const noexcept; const_iterator erase_after(const_iterator p); const_iterator begin() const noexcept; const_iterator end() const noexcept; const_iterator cbegin() const noexcept; const_iterator cend() const noexcept;};}

The tzdb_list database is a singleton; the unique object of type tzdb_list can be accessed via the get_tzdb_list() function.

[Note 1:

This access is only needed for those applications that need to have long uptimes and have a need to update the time zone database while running.

Other applications can implicitly access the front() of this list via the read-only namespace scope functionsget_tzdb(),locate_zone(), andcurrent_zone().

— _end note_]

The tzdb_list object contains a list of tzdb objects.

tzdb_list​::​const_iterator is a constant iterator which meets the Cpp17ForwardIterator requirements and has a value type of tzdb.

const tzdb& front() const noexcept;

Synchronization: This operation is thread-safe with respect to reload_tzdb().

[Note 2:

reload_tzdb() pushes a new tzdbonto the front of this container.

— _end note_]

Returns: A reference to the first tzdb in the container.

const_iterator erase_after(const_iterator p);

Preconditions: The iterator following p is dereferenceable.

Effects: Erases the tzdb referred to by the iterator following p.

Postconditions: No pointers, references, or iterators are invalidated except those referring to the erased tzdb.

[Note 3:

It is not possible to erase the tzdbreferred to by begin().

— _end note_]

Returns: An iterator pointing to the element following the one that was erased, or end() if no such element exists.

const_iterator begin() const noexcept;

Returns: An iterator referring to the first tzdb in the container.

const_iterator end() const noexcept;

Returns: An iterator referring to the position one past the last tzdb in the container.

const_iterator cbegin() const noexcept;

const_iterator cend() const noexcept;

30.11.2.3 Time zone database access [time.zone.db.access]

tzdb_list& get_tzdb_list();

Effects: If this is the first access to the time zone database, initializes the database.

If this call initializes the database, the resulting database will be a tzdb_listholding a single initialized tzdb.

Synchronization: It is safe to call this function from multiple threads at one time.

Returns: A reference to the database.

Throws: runtime_error if for any reason a reference cannot be returned to a valid tzdb_listcontaining one or more valid tzdbs.

Returns: get_tzdb_list().front().

const time_zone* locate_zone(string_view tz_name);

Returns: get_tzdb().locate_zone(tz_name).

[Note 1:

The time zone database will be initialized if this is the first reference to the database.

— _end note_]

const time_zone* current_zone();

Returns: get_tzdb().current_zone().

30.11.2.4 Remote time zone database support [time.zone.db.remote]

The local time zone database is that supplied by the implementation when the program first accesses the database, for example via current_zone().

While the program is running, the implementation may choose to update the time zone database.

This update shall not impact the program in any way unless the program calls the functions in this subclause.

This potentially updated time zone database is referred to as the remote time zone database.

const tzdb& reload_tzdb();

Effects: This function first checks the version of the remote time zone database.

If the versions of the local and remote databases are the same, there are no effects.

Otherwise the remote database is pushed to the front of the tzdb_listaccessed by get_tzdb_list().

Synchronization: This function is thread-safe with respect toget_tzdb_list().front() and get_tzdb_list().erase_after().

Postconditions: No pointers, references, or iterators are invalidated.

Returns: get_tzdb_list().front().

Throws: runtime_error if for any reason a reference cannot be returned to a valid tzdb.

Returns: The latest remote database version.

[Note 1:

This can be compared with get_tzdb().versionto discover if the local and remote databases are equivalent.

— _end note_]