std::chrono...o::tai_time)(3)
β¨ std::chrono::from_stream(std::chrono::tai_time) β¨
okay so we're looking at std::chrono...o::tai_time)(3) from the C++ Standard Libary manual (yes, "Libary" is right there in the header, don't come for me π
), and it's all about that one function std::chrono::from_stream(std::chrono::tai_time). bestie, it's giving stream-parsing main-character energy π.
π NAME π
std::chrono::from_stream(std::chrono::tai_time) - std::chrono::from_stream(std::chrono::tai_time)
β¨ Synopsis β¨
the template setup is:
template< class CharT, class Traits, class Duration, class Alloc = std::allocator<CharT> >
and the function is:
std::basic_istream<CharT, Traits>&
from_stream( std::basic_istream<CharT, Traits>& is, const CharT* fmt,
std::chrono::tai_time<Duration>& tp,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr );
this one is (since C++20), periodt π.
so what does it do? it attempts to parse the input stream is into the time point tp according to the format string fmt π.
it behaves as an UnformattedInputFunction, except that it has an unspecified effect on is.gcount() π. after constructing and checking 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 andtpis not modified. no cap, that's the fail state, bestie π.
then there's the format-specifier lore:
- if the format specifier
%Zis used and successfully parsed, the parsed value is assigned to*abbrevifabbrevis not null π¦. - if the format specifier
%zor a modified variant is used and successfully parsed, the parsed value is assigned to*offsetifoffsetis not null, and the parsed offset will be subtracted from the parsed timestamp before the difference is assigned totpπΈ.
π Parameters π
isβ the input stream you're reading from, bestiefmtβ a format string (full breakdown below π)tpβ the time point object that's gonna hold the parse resultabbrevβ if it's not null, this is a pointer to an object that'll hold the time zone abbreviation or name matching the%Zspecifieroffsetβ if it's not null, this is a pointer to an object that'll hold the offset from UTC matching the%zspecifier
β¨ Format string β¨
Okay so the format string is made of zero or more conversion specifiers plus ordinary characters. Every ordinary character β and we're not counting whitespace characters or the terminating null character here β matches one identical character from the input stream. And if the next character on the stream doesn't compare equal? The function just fails. No cap. π
Each whitespace character matches zero or more whitespace characters in the input stream.
Every unmodified conversion specifier starts with a % character, followed by a character that decides what the specifier actually does. Some conversion specifiers have a modified form where an E or O modifier character gets inserted right after the % character. And some have a modified form where a width parameter β given as a positive decimal integer, shown as N below β gets inserted after the % character. Each conversion specifier makes the matched characters get interpreted as parts of date and time types, per the table below. ποΈ
A character sequence in the format string that begins with a % but doesn't match one of the conversion specifiers below? That's interpreted as ordinary characters. Surprise! π
β οΈ Heads up: 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, thenis.setstate(std::ios_base::failbit)is called. So yeah. Pay attention.
The following conversion specifiers are available:
π The basics
%%β 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 is2. 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 isn't otherwise specified (like, 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 is2. 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 is4. 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 is1). The width N specifies the maximum number of characters to read. The default width is2. 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 is2. Leading zeroes are permitted but not required.%e,%Ne,%Oeβ 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 is1. The width N specifies the maximum number of characters to read. The default width is1. Leading zeroes are permitted but not required.%w,%Nw,%Owβ parses the weekday as a decimal number (0-6), where Sunday is0. The width N specifies the maximum number of characters to read. The default width is1. 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 has to satisfy the following requirements:
- Includes January 4
- Includes first Thursday of the year
So with that in mind:
%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 is2. 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 is4. 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 is2. 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 is1). The width N specifies the maximum number of characters to read. The default width is3. 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 week01. Days of the same year prior to that are in week00. The width N specifies the maximum number of characters to read. The default width is2. 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 week01. Days of the same year prior to that are in week00. The width N specifies the maximum number of characters to read. The default width is2. 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 is2. 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 is2. 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 is2. 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 is2if Duration is convertible tostd::chrono::seconds, otherwise it is determined by the decimal precision of Duration and 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.
π Miscellaneous π
okay bestie, hereβs the miscellaneous format-specifier lore drop β every single one, no skipping π
%cβ parses the locale's date and time representation. π°οΈ%Ecβ the modified command: it interprets the locale's alternative date and time representation. β¨%zβ parses the offset from UTC in the format[+|-]hh[mm]. For example,-0430refers to 4 hours 30 minutes behind UTC and04refers to 4 hours ahead of UTC. π%Ez,%Ozβ the modified commands%Ezand%Ozparse the format[+|-]h[h][:mm](i.e., requiring a:between the hours and minutes and making the leading zero for hour optional). π%Zβ parses the time zone abbreviation or name, taken as the longest sequence of characters that only contains the charactersAthroughZ,athroughz,0through9,-,+,_, and/. π¦
π Return Value π
The Return value section is literally just:
is
Thatβs the whole thing. Incomplete-manpage behavior, no cap. ππ
πΈ Example πΈ
This section is incomplete Reason: no example
Not me showing up with zero example content π but that is exactly what the page says, so we keep it. π«Ά
π¦ See Also π¦
parseβ parses a chrono object from a stream (C++20)(function template)β¨
π Category π
* Todo no example
source: http://cppreference.com Β· version/date: 2024.06.10 β bye bestie, go parse something iconic π
β¨
π¦ 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