107 lines
4.3 KiB
Markdown
107 lines
4.3 KiB
Markdown
[time.zone.exception]
|
||
|
||
# 30 Time library [[time]](./#time)
|
||
|
||
## 30.11 Time zones [[time.zone]](time.zone#exception)
|
||
|
||
### 30.11.3 Exception classes [time.zone.exception]
|
||
|
||
#### [30.11.3.1](#nonexist) Class nonexistent_local_time [[time.zone.exception.nonexist]](time.zone.exception.nonexist)
|
||
|
||
namespace std::chrono {class nonexistent_local_time : public runtime_error {public:template<class Duration> nonexistent_local_time(const local_time<Duration>& tp, const local_info& i); };}
|
||
|
||
[1](#nonexist-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9096)
|
||
|
||
nonexistent_local_time is thrown when
|
||
an attempt is made
|
||
to convert a non-existent local_time to a sys_time without specifying choose::earliest or choose::latest[.](#nonexist-1.sentence-1)
|
||
|
||
[ð](#lib:nonexistent_local_time,constructor)
|
||
|
||
`template<class Duration>
|
||
nonexistent_local_time(const local_time<Duration>& tp, const local_info& i);
|
||
`
|
||
|
||
[2](#nonexist-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9109)
|
||
|
||
*Preconditions*: i.result == local_info::nonexistent is true[.](#nonexist-2.sentence-1)
|
||
|
||
[3](#nonexist-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9113)
|
||
|
||
*Effects*: Initializes the base class with a sequence of char equivalent to that produced by os.str() initialized as shown below:ostringstream os;
|
||
os << tp << " is in a gap between\n"<< local_seconds{i.first.end.time_since_epoch()} + i.first.offset << ' '<< i.first.abbrev << " and\n"<< local_seconds{i.second.begin.time_since_epoch()} + i.second.offset << ' '<< i.second.abbrev << " which are both equivalent to\n"<< i.first.end << " UTC";
|
||
|
||
[4](#nonexist-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9129)
|
||
|
||
[*Example [1](#nonexist-example-1)*: #include <chrono>#include <iostream>int main() {using namespace std::chrono; try {auto zt = zoned_time{"America/New_York",
|
||
local_days{Sunday[2]/March/2016} + 2h + 30min}; } catch (const nonexistent_local_time& e) { std::cout << e.what() << '\n'; }}
|
||
|
||
Produces the output:
|
||
|
||
```
|
||
2016-03-13 02:30:00 is in a gap between
|
||
2016-03-13 02:00:00 EST and
|
||
2016-03-13 03:00:00 EDT which are both equivalent to
|
||
2016-03-13 07:00:00 UTC
|
||
|
||
```
|
||
|
||
â *end example*]
|
||
|
||
#### [30.11.3.2](#ambig) Class ambiguous_local_time [[time.zone.exception.ambig]](time.zone.exception.ambig)
|
||
|
||
namespace std::chrono {class ambiguous_local_time : public runtime_error {public:template<class Duration> ambiguous_local_time(const local_time<Duration>& tp, const local_info& i); };}
|
||
|
||
[1](#ambig-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9169)
|
||
|
||
ambiguous_local_time is thrown when
|
||
an attempt is made
|
||
to convert an ambiguous local_time to a sys_time without specifying choose::earliest or choose::latest[.](#ambig-1.sentence-1)
|
||
|
||
[ð](#lib:ambiguous_local_time,constructor)
|
||
|
||
`template<class Duration>
|
||
ambiguous_local_time(const local_time<Duration>& tp, const local_info& i);
|
||
`
|
||
|
||
[2](#ambig-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9182)
|
||
|
||
*Preconditions*: i.result == local_info::ambiguous is true[.](#ambig-2.sentence-1)
|
||
|
||
[3](#ambig-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9186)
|
||
|
||
*Effects*: Initializes the base class with a sequence of char equivalent to that produced by os.str() initialized as shown below:ostringstream os;
|
||
os << tp << " is ambiguous. It could be\n"<< tp << ' ' << i.first.abbrev << " == "<< tp - i.first.offset << " UTC or\n"<< tp << ' ' << i.second.abbrev << " == "<< tp - i.second.offset << " UTC";
|
||
|
||
[4](#ambig-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9200)
|
||
|
||
[*Example [1](#ambig-example-1)*: #include <chrono>#include <iostream>int main() {using namespace std::chrono; try {auto zt = zoned_time{"America/New_York",
|
||
local_days{Sunday[1]/November/2016} + 1h + 30min}; } catch (const ambiguous_local_time& e) { std::cout << e.what() << '\n'; }}
|
||
|
||
Produces the output:
|
||
|
||
```
|
||
2016-11-06 01:30:00 is ambiguous. It could be
|
||
2016-11-06 01:30:00 EDT == 2016-11-06 05:30:00 UTC or
|
||
2016-11-06 01:30:00 EST == 2016-11-06 06:30:00 UTC
|
||
|
||
```
|
||
|
||
â *end example*]
|