Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_zone_struct.hpp
Go to the documentation of this file.
1#pragma once
4#ifndef _TIME_SHIELD_TIME_ZONE_STRUCT_HPP_INCLUDED
5#define _TIME_SHIELD_TIME_ZONE_STRUCT_HPP_INCLUDED
6
7#include "types.hpp"
8#include "constants.hpp"
9
10namespace time_shield {
11
18 int hour;
19 int min;
21 };
22
30 int hour,
31 int min,
32 bool is_positive = true) {
33 return TimeZoneStruct{hour, min, is_positive};
34 }
35
36//------------------------------------------------------------------------------
37
44 int abs_val = std::abs(offset);
45 int hour = abs_val / SEC_PER_HOUR;
46 int min = abs_val % SEC_PER_MIN;
47 bool is_positive = (offset >= 0);
48 return TimeZoneStruct{hour, min, is_positive};
49 }
50
55 inline const TimeZoneStruct to_tz(tz_t offset) {
56 return to_time_zone_struct(offset);
57 }
58
59//------------------------------------------------------------------------------
60
66 inline const std::string time_zone_struct_to_string(const TimeZoneStruct& tz) {
67 char sign = tz.is_positive ? '+' : '-';
68 return std::string(1, sign) + (tz.hour < 10 ? "0" : "") + std::to_string(tz.hour) + ":" + (tz.min < 10 ? "0" : "") + std::to_string(tz.min);
69 }
70
75 inline const std::string to_string(const TimeZoneStruct& tz) {
77 }
78
83 inline const std::string to_str(const TimeZoneStruct& tz) {
85 }
86
87//------------------------------------------------------------------------------
88
95 return (tz.is_positive ? 1 : -1) * (tz.hour * SEC_PER_HOUR + tz.min * SEC_PER_MIN);
96 }
97
101 inline const tz_t tz_to_offset(const TimeZoneStruct& tz) {
103 }
104
108 inline const tz_t to_offset(const TimeZoneStruct& tz) {
110 }
111
112}; // namespace time_shield
113
114#endif // _TIME_SHIELD_TIME_STRUCT_HPP_INCLUDED
Header file with time-related constants.
constexpr int64_t SEC_PER_MIN
Seconds per minute.
Definition constants.hpp:53
constexpr int64_t SEC_PER_HOUR
Seconds per hour.
Definition constants.hpp:59
const tz_t time_zone_struct_to_offset(const TimeZoneStruct &tz)
Converts a TimeZoneStruct to a single integer representation.
const TimeZoneStruct to_tz(tz_t offset)
Alias for to_time_zone_struct function.
const tz_t tz_to_offset(const TimeZoneStruct &tz)
Alias for time_zone_struct_to_offset function.
const TimeZoneStruct to_time_zone_struct(tz_t offset)
Converts an integer to a TimeZoneStruct.
const tz_t to_offset(const TimeZoneStruct &tz)
Alias for time_zone_struct_to_offset function.
const std::string & to_str(Weekday value, FormatType format=UPPERCASE_NAME)
Converts a Weekday enum value to a string.
Definition enums.hpp:81
const std::string to_string(const std::string &format_str, T timestamp, tz_t utc_offset=0)
Convert timestamp to string with custom format.
const std::string time_zone_struct_to_string(const TimeZoneStruct &tz)
Converts a TimeZoneStruct to a string representation.
const TimeZoneStruct create_time_zone_struct(int hour, int min, bool is_positive=true)
Creates a TimeZoneStruct instance.
int tz_t
Type for representing time zone offsets in minutes.
Definition types.hpp:41
Main namespace for the Time Shield library.
Definition constants.hpp:12
Structure to represent time zone information.
int hour
Hour component of time (0-23)
int min
Minute component of time (0-59)
bool is_positive
True if the time zone offset is positive, false if negative.
Header file with type definitions.