std::chrono...o::sys_time)(3)
π NAME π
std::chrono::from_stream(std::chrono::sys_time) β literally the std::chrono::from_stream(std::chrono::sys_time) overload, bestie. That's the whole name, no cap. It lives in the C++ Standard Library, section 3 of the manual, iykyk. πΈ
β¨ SYNOPSIS β¨
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,
std::chrono::sys_time<Duration>& tp,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr );
(since C++20) π¦ β yes queen, this one is a C++20 girlie, and that note applies to the whole overload up there, not just the line it's sitting next to in the raw page. π
So like. What does it actually do? It attempts to parse the input stream is into the time point tp according to the format string fmt. That's the whole vibe check. π
It behaves as an UnformattedInputFunction, with one very specific caveat: except that it has an unspecified effect on is.gcount(). So don't come for gcount()'s whole life expecting tea, because the standard is literally not telling you. π
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, then β and this is the important bit, bestie, write it down β is.setstate(std::ios_base::failbit) is called and tp is not modified. Like, not even a little. It stays exactly as it was. She's not getting dragged into your failed parse. π
ββοΈ
β οΈ ok so fr fr: if the parse fails, you getfailbiton the stream and yourtpis left untouched. No partial slay, no half-written timestamp, just failure energy. π
π the %Z and %z situation (iykyk)
Two format specifiers have side quests, and they're both obsessed with your pointer arguments:
%Zβ if the format specifier%Zis used and successfully parsed, the parsed value is assigned to*abbrevifabbrevis not null. (Default isnullptr, so if you didn't pass one, nothing happens. She's chill like that. π«Ά)%z(or a modified variant of it) β 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. π§
Read that last part again because it's giving main character energy: the offset doesn't just get handed to you, it gets subtracted from the parsed timestamp first, and then the resulting difference is what lands in tp. β¨ Math girlie behavior, honestly iconic. π
π bothabbrevandoffsetare the classic "only touch it if it's not null" pattern, so passingnullptr(which is the default for both) means the parse still works fine, you just don't get the extra little gift basket. π
ok that's part one of this page done!! more to come, don't go anywhere, the rest of this overload's lore is literally right there. π
π Parameters π«Ά
Okay so here's who's showing up to the function, bestie β know your cast:
isβ an input stream. The source of truth, the feed, the whole vibe. π§fmtβ a format string (see below β and yes, "below" is a whole journey). πΊοΈtpβ the time point object that's gonna hold the parse result. It's the container, the little guy getting filled up. β¨abbrevβ if it's not null, it's a pointer to an object that will hold the time zone abbreviation or name corresponding to the%Zspecifier. πoffsetβ if it's not null, pointer to an object that will hold the offset from UTC corresponding to the%zspecifier. π
πΈ Format string πΈ
So the format string is literally made of zero or more conversion specifiers plus ordinary characters, and here's how each one behaves, no cap:
Each ordinary character β meaning not whitespace, and not the terminating null character β matches one identical character from the input stream. And if the next character on the stream doesn't compare equal? Boom, the function fails. π Match or miss, babe.
Each whitespace character matches zero or more whitespace characters in the input stream. Flexible queen behavior. π
Each unmodified conversion specifier starts with a % character followed by a character that decides how it behaves. Some specifiers have a modified form where an E or O modifier character gets inserted right after the %. Some have a modified form where a width parameter β given as a positive decimal integer, shown as N below β goes in after the % character. Every conversion specifier makes those matched characters get interpreted as parts of date and time types, per the table below. π
And a heads-up: a character sequence in the format string that starts with a % but doesn't actually match one of the conversion specifiers below? It gets interpreted as ordinary characters. It's just gonna sit there being text. π
β οΈ Warning time, bestie: iffrom_streamfails to parse everything specified by the format string, or if there's insufficient information parsed to specify a complete result, or if parsing discloses contradictory information β thenis.setstate(std::ios_base::failbit)is called. That's the fail bit. It's over. π
The following conversion specifiers are available:
β The little basics
%%β matches a literal%character.%nβ matches one whitespace character.%tβ matches zero or one whitespace character.
π₯ Year
%C,%NCβ 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.%ECβ 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 (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 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β 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. (Yeah,%Odrides along in this group β that's just how the page tells it. π)
π 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
First, the rules, because ISO 8601 has opinions. In ISO 8601, weeks begin with Monday and the first week of the year must satisfy these requirements:
- Includes January 4
- Includes first Thursday of the year
Now the specifiers:
%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 rest of the format-specifier tea β β every one of these is having its own little parse moment, no cap.
%cβ parses the localeβs date and time representation. π%Ecβ the modified command%Ecinterprets the localeβs alternative date and time representation. slay, but make it localized β¨%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%Ozparses the format[+|-]h[h][:mm](i.e., requiring a:between the hours and minutes and making the leading zero for hour optional). yes, the original says βparses,β weβre keeping that energy fr fr π«Ά%Zβ parses the time zone abbreviation or name, taken as the longest sequence of characters that only contains the charactersAthroughZ,athroughz,0through9,-,+,_, and/. iconic character set, honestly π
π Return value π
The page says: is
Thatβs it. Thatβs the whole return value section. not me staring at it like ποΈπποΈ β but we keep the facts exactly as they are.
π Example π
This section is incomplete.
Reason: no example
(cries in no snippet π but we move.)
π See also π
parseβ parses a chrono object from a stream (C++20) (function template)
π·οΈ Category π·οΈ
* Todo no example
xoxo, bestie π β this page came from http://cppreference.com, and the version/date situation is 2024.06.10. stay parsed, stay slay π¦β¨
π¦ 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