Skip to content

mguludag/chrono_parse

Repository files navigation

chrono_parse

parse date and times with {fmt} style intostd::chrono::time_point {WIP}

Fetch library with CMake

include(FetchContent)

FetchContent_Declare(
  chrono_parse
  GIT_REPOSITORY https://github.com/mguludag/chrono_parse.git
  GIT_TAG main # or the specific tag or branch you want to use
)

FetchContent_MakeAvailable(chrono_parse)

#...

target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE mgutility::chrono_parse)
#include "mgutility/chrono/parse.hpp"

// {fmt} for printing
#include <fmt/chrono.h>
#include <fmt/format.h>

int main() {
    const auto chrono_time = mgutility::chrono::parse("{:%FT%T.%f%z}", "2023-04-16T00:05:23.999+0100");

    fmt::print("{:%F %T}\n", chrono_time); // prints 2023-04-15 23:05:23.999000000 ({fmt} trunk version)
}

Format specifiers

Format Specifier Explanation
%Y parses year as a decimal number, e.g. 2023
%m parses month as a decimal number, e.g. 05
%d parses day as a decimal number, e.g. 14
%H parses hour as a decimal number, e.g. 16
%M parses minute as a decimal number, e.g. 31
%S parses second as a decimal number, e.g. 59
%F parses year-month-day as an iso8601 date, e.g. 2023-05-04
%T parses hour:minute:second as an iso8601 time, e.g. 16:31:59
%f parses (milli/micro/nano)seconds as a decimal number, e.g. 869
%z parses timezone as a decimal number, e.g. +0100 or -01:00 or Z
%p parses AM/PM e.g. AM or PM
  • Performance is ~20x faster than std::get_time + std::mktime.
FuYJ4VJsqNsVqQ2Z92zbyToPDAA clang 17 libc++ c++23 -OFast
37g7u6VRsTnA-NuvD_QuKdbo6TA clang 17 libstdc++ c++23 -OFast
6O2Ctb9wRnkvx_kHeq40xbYJu6A gcc 13.2 libstdc++ c++23 -OFast

About

parse date_times with {fmt} style into std::chrono::time_point {WIP}

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published