std::chrono...o::tai_time)(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ 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 and tp is not modified. no cap, that's the fail state, bestie πŸ’€.

then there's 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 πŸ¦‹.
  • 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, and the parsed offset will be subtracted from the parsed timestamp before the difference is assigned to tp 🌸.

πŸŽ€ Parameters πŸŽ€

  • is β€” the input stream you're reading from, bestie
  • fmt β€” a format string (full breakdown below πŸ‘‡)
  • tp β€” the time point object that's gonna hold the parse result
  • abbrev β€” if it's not null, this is a pointer to an object that'll hold the time zone abbreviation or name matching the %Z specifier
  • offset β€” if it's not null, this is a pointer to an object that'll hold the offset from UTC matching the %z specifier

✨ 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: if from_stream fails 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, then is.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 is 2. Leading zeroes are permitted but not required. The modified command %EC interprets 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 is 2. Leading zeroes are permitted but not required. The modified commands %Ey and %Oy interpret 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 %EY interprets 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 %Om interprets 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 β€” the modified commands %Od and %Oe interpret 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 %Ow interprets 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 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 %OU interprets 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 %OW interprets 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 %Ex interprets 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 %OH interprets 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 %OI interprets 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 %OM interprets 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 if Duration is convertible to std::chrono::seconds, otherwise it is determined by the decimal precision of Duration and the field is interpreted as a long double in a fixed format, with the decimal point character determined by the locale (if encountered). Leading zeroes are permitted but not required. The modified command %OS interprets 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 %EX interprets 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, -0430 refers to 4 hours 30 minutes behind UTC and 04 refers to 4 hours ahead of UTC. 🌍
  • %Ez, %Oz β€” the modified commands %Ez and %Oz parse 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 characters A through Z, a through z, 0 through 9, -, +, _, 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