Time Shield Library
C++ library for working with time
|
Version: 1.0.2
The Time Shield Library is a comprehensive C++ library designed for time manipulation, formatting, and conversion. It was built for practical and engineering tasks, especially in constrained or performance-critical environments.
Unlike std::chrono
or more academic libraries like HowardHinnant/date
, Time Shield is designed to be simple, portable, and suitable for scenarios like logging, serialization, MQL5 usage, and date/time formatting.
int64_t
, double
) like ts_t
, fts_t
for timestamps — easy to serialize and store.<cstdint>
.NtpClient
) are isolated and optional.Compile-time macros in time_shield/config.hpp
allow adapting the library to the target platform and toggling optional modules:
TIME_SHIELD_PLATFORM_WINDOWS
/ TIME_SHIELD_PLATFORM_UNIX
— platform detection.TIME_SHIELD_HAS_WINSOCK
— WinSock availability.TIME_SHIELD_ENABLE_NTP_CLIENT
— builds the NTP client when set to 1
.All public symbols are declared inside the time_shield
namespace.
ts_t
represents Unix time in seconds as a signed 64-bit integer with microsecond precision available through conversions.fts_t
stores time as double precision seconds; conversions maintain microsecond accuracy.std::string
rely on the caller for allocations.Here is a simple demonstration:
Additional example files are located in the examples/
folder:
time_utils_example.cpp
— get timestamps and partstime_formatting_example.cpp
— to_string, ISO8601, MQL5time_parser_example.cpp
— parse ISO8601time_conversions_example.cpp
— convert between formatstime_zone_conversions_example.cpp
— CET/EET ↔ GMTntp_client_example.cpp
— NTP sync (Windows-only)find_package
After installing the library (e.g., via cmake --install
), locate it with find_package
:
add_subdirectory
Vendor the library as a submodule:
Then include it:
Install via a local overlay port:
Use the vcpkg toolchain when configuring CMake:
The port is intended to be upstreamed to microsoft/vcpkg.
For MQL5/MetaTrader, run install_mql5.bat
to copy the .mqh
files to your include directory.
To build the C++ examples use the helper scripts:
build-examples.bat
for Windowsbuild_examples.sh
for Linux/macOSbuild-cb.bat
to generate a Code::Blocks projectPlatform | Compilers | C++ Standards |
---|---|---|
Windows | MSVC, ClangCL | 11, 14, 17 |
Linux | GCC, Clang | 11, 14, 17 |
macOS | Apple Clang | 11, 14, 17 |
The latest generated API reference is available at newyaroslav.github.io/time-shield-cpp.
Time Shield Library GitHub repository
This library is licensed under the MIT License. See the LICENSE file for more details.