Skip to content

HotbitsZA/DateHelper

Repository files navigation

DateHelper

DateHelper is a small C++17 date/time helper library built around std::chrono and the bundled Howard Hinnant date.h headers. The project provides a portable V2 API for:

  • creating and formatting timestamps
  • converting to and from std::tm
  • carrying millisecond-aware date values in a simple shared struct
  • computing signed time differences
  • working with local time versus UTC safely

The repository focuses on the portable V2 headers:

  • cDateHelper_V2.h
  • cDateHelper2_V2.h
  • cDateHelperData_V2.h

Why V2

The older DateHelper code path depended on COM/ATL DATE handling and was effectively Windows-only. The V2 API keeps the library usable under modern C++17 toolchains on macOS, Linux, and Windows.

Dependencies

No external package manager dependency is required for the V2 path.

Build

cmake -S . -B build
cmake --build build

This builds the example programs by default.

Usage

Include the front header:

#include "cDateHelper_V2.h"

Create and format a timestamp:

auto candle = CDateTime_V2::EncodeDateTime(2026, 4, 3, 15, 30, 0, 250);
auto text = candle.ToStringFull();   // 2026/04/03 15:30:00.250

Get signed differences:

auto start = CDateTime_V2::EncodeDateTime(2026, 4, 3, 15, 0, 0, 0);
auto end = CDateTime_V2::EncodeDateTime(2026, 4, 3, 15, 0, 1, 500);

auto seconds = end.GetSecondsSince(start, CDateTime_V2::Rounding::Floor);
auto millis = end.GetMilliSecondsSince(start);

Use the shared data contract:

td_datetime_2_val_V2 payload;
payload.tm_year = 126;   // years since 1900
payload.tm_mon = 3;      // April (0-based)
payload.tm_mday = 3;
payload.tm_hour = 15;
payload.tm_min = 30;
payload.tm_sec = 0;
payload.tm_millisec = 250;

auto value = CDateTime2_V2::EncodeDateTime(payload);

Examples

Runnable examples live in examples:

  • basicDateExample_V2.cpp
  • timeReferenceExample_V2.cpp
  • dataContractExample_V2.cpp

Example binaries are built into the build directory:

./build/examples/basicDateExample_V2
./build/examples/timeReferenceExample_V2
./build/examples/dataContractExample_V2

Project Layout

License

This project is licensed under the GNU GPL v3.0. Third-party components keep their own licenses; the bundled date.h sources remain under their upstream terms.

About

`DateHelper` is a small C++17 date/time helper library built around `std::chrono` and the bundled Howard Hinnant `date.h` headers. The project provides a portable V2 API for: - creating and formatting timestamps - converting to and from `std::tm` - carrying millisecond-aware date values in a simple shared struct - computing signed time differences

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages