std::chrono::file_clock(3)

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

πŸ’… std::chrono::file_clock β€” yeah bestie, it's a cppreference.com page (2024.06.10) and the manpage is literally called std::chrono::file_clock(3), okurrr

okay so picture this: you're deep in C++ Standard Library land and you meet std::chrono::file_clock. She's the clock that the filesystem girlies use. Let me introduce you properly πŸ’–


✨ NAME ✨

std::chrono::file_clock β€” bestie, it's literally std::chrono::file_clock. That's the name. That's the whole thing. Iconic behaviour honestly πŸ‘‘


🌸 SYNOPSIS 🌸

Defined in header <chrono>:

using file_clock = /* see below */;  (since C++20)

std::chrono::file_clock is an alias for the clock used for std::filesystem::file_time_type. Her epoch? Unspecified. We don't know her birthday and honestly we're not asking πŸŽ€

file_clock meets the TrivialClock requirements. Slay. Requirements: met. Periodt πŸ’…


πŸ’œ MEMBER TYPES πŸ’œ

Every one of these cuties, accounted for:

  • rep β€” a signed arithmetic type representing the number of ticks in the clock's duration πŸ•°οΈ
  • period β€” a std::ratio type representing the tick period of the clock, in seconds ⏱️
  • duration β€” std::chrono::duration<rep, period>, and yeah she's capable of representing negative durations, she contains multitudes 😭
  • time_point β€” std::chrono::time_point<std::chrono::file_clock> ⭐

πŸ¦‹ MEMBER CONSTANTS πŸ¦‹

  • constexpr bool is_steady [static] β€” true if the time between ticks is always constant, i.e. calls to now() return values that increase monotonically even in case of some external clock adjustment, otherwise false. It's a public static member constant, no cap 🌈
Not me explaining is_steady like it's a vibe check β€” it literally is one. Is the tick interval constant? Is now() monotonic even if something externally messes with the clock? That's the whole question, bestie 🫢

πŸ‘‘ MEMBER FUNCTIONS πŸ‘‘

okay so here's the tea β€” file_clock provides exactly one of the following two pairs of static member functions:

  • to_utc and from_utc; or
  • to_sys and from_sys.

One pair. Not both. Exactly one. Choose your fighter 🧚

Here's everyone in the lineup:

  • now [static] β€” returns a std::chrono::time_point representing the current point in time. Public static member function, serving main character energy ✨
  • to_utc / from_utc [static] (optional) β€” converts between file_time and utc_time. Public static member functions πŸ’–
  • to_sys / from_sys [static] (optional) β€” converts between file_time and sys_time. Public static member functions πŸ”₯
Heads up β€” to_utc/from_utc and to_sys/from_sys are marked (optional) in the docs, and remember the rule from up top: she ships with exactly one of those two pairs. Don't come for me if your implementation picked the other one, iykyk πŸ™ˆ

πŸ“ THE CUTE SIGN-OFF πŸ“

That's the whole page babes β€” sourced from <rainbow>http://cppreference.com</rainbow>, dated <yellow>2024.06.10</yellow>, and officially filed under std::chrono::file_clock(3). Go forth and timestamp your files, you beautiful genius πŸ’…πŸŽ€πŸŒ·

πŸ“¦ where this page comes from