Created on 2025-02-22.00:00:00 last changed 1 month ago
Proposed resolution:
This wording is relative to N5001.
const time_zone* locate_zone(string_view tz_name) const;-2- Returns:
- (2.1) — If `zones` contains an element `tz` for which `tz.name() == tz_name`, a pointer to `tz`;
- (2.2) — otherwise, if `links` contains an element `tz_l` for which `tz_l.name() == tz_name`, then
a pointer to the element `tz` of zones for which `tz.name() == tz_l.target()`the result of `locate_zone(tz_l.target())`. .[Note 1: A `time_zone_link` specifies an alternative name for a `time_zone`. — end note]
-3- 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]
-?- Remarks: If both `zones` and `links` contain elements that match `tz_name` then it is unspecified whether
&tzorlocate_zone(tz_l.target())is returned.[Drafting note: This gives flexibility how to implement the lookup in `locate_zone`.]
-1- A `time_zone_link` specifies an alternative name for a `time_zone`. `time_zone_links` are constructed when the time zone database is initialized. The name of a `time_zone_link` can be used as an argument to `tzdb::locate_zone` ([time.zone.db.tzdb]). A `time_zone_link` can refer directly to a `time_zone`, or to another `time_zone_link`, forming a chain of links.
-1- Returns: The alternative name for the time zone.string_view name() const noexcept;string_view target() const noexcept;-2- Returns: The name of the `time_zone` for which this `time_zone_link` provides an alternative name or the name of another `time_zone_link`.
[Note 1: `tzdb::locate_zone` follows a chain of links formed when a link's target is the name of a `time_zone_link`, throwing an exception if the chain of links does not terminate in a `time_zone`. — end note]
[ 2025-10-21; Reflector poll. ]
Set priority to 2 after reflector poll. Add Jonathan's comments on the resolution:
The goal of the resolution is to permit `time_zone_link::target` to name another link, and not overspecify `tzdb::locate_zone` to require that `tz_l.target()` names a valid zone `tz`. Considered normatively saying what happens if a link chain doesn't terminate in a zone (like the zic(8) man page does), but that seemed like overspecification. We don't currently say what happens if a non-chained link has an invalid target, it's just covered by `locate_zone` failing to find anything. So just added a note saying bad chains are bad.
Not urgent, as Libstdc++ and libc++ already handle this in some form. Links that use the same name as zones are unlikely to be a problem with the official IANA database, probably only relevant for manually edited data. Likewise for cycles in link chains. Maybe just leave to QoI.
Since October 2022 the IANA Time Zone Database's `tzfile` data format allows a Link to refer to another Link, instead of referring directly to a Zone. The zic(8) man page says:
The TARGET field should appear as the NAME field in some zone line or as the LINK-NAME field in some link line. The LINK-NAME field is used as an alternative name for that zone; it has the same syntax as a zone line's NAME field. Links can chain together, although the behavior is unspecified if a chain of one or more links does not terminate in a Zone name.Because chains of links were introduced to `tzfile` after `chrono::tzdb` was standardized, C++ does not properly support chains of links.
The `time_zone_link::target()` member function is required to return "The name of the `time_zone` for which this `time_zone_link` provides an alternative name." This doesn't allow returning the name of another `time_zone_link`, which implies that the implementation should flatten a series of links so that the target is a `time_zone`. However, this discards information which is present in the `tzdb`, so that the information exposed to a C++ program does not preserve the original structure of a chain of links.
The standard could be adjusted to support chains of links by allowing `time_zone_link::target()` to refer to another link, and then altering the algorithm used by `tzdb::locate_zone(string_view)` to find a `time_zone` from a name that might be a zone or a link.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2025-10-21 15:17:02 | admin | set | messages: + msg15323 |
| 2025-02-22 22:47:24 | admin | set | messages: + msg14651 |
| 2025-02-22 00:00:00 | admin | create | |