std::chrono...:local_time)(3)
π std::chrono::from_stream(std::chrono::local_time) π
okay so this is the std::chrono::from_stream(std::chrono::local_time) page from the C++ Standard Libary manual, section 3, bestie. yes, that's the manual name, we're not fixing it, we're just vibing π
πΈ NAME πΈ
std::chrono::from_stream(std::chrono::local_time) β the overload that parses a stream into a std::chrono::local_time, and honestly? it's giving βchrono but make it localβ β¨
β¨ Synopsis β¨
here's the exact signature, no cap β yes, including the (since C++20) tag chillin' in the middle π«Ά
template< class CharT, class Traits, class Duration, class Alloc =
std::allocator<CharT> >
std::basic_istream<CharT, Traits>&
from_stream( std::basic_istream<CharT, Traits>& is, const CharT*
fmt,
(since C++20)
std::chrono::local_time<Duration>& tp,
std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
std::chrono::minutes* offset = nullptr );
okay so here's the tea β: it attempts to parse the input stream is into the time point tp according to the format string fmt. that's literally the whole main character energy of this function π
it behaves as an UnformattedInputFunction, except that it has an unspecified effect on is.gcount(). so like... gcount is lowkey not invited to the group chat, iykyk π
after it constructs and checks the sentry object, it attempts to parse the input stream is into tp according to the format string fmt. if the parse fails to decode a valid time point, is.setstate(std::ios_base::failbit) is called and tp is not modified β periodt, no half-parsed chaos allowed π
if the format specifier %Z is used and successfully parsed, the parsed value is assigned to *abbrev if abbrev is not null. iconic little side quest for timezone abbreviations π¦
if the format specifier %z or a modified variant is used and successfully parsed, the parsed value is assigned to *offset if offset is not null. so yeah, that offset pointer gets the parsed value when it's not null, fr fr π
π PARAMETERS π
okay so hereβs the cast of characters for this function call, bestie:
isβ an input stream.fmtβ a format string (see below π).tpβ time point object to hold the parse result.abbrevβ if not null, pointer to an object that will hold the time zone abbreviation or name corresponding to the%Zspecifier.offsetβ if not null, pointer to an object that will hold the offset from UTC corresponding to the%zspecifier.
π FORMAT STRING π
The format string consists of zero or more conversion specifiers and ordinary characters. Each ordinary character, excluding whitespace characters and the terminating null character, matches one identical character from the input stream, or causes the function to fail if the next character on the stream does not compare equal.
Each whitespace character matches zero or more whitespace characters in the input stream.
Each unmodified conversion specifier begins with a % character followed by a character that determines the behavior of the specifier. Some conversion specifiers have a modified form in which an E or O modifier character is inserted after the % character. Some conversion specifiers have a modified form in which a width parameter given as a positive decimal integer (shown as N below) is inserted after the % character. Each conversion specifier causes the matched characters to be interpreted as parts of date and time types according to the table below.
A character sequence in the format string that begins with a % but does not match one of the conversion specifiers below is interpreted as ordinary characters.
π¨ Iffrom_streamfails to parse everything specified by the format string, or if insufficient information is parsed to specify a complete result, or if parsing discloses contradictory information,is.setstate(std::ios_base::failbit)is called. no cap, thatβs the fail flag doing its thing.
The following conversion specifiers are available:
%%β Matches a literal%character.%nβ Matches one whitespace character.%tβ Matches zero or one whitespace character.
π Year
%C,%NC,%ECβ Parses the century as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required. The modified command%ECinterprets the locale's alternative representation of the century.%y,%Ny,%Ey,%Oyβ Parses the last two decimal digits of the year. If the century is not otherwise specified (e.g. with%C), values in the range[69, 99]are presumed to refer to the years 1969 to 1999, and values in the range[00, 68]are presumed to refer to the years 2000 to 2068. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required. The modified commands%Eyand%Oyinterpret the locale's alternative representation.%Y,%NY,%EYβ Parses the year as a decimal number. The width N specifies the maximum number of characters to read. The default width is 4. Leading zeroes are permitted but not required. The modified command%EYinterprets the locale's alternative representation.
πΈ Month
%b,%B,%hβ Parses the locale's full or abbreviated case-insensitive month name.%m,%Nm,%Omβ Parses the month as a decimal number (January is 1). The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required. The modified command%Ominterprets the locale's alternative representation.
π¦ Day
%d,%Nd,%Odβ Parses the day of month as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.%e,%Ne,%Oeβ this is the group as listed, and the note attached to it says: the modified commands%Odand%Oeinterpret the locale's alternative representation.
π Day of the week
%a,%Aβ Parses the locale's full or abbreviated case-insensitive weekday name.%u,%Nuβ Parses the ISO weekday as a decimal number (1-7), where Monday is 1. The width N specifies the maximum number of characters to read. The default width is 1. Leading zeroes are permitted but not required.%w,%Nw,%Owβ Parses the weekday as a decimal number (0-6), where Sunday is 0. The width N specifies the maximum number of characters to read. The default width is 1. Leading zeroes are permitted but not required. The modified command%Owinterprets the locale's alternative representation.
π§ ISO 8601 week-based year
In ISO 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements:
- Includes January 4
- Includes first Thursday of the year
%g,%Ngβ Parses the last two decimal digits of the ISO 8601 week-based year. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.%G,%NGβ Parses the ISO 8601 week-based year as a decimal number. The width N specifies the maximum number of characters to read. The default width is 4. Leading zeroes are permitted but not required.%V,%NVβ Parses the ISO 8601 week of the year as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required.
β Week/day of the year
%j,%Njβ Parses the day of the year as a decimal number (January 1 is 1). The width N specifies the maximum number of characters to read. The default width is 3. Leading zeroes are permitted but not required.%U,%NU,%OUβ Parses the week number of the year as a decimal number. The first Sunday of the year is the first day of week 01. Days of the same year prior to that are in week 00. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required. The modified command%OUinterprets the locale's alternative representation.%W,%NW,%OWβ Parses the week number of the year as a decimal number. The first Monday of the year is the first day of week 01. Days of the same year prior to that are in week 00. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required. The modified command%OWinterprets the locale's alternative representation.
π Date
%Dβ Equivalent to"%m/%d/%y".%F,%NFβ Equivalent to"%Y-%m-%d". If the width is specified, it is only applied to the%Y.%x,%Exβ Parses the locale's date representation. The modified command%Exinterprets the locale's alternate date representation.
π Time of day
%H,%NH,%OHβ Parses the hour (24-hour clock) as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required. The modified command%OHinterprets the locale's alternative representation.%I,%NI,%OIβ Parses the hour (12-hour clock) as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required. The modified command%OIinterprets the locale's alternative representation.%M,%NM,%OMβ Parses the minute as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2. Leading zeroes are permitted but not required. The modified command%OMinterprets the locale's alternative representation.%S,%NS,%OSβ Parses the second as a decimal number. The width N specifies the maximum number of characters to read. The default width is 2 ifDurationis convertible tostd::chrono::seconds, otherwise it is determined by the decimal precision ofDurationand the field is interpreted as along doublein a fixed format, with the decimal point character determined by the locale (if encountered). Leading zeroes are permitted but not required. The modified command%OSinterprets the locale's alternative representation.%pβ Parses the locale's equivalent of the AM/PM designations associated with a 12-hour clock.%Rβ Equivalent to"%H:%M".%Tβ Equivalent to"%H:%M:%S".%rβ Parses the locale's 12-hour clock time.%X,%EXβ Parses the locale's time representation. The modified command%EXinterprets the locale's alternate time representation.%c,%Ecβ parses the locale's date and time representation. And the modified command%Ecdoes the β¨extraβ¨ thing: it interprets the locale's alternative date and time representation. iykyk π%zβ parses the offset from UTC, in the format[+|-]hh[mm]. So for example-0430refers to 4 hours 30 minutes behind UTC, and04refers to 4 hours ahead of UTC. Little format, big job π«Ά%Ez,%Ozβ these are the modified commands, and they parse the format[+|-]h[h][:mm]. Two things to notice, bestie: it requires a:between the hours and minutes, and it makes the leading zero for the hour optional. So it's lowkey stricter in one place and chiller in another π iconic behavior%Zβ parses the time zone abbreviation or name, taken as the longest sequence of characters that only contains the charactersAthroughZ,athroughz,0through9,-,+,_, and/. That's the whole guest list for this party, no randos allowed π
π Return value
The page here just says is. That's it. That's the whole section π it's giving "sentence that got cut off in the render," so, like, don't come for me, I'm reporting exactly what's on the page fr fr.
π¦ Notes
Okay so this one is important, so listen up: this overload does not subtract the parsed offset (if any) from the parsed timestamp. That's the opposite of what happens with the from_stream overloads for the time_point of other clocks β those ones do subtract it. So the vibe check here is: no offset subtraction, periodt. π
No cap, if you're expecting the offset to be applied for you, this overload will not do it. Don't get caught out π
πΈ Example
This section is incomplete.
Reason: no example.
(Yeah bestie, we're all waiting for the example. The section said it was incomplete, and honestly same. π)
π See also
parseβ parses a chrono object from a stream (C++20) (function template)
π Category
- Todo no example
And that's a wrap on this page, bestie! π Source: http://cppreference.com, version dated 2024.06.10, on the std::chrono...:local_time)(3) page. Go forth and parse your little hearts out πβ¨π§
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms