std::chrono...s_local_time(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

okay bestie, you're in the C++ Standard Libary manual on page std::chrono...s_local_time(3) β€” and this whole page is about std::chrono::ambiguous_local_time. it's giving β€œtime zones said both, actually” energy. πŸ•°οΈπŸ’…

πŸ’– NAME πŸ’–

std::chrono::ambiguous_local_time β€” std::chrono::ambiguous_local_time. yes bestie, that's the name, twice, and it's the exception type for ambiguous local-time conversions. no cap.

✨ Synopsis ✨

Defined in header <chrono>:

Defined in header <chrono>
class ambiguous_local_time;  (since C++20)

Defines a type of object to be thrown as exception to report that an attempt was made to convert an ambiguous std::chrono::local_time to a std::chrono::sys_time without specifying a std::chrono::choose (such as choose::earliest or choose::latest). periodt.

This exception is thrown by std::chrono::time_zone::to_sys and functions that call it (such as the constructors of std::chrono::zoned_time that take a std::chrono::local_time). lowkey iconic of it to show up exactly where the time-zone math gets messy. πŸ¦‹

The page also has an inheritance diagram, and the image filename is literally this: std-chrono-ambiguous local time-inheritance.svg β€” that's the Inheritance diagram label, bestie. keep the spaces exactly.

🫢 Member functions 🫢

  • constructor β€” constructs the exception object (public member function)
  • operator= β€” replaces the exception object (public member function)
  • what β€” returns the explanatory string (public member function)

πŸŽ€ std::chrono::ambiguous_local_time::ambiguous_local_time πŸŽ€

the signature is this, overloads and all:

template< class Duration >

ambiguous_local_time( const std::chrono::local_time<Duration>& tp,
                      const std::chrono::local_info& i );  (1) (since C++20)

ambiguous_local_time( const ambiguous_local_time& other )  (2) (since C++20)
    noexcept;

Constructs the exception object.

  1. The explanatory string returned by what() is equivalent to that produced by os.str() after the following code:
std::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";
⚠️ bestie, the behavior is undefined if i.result != std::chrono::local_info::ambiguous. undefined behavior is the final boss β€” do not test it. πŸ’€
  1. Copy constructor. If *this and other both have dynamic type std::chrono::ambiguous_local_time then std::strcmp(what(), other.what()) == 0.

πŸ’… Parameters πŸ’…

  • tp β€” the time point for which conversion was attempted
  • i β€” a std::chrono::local_info describing the result of the conversion attempt
  • other β€” another ambiguous_local_time to copy

😭 Exceptions 😭

May throw std::bad_alloc.

πŸ“ Notes πŸ“

Because copying a standard library class derived from std::exception is not permitted to throw exceptions, this message is typically stored internally as a separately-allocated reference-counted string. that's the note, bestie β€” it's allocated separately so copying stays noexcept-ish in spirit.

πŸŽ€ std::chrono::ambiguous_locale_time::operator= πŸŽ€

yes, the page really spells this one ambiguous_locale_time with an e here, bestie β€” it's right there in the original, so keep it exactly. πŸ™ˆ
ambiguous_locale_time& operator=( const ambiguous_locale_time& other ) noexcept;  (since C++20)

Assigns the contents with those of other. If *this and other both have dynamic type std::chrono::ambiguous_locale_time then std::strcmp(what(), other.what()) == 0 after assignment.

πŸ“ Parameters πŸ“

  • other β€” another exception object to assign with

πŸ‘‘ Return value πŸ‘‘

*this

πŸŽ€ std::chrono::ambiguous_locale_time::what πŸŽ€

virtual const char* what() const noexcept;  (since C++20)

Returns the explanatory string.

🌸 Parameters 🌸

(none)

⭐ Return value ⭐

Pointer to a null-terminated string with explanatory information. The string is suitable for conversion and display as a std::wstring. The pointer is guaranteed to be valid at least until the exception object from which it is obtained is destroyed, or until a non-const member function (e.g. copy assignment operator) on the exception object is called.

🧚 Notes 🧚

Implementations are allowed but not required to override what().

🌈 Inherited from std::runtime_error 🌈

🌈 Inherited from std::exception 🌈

🫢 Member functions 🫢

  • destructor β€” destroys the exception object [virtual] (virtual public member function of std::exception)
  • what β€” returns an explanatory string [virtual] (virtual public member function of std::exception)

πŸ‘€ See also πŸ‘€

  • nonexistent_local_time β€” exception thrown to report that a local time is nonexistent (C++20) (class)

source/version/date from the footer, bestie: http://cppreference.com, 2024.06.10, and std::chrono...s_local_time(3). go forth and disambiguate responsibly πŸ’–βœ¨

πŸ“¦ where this page comes from