Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_zone_offset.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2#pragma once
3#ifndef _TIME_SHIELD_TIME_ZONE_OFFSET_HPP_INCLUDED
4#define _TIME_SHIELD_TIME_ZONE_OFFSET_HPP_INCLUDED
5
19
20#include "config.hpp"
21#include "types.hpp"
22#include "time_conversions.hpp"
23#include "time_zone_struct.hpp"
24
25namespace time_shield {
26
29
34 TIME_SHIELD_CONSTEXPR inline ts_t to_utc(ts_t local, tz_t utc_offset) noexcept {
35 return local == ERROR_TIMESTAMP ? ERROR_TIMESTAMP
36 : local - static_cast<ts_t>(utc_offset);
37 }
38
43 TIME_SHIELD_CONSTEXPR inline ts_t to_local(ts_t utc, tz_t utc_offset) noexcept {
44 return utc == ERROR_TIMESTAMP ? ERROR_TIMESTAMP
45 : utc + static_cast<ts_t>(utc_offset);
46 }
47
52 TIME_SHIELD_CONSTEXPR inline ts_ms_t to_utc_ms(ts_ms_t local_ms, tz_t utc_offset) noexcept {
53 return local_ms == ERROR_TIMESTAMP ? ERROR_TIMESTAMP
54 : local_ms - sec_to_ms<ts_ms_t, tz_t>(utc_offset);
55 }
56
61 TIME_SHIELD_CONSTEXPR inline ts_ms_t to_local_ms(ts_ms_t utc_ms, tz_t utc_offset) noexcept {
62 return utc_ms == ERROR_TIMESTAMP ? ERROR_TIMESTAMP
63 : utc_ms + sec_to_ms<ts_ms_t, tz_t>(utc_offset);
64 }
65
69 TIME_SHIELD_CONSTEXPR inline tz_t utc_offset_of(const TimeZoneStruct& tz) noexcept {
71 }
72
74
75} // namespace time_shield
76
77#endif
Configuration macros for the library.
constexpr int64_t ERROR_TIMESTAMP
Error timestamp value.
TIME_SHIELD_CONSTEXPR tz_t utc_offset_of(const TimeZoneStruct &tz) noexcept
Extract numeric UTC offset (in seconds) from TimeZoneStruct.
TIME_SHIELD_CONSTEXPR ts_t to_utc(ts_t local, tz_t utc_offset) noexcept
Convert local timestamp (seconds) to UTC using UTC offset.
TIME_SHIELD_CONSTEXPR ts_t to_local(ts_t utc, tz_t utc_offset) noexcept
Convert UTC timestamp (seconds) to local time using UTC offset.
TIME_SHIELD_CONSTEXPR ts_ms_t to_local_ms(ts_ms_t utc_ms, tz_t utc_offset) noexcept
Convert UTC timestamp (milliseconds) to local time using UTC offset.
TIME_SHIELD_CONSTEXPR ts_ms_t to_utc_ms(ts_ms_t local_ms, tz_t utc_offset) noexcept
Convert local timestamp (milliseconds) to UTC using UTC offset.
constexpr T1 sec_to_ms(T2 ts) noexcept
Converts a timestamp from seconds to milliseconds.
TIME_SHIELD_CONSTEXPR tz_t time_zone_struct_to_offset(const TimeZoneStruct &tz) noexcept
Convert a TimeZoneStruct to a numeric UTC offset (seconds).
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
Definition types.hpp:48
int32_t tz_t
Time zone offset in minutes from UTC (e.g., +180 = UTC+3).
Definition types.hpp:60
int64_t ts_ms_t
Unix timestamp in milliseconds since epoch.
Definition types.hpp:49
Main namespace for the Time Shield library.
Structure to represent time zone information.
Umbrella header for time conversion functions.
Header for time zone structure and related functions.
Type definitions for time-related units and formats.