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

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 <iostream>
#include "time_shield.hpp"
int main() {
// Get the current timestamp
tsh::ts_t current_ts = tsh::timestamp(); // or ts();
// Calculate the timestamp for the end of the current year
tsh::ts_t future_ts = tsh::end_of_year(current_ts);
// Calculate the number of days between current timestamp and the future timestamp
int days = tsh::get_days_difference(current_ts, future_ts); // or days(current_ts, future_ts);
std::cout << "Days until end of year: " << days << std::endl;
// Convert the future timestamp to a formatted string in ISO8601 format
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;
}
// Convert the milliseconds timestamp to a formatted string in ISO8601 UTC format
formatted_time = tsh::to_iso8601_utc_str_ms(ts_ms);
// Output the formatted time
std::cout << "Future time: " << formatted_time << std::endl;
return 0;
}
int64_t ts_t
Integer timestamp type.
Definition types.hpp:15
int64_t ts_ms_t
Integer timestamp milliseconds type.
Definition types.hpp:16
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).
constexpr const T get_days_difference(const ts_t &start, const ts_t &stop) noexcept
Get the number of days between two timestamps.
const std::string to_iso8601_utc_str_ms(const ts_ms_t &ts_ms)
Converts a timestamp in milliseconds to an ISO8601 string in UTC format.
const ts_t timestamp() noexcept
Get the current UTC timestamp in seconds.
TIME_SHIELD_CONSTEXPR ts_t end_of_year(const ts_t &ts=ts())
Get the end-of-year timestamp.
const std::string to_iso8601_str(const T &ts)
Converts a timestamp to an ISO8601 string.
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.