Time Shield Library
C++ library for working with time
Toggle main menu visibility
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_HEADER_TIME_SHIELD_TIME_ZONE_OFFSET_HPP_INCLUDED
4
#define TIME_SHIELD_HEADER_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
25
namespace
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
{
70
return
time_zone_struct_to_offset
(tz);
71
}
72
74
75
}
// namespace time_shield
76
77
#endif
// TIME_SHIELD_HEADER_TIME_SHIELD_TIME_ZONE_OFFSET_HPP_INCLUDED
config.hpp
Configuration macros for the library.
time_shield::ERROR_TIMESTAMP
constexpr int64_t ERROR_TIMESTAMP
Error timestamp value.
Definition
constants.hpp:161
time_shield::utc_offset_of
TIME_SHIELD_CONSTEXPR tz_t utc_offset_of(const TimeZoneStruct &tz) noexcept
Extract numeric UTC offset (in seconds) from TimeZoneStruct.
Definition
time_zone_offset.hpp:69
time_shield::to_utc
TIME_SHIELD_CONSTEXPR ts_t to_utc(ts_t local, tz_t utc_offset) noexcept
Convert local timestamp (seconds) to UTC using UTC offset.
Definition
time_zone_offset.hpp:34
time_shield::to_local
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.
Definition
time_zone_offset.hpp:43
time_shield::to_local_ms
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.
Definition
time_zone_offset.hpp:61
time_shield::to_utc_ms
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.
Definition
time_zone_offset.hpp:52
time_shield::sec_to_ms
TIME_SHIELD_CONSTEXPR T1 sec_to_ms(T2 ts) noexcept
Converts a timestamp from seconds to milliseconds.
Definition
time_unit_conversions.hpp:155
time_shield::time_zone_struct_to_offset
TIME_SHIELD_CONSTEXPR tz_t time_zone_struct_to_offset(const TimeZoneStruct &tz) noexcept
Convert a TimeZoneStruct to a numeric UTC offset (seconds).
Definition
time_zone_struct.hpp:97
time_shield::ts_t
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
Definition
types.hpp:49
time_shield::tz_t
int32_t tz_t
Time zone offset in minutes from UTC (e.g., +180 = UTC+3).
Definition
types.hpp:61
time_shield::ts_ms_t
int64_t ts_ms_t
Unix timestamp in milliseconds since epoch.
Definition
types.hpp:50
time_shield
Main namespace for the Time Shield library.
time_shield::TimeZoneStruct
Structure to represent time zone information.
Definition
time_zone_struct.hpp:22
time_conversions.hpp
Umbrella header for time conversion functions.
time_zone_struct.hpp
Header for time zone structure and related functions.
types.hpp
Type definitions for time-related units and formats.
include
time_shield
time_zone_offset.hpp
Generated by
1.17.0