std::chrono...:month_day)(3)
π std::chrono::from_stream(std::chrono::month_day) β C++ Standard Library, section 3
okay bestie, we are in part 1 of 3 of this absolute unit of a manual page. buckle up, because this one is all about parsing a month_day out of a stream and it is lowkey iconic. more parts are coming, so do not close the tab. π
πΈ NAME
std::chrono::from_stream(std::chrono::month_day) β and the description is literally std::chrono::from_stream(std::chrono::month_day) again. yes, the same string twice. the duplication is giving copy-paste main character energy, and honestly? we respect it. π
β¨ Synopsis
Defined in header <chrono> β write that down, bestie.
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::month_day& md,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr );
This overload is here since C++20. β¨
So what does it actually do? It attempts to parse the input stream is into the std::chrono::month_day md according to the format string fmt. that is the whole quest. no cap. π¦
Vibe check: it behaves as an UnformattedInputFunction, except that it has an unspecified effect on is.gcount(). so do not count on gcount() being predictable here. it is giving βwe donβt promise anything about that counterβ and we are simply going to accept it. π
After constructing and checking the sentry object, it attempts to parse the input stream is into md according to the format string fmt. yes, sentry object first. it is doing its little checks before the parse era begins. π«Ά
bestie warning: if the parse fails to decode a validmonth_day, thenis.setstate(std::ios_base::failbit)is called, andmdis not modified. so no half-parsed chaos, no accidental glow-up on yourmd. it stays exactly as it was. periodt. π
Now for the format-specifier lore: if the format specifier %Z is used and successfully parsed, the parsed value is assigned to *abbrev if abbrev is not null. and 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. both of those pointers default to nullptr in the synopsis, so you only get the assignment when you actually passed somewhere to put it. iykyk. π
okay that is the synopsis and the core behavior of part 1. part 2 is literally next, bestie β keep scrolling, do not sign off. π
π Parameters π
okay so here's what you're actually handing this thing, bestie:
isβ an input stream π«Άfmtβ a format string (see below π literally the whole personality of this function)mdβ object to hold the parse resultabbrevβ if not null, pointer to an object that will hold the time zone abbreviation or name corresponding to the%Zspecifieroffsetβ if not null, pointer to an object that will hold the offset from UTC corresponding to the%zspecifier
π Format string π
The format string is made of zero or more conversion specifiers plus ordinary characters. that's it, that's the recipe π
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. no vibes-based matching here, it's gotta be a literal match fr fr.
Each whitespace character matches zero or more whitespace characters in the input stream. slay, flexible.
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.
π¨ heads up: 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. no error, no drama, it just becomes plain text.
π also important: 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. so likeβ¦ it will let you know.
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 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 years 1969 to 1999, and values in the range[00, 68]are presumed to refer to the years 2000 to 2068. 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 π
%b,%B,%hβ parses the locale's full or abbreviated case-insensitive month name. (yes, case-insensitive, we're not out here case-shaming anyone β¨)%m,%Nm,%Omβ parses the month as a decimal number (January is 1). 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 π¦
%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.%e,%Ne,%Oeβ also part of the Day lineup, and quick note: 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 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 is 0. 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 π§
ok so in ISO 8601, weeks begin with Monday and the first week of the year has to satisfy these requirements:
- Includes January 4
- Includes first Thursday of the year
the way that's so specific and yet so iconic. periodt.
%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 π₯
%j,%Njβ parses the day of the year as a decimal number (January 1 is 1). 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 week 01. Days of the same year prior to that are in week 00. 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 week 01. Days of the same year prior to that are in week 00. 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 π
%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. (read that again bestie, the width does not touch the other pieces π)%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 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 π¦
okay so these are the leftover format specifiers, and theyβre honestly kind of iconic once you clock the pattern π
%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 π
is
okay so real talk: thatβs literally all it says π the page got cut off mid-thought and Iβm not gonna invent lore for you, bestie. No cap, thatβs the whole section as it survived.
π See also π
parseβ parses a chrono object from a stream (C++20) (function template)
source: cppreference.com Β· version/date: 2024.06.10 Β· page: std::chrono...:month_day)(3) π«Άβ¨
π¦ 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