std::chrono...hrono::year)(3)
π C++ Standard Library π β a lil page about std::chrono::from_stream(std::chrono::year)
okay so bestie, welcome to the group chat. this is the manual page for std::chrono::from_stream(std::chrono::year), straight out of the C++ Standard Library, and it's giving "niche but iconic." part 1 of 3, so buckle up β more coming after this, no sign-off, we're not done yet π
β¨ NAME β¨
std::chrono::from_stream(std::chrono::year) β like, that's the whole name, twice, because the manpage said it twice and I would never gatekeep a single crumb of info from you π«Ά
std::chrono::from_stream(std::chrono::year)
πΈ Synopsis πΈ
so first things first, it lives here:
Defined in header <chrono>
and the template situation is this, literally copy-paste it exactly, don't freestyle:
template< class CharT, class Traits, class Alloc = std::allocator<CharT> >
std::basic_istream<CharT, Traits>&
from_stream( std::basic_istream<CharT, Traits>& is, const CharT* fmt,
std::chrono::year& y,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr );
(since C++20) β yes queen, she's a modern girlie β¨
π¦ okay but what does it DO π¦
So basically: it attempts to parse the input stream is into the std::chrono::year y, according to the format string fmt. that's the whole vibe. parse β year β slay.
It behaves as an UnformattedInputFunction, except β and this is the important lil caveat β it has an unspecified effect on is.gcount(). like, don't count on gcount, bestie, it's not that kind of function π
After constructing and checking the sentry object, it attempts to parse the input stream is into y according to the format string fmt. and if the parse fails to decode a valid year? tragic. is.setstate(std::ios_base::failbit) gets called and y is not modified. so your year stays exactly where it was, untouched, unbothered, main character energy π
π the %Z and %z situation π
this part is lowkey the most important, so pay attention π₯
- If the format specifier
%Zis used and successfully parsed, the parsed value is assigned to*abbrevβ but only ifabbrevis not null. no abbrev, no assign. simple as. - If the format specifier
%zor a modified variant is used and successfully parsed, the parsed value is assigned to*offsetβ but only ifoffsetis not null. same rules, bestie.
β οΈ reminder: "ifabbrevis not null" and "ifoffsetis not null" are doing a LOT of heavy lifting in those sentences. the default for both isnullptr, so if you don't pass them, nothing gets written. periodt.
k that's part 1, more coming, don't go anywhere ππ§
π Parameters π
okay bestie, hereβs the whole intake list β no cap, every single one:
isβ an input stream πfmtβ a format string (peep the next section π)yβ the object that holds the parse resultabbrevβ if itβs not null, a pointer to an object that will hold the time zone abbreviation or name corresponding to the%Zspecifieroffsetβ if itβs not null, a pointer to an object that will hold the offset from UTC corresponding to the%zspecifier
π Format string π
The format string is literally zero or more conversion specifiers plus ordinary characters. Itβs giving build-your-own-parser, and honestly? iconic.
- 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
EorOmodifier 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
Nbelow) 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. slay, it just vibes as text.
π¨ 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.
β¨ The conversion specifiers β¨
%%β matches a literal%character.%nβ matches one whitespace character.%tβ matches zero or one whitespace character.
Year era π
%C,%NC,%ECβ parses the century as a decimal number. The widthNspecifies 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 is not otherwise specified (e.g. with%C), values in the range[69, 99]are presumed to refer to the years1969to1999, and values in the range[00, 68]are presumed to refer to the years2000to2068. The widthNspecifies 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 widthNspecifies 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 moment πΈ
%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 widthNspecifies 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 energy π
%d,%Nd,%Odβ parses the day of month as a decimal number. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified command%Odinterprets the localeβs alternative representation.%e,%Ne,%Oeβ these sit in the day-of-month group too. The modified commands%Odand%Oeinterpret the localeβs alternative representation.
Day of the week files ποΈ
%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 widthNspecifies 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 widthNspecifies 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, periodt π¦
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 widthNspecifies 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 widthNspecifies 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 widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required.
Week/day of the year vibes π
%j,%Njβ parses the day of the year as a decimal number (January 1 is1). The widthNspecifies 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 widthNspecifies 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 widthNspecifies 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 section, weβre so back π
%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, main character energy β°
%H,%NH,%OHβ parses the hour (24-hour clock) as a decimal number. The widthNspecifies 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 widthNspecifies 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 widthNspecifies 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 widthNspecifies the maximum number of characters to read. The default width is2. 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 π
These format-command besties are all about parsing date/time vibes, and every little character matters π
%cβ Parses the locale's date and time representation. ποΈ%Ecβ The modified command%Ecinterprets 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 situation is literally just:
is
That's the whole thing, bestie β no extra lore in this part π
π¦ See also π¦
parseβ parses a chrono object from a stream (C++20) (function template). π
Okay, part 3 wrap-up time π
Big source shoutout to cppreference.com, version/date 2024.06.10, and the footer vibe std::chrono...hrono::year)(3) β mwah ππ
π¦ 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