Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
Time Shield Library

Version: 1.0.0

Introduction

The Time Shield Library is a comprehensive C++ library designed for time manipulation, formatting, and conversion. This library aims to provide a robust and flexible set of tools for handling various time-related tasks with ease.

Features

  • Validation of dates and times
  • Time and date formatting
  • Time zone calculations
  • Conversion between different time representations
  • Utilities for time manipulation

Usage

#include <time_shield.hpp>
int main() {
tsh::ts_t current_ts = tsh::timestamp();
tsh::ts_t future_ts = tsh::end_of_year(current_ts);
int days = tsh::get_days_difference(current_ts, future_ts);
std::cout << "Days until end of year: " << days << std::endl;
std::string formatted_time = tsh::to_iso8601_str(future_ts);
tsh::ts_ms_t ts_ms = 0;
if (!tsh::str_to_ts_ms(formatted_time, ts_ms)) {
std::cout << "Error occurred while parsing ISO8601 string" << std::endl;
return -1;
}
formatted_time = tsh::to_iso8601_utc_ms(ts_ms);
std::cout << "Future time: " << formatted_time << std::endl;
return 0;
}
constexpr const T get_days_difference(ts_t start, ts_t stop) noexcept
Get the number of days between two timestamps.
TIME_SHIELD_CONSTEXPR ts_t end_of_year(ts_t ts=ts())
Get the end-of-year timestamp.
const std::string to_iso8601_utc_ms(ts_ms_t ts_ms)
Converts a timestamp in milliseconds to an ISO8601 string in UTC format.
const bool str_to_ts_ms(const std::string &str, ts_ms_t &ts)
Convert an ISO8601 string to a millisecond timestamp (ts_ms_t).
int64_t ts_t
Type for representing timestamps in seconds.
Definition types.hpp:34
int64_t ts_ms_t
Type for representing timestamps in milliseconds.
Definition types.hpp:35
const ts_t timestamp() noexcept
Get the current UTC timestamp in seconds.
Main header file for the Time Shield library.

Installation

To use the Time Shield Library in your project, include the header file time_shield.hpp in your source code. Ensure that your project is set up to compile with standards from C++11 to C++17.

Repository

Time Shield Library GitHub repository

License

This library is licensed under the MIT License. See the LICENSE file for more details.