std::filesy...le_time_type(3)

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

πŸ’… std::filesystem::file_time_type β€” the C++ Standard Library tea (from the std::filesy...le_time_type(3) page)

okay so bestie, welcome to the manual page for std::filesystem::file_time_type β€” yeah the header got truncated in the terminal and it's giving "my name is a mystery" but it's literally std::filesystem::file_time_type from the C++ Standard Library. no cap. let's get into it πŸ’–


✨ NAME ✨

std::filesystem::file_time_type β€” and yes that's literally the whole name section, std::filesystem::file_time_type. iconic, no notes. πŸ‘‘


🌸 SYNOPSIS 🌸

okay so here's the whole vibe, and the way it's defined changed in C++20 so pay attention bestie:

Defined in the header <filesystem>:

using file_time_type = std::chrono::time_point</*trivial-clock*/>;

(since C++17) β€” and also (until C++20) because this version is only valid up to that point.

then, starting in C++20, it becomes:

using file_time_type =
std::chrono::time_point<std::chrono::file_clock>;

(since C++20) πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

literally what it says on the tin: it Represents file time. that's the whole job. main character energy tbh. ✨

and about that mysterious trivial-clock β€” bestie it's an implementation-defined type, meaning your implementation gets to pick it, and it satisfies TrivialClock and is sufficient to represent the resolution and range of the file time values offered by the filesystem. that whole trivial-clock explanation is (until C++20), so once you're on C++20 it's std::chrono::file_clock and we move on πŸ’…


πŸŽ€ EXAMPLE πŸŽ€

fr fr the code says // Run this code at the top, so here's the whole thing verbatim, don't touch anything:

#include <chrono>
#include <filesystem>
#include <format>
#include <fstream>
#include <iostream>

using namespace std::chrono_literals;

int main()
{
    auto p = std::filesystem::temp_directory_path() / "example.bin";
    std::ofstream{p.c_str()}.put('a'); // create file

    std::filesystem::file_time_type ftime =
std::filesystem::last_write_time(p);
    std::cout << std::format("File write time is {}\n", ftime);

    // move file write time 1 hour to the future
    std::filesystem::last_write_time(p, ftime + 1h);

    // read back from the filesystem
    ftime = std::filesystem::last_write_time(p);
    std::cout << std::format("File write time is {}\n", ftime);

    std::filesystem::remove(p);
}

⭐ Possible output

no cap, this is what it can spit out:

File write time is 2023-09-04 19:33:24.702639224
File write time is 2023-09-04 20:33:24.702639224

see that? one hour apart. the 1h moved it, periodt. πŸ•


πŸ¦‹ SEE ALSO πŸ¦‹

  • last_write_time β€” gets or sets the time of the last data modification (C++17) (function) πŸ’–

ngl this one's short and sweet, but don't sleep on it β€” this type is literally how your filesystem timestamps get stored, so treat it with respect 🫢

okay bye bestie, mwah πŸ˜­πŸ’… β€” this page came from http://cppreference.com, dated 2024.06.10, and the footer title was std::filesy...le_time_type(3) (truncated again, we love that for us 🌈). go touch some files. πŸ“

πŸ“¦ where this page comes from