std::chrono...ono::month)(3)

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

okay so this is the C++ Standard Library manpage for std::chrono::from_stream(std::chrono::month), and bestie, it's giving time-parsing realness πŸ’…

🌸 NAME 🌸

std::chrono::from_stream(std::chrono::month) - std::chrono::from_stream(std::chrono::month)

✨ Synopsis ✨

Defined in header <chrono>

          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,
       (since C++20)
                           std::chrono::month& m,
                           std::basic_string<CharT, Traits, Alloc>* abbrev =
          nullptr,

                           std::chrono::minutes* offset = nullptr );

so what it does is try to parse the input stream is into the std::chrono::month object m, using the format string fmt as its guide. πŸ’…

It behaves like an UnformattedInputFunction, except that it has an unspecified effect on is.gcount(). (iykyk, don't rely on gcount here, bestie.)

After it constructs and checks the sentry object, it tries to parse is into m according to fmt. If the parse fails to decode a valid month, it calls is.setstate(std::ios_base::failbit) and m is not modified β€” so no half-parsed mess, periodt. 🫢

If the format specifier %Z is used and successfully parsed, the parsed value gets assigned to *abbrev as long as abbrev is not null. And if the format specifier %z or a modified variant is used and successfully parsed, the parsed value gets assigned to *offset as long as offset is not null. ✨


part 2 is coming, don't touch that dial πŸ’–

πŸ“‹ Parameters

  • is β€” the input stream, aka the thing you're reading from 🫢
  • fmt β€” the format string (full breakdown below, bestie, it's giving long)
  • m β€” the object that's gonna hold the parse result
  • abbrev β€” if it's not null, this is a pointer to an object that will hold the time zone abbreviation or name that matches up with the %Z specifier
  • offset β€” if it's not null, this is a pointer to an object that will hold the offset from UTC that matches up with the %z specifier

✨ Format string ✨

Okay so the format string is made of zero or more conversion specifiers plus ordinary characters. Lowkey simple, highkey powerful.

Every ordinary character β€” and that means every one except whitespace characters and the terminating null character β€” matches exactly one identical character from the input stream. If the next character on the stream does not compare equal, the function just fails. Periodt. πŸ’€

Every 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 what that specifier actually does. Some conversion specifiers have a modified form where an E or O modifier character gets inserted right after the % character. Other conversion specifiers have a modified form where a width parameter β€” given as a positive decimal integer, shown as N below β€” gets inserted right 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 starts with % but doesn't match any of the conversion specifiers listed below gets interpreted as ordinary characters. No cap.

🚨 Real talk: 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. That's the fail state, bestie. It's not a vibe.

The following conversion specifiers are available:

🌈 The universal 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 these requirements:

  • Includes January 4
  • Includes first Thursday of the year

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 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. 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 (the little odds-and-ends corner) πŸ’…

Okay bestie, these are the last few format specifiers and honestly they're giving "miscellaneous but make it iconic" ✨

  • %c, %Ec β€” %c parses the locale's date and time representation. The modified command %Ec interprets the locale's alternative date and time representation. Same vibe, different outfit 🫢
  • %z, %Ez, %Oz β€” these parse the offset from UTC, in the format [+|-]hh[mm]. Like, for example, -0430 refers to 4 hours 30 minutes behind UTC, and 04 refers to 4 hours ahead of UTC 🌍 The modified commands %Ez and %Oz parse the format [+|-]h[h][:mm] instead β€” i.e., they require a : between the hours and minutes, and they make the leading zero for the hour optional. Fancy πŸ’…
  • %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 /. That's the whole guest list for this party, no randoms allowed πŸš«πŸŽ‰

πŸ’– Return value

Okay so. The page says:

is

That's it. That's the whole return value section. Just the word is. Not me screaming 😭 Bestie I am not making anything up here β€” this is genuinely all the page gives us, so I'm passing it to you exactly as it landed. No cap. 🫠


🌈 See also

  • parse β€” parses a chrono object from a stream. Marked (C++20) and it's a (function template) πŸ‘‘ The main character of the see-also section, fr fr.

Real talk: that return value section is a whole mood and a half, but it's literally what the page contains, so I'm keeping it verbatim instead of guessing. Don't come for me πŸ’€

And that's a wrap on this page, bestie! πŸ¦‹ This was std::chrono...ono::month)(3), straight from the fine folks at http://cppreference.com, dated 2024.06.10 β€” go drink some water and go parse something cute πŸŒΈπŸ’œ

πŸ“¦ where this page comes from