sparrow 0.9.0
Loading...
Searching...
No Matches
timestamp_without_timezone_types.hpp
Go to the documentation of this file.
1// Copyright 2024 Man Group Operations Limited
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or mplied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <chrono>
18
19namespace sparrow
20{
25 {
27
28 explicit zoned_time_without_timezone_seconds(int64_t seconds)
29 : std::chrono::duration<int64_t>(seconds)
30 {
31 }
32 };
33
38 {
40
41 explicit zoned_time_without_timezone_milliseconds(int64_t milliseconds)
42 : std::chrono::duration<int64_t, std::milli>(milliseconds)
43 {
44 }
45 };
46
51 {
53
54 explicit zoned_time_without_timezone_microseconds(int64_t microseconds)
55 : std::chrono::duration<int64_t, std::micro>(microseconds)
56 {
57 }
58 };
59
64 {
66
67 explicit zoned_time_without_timezone_nanoseconds(int64_t nanoseconds)
68 : std::chrono::duration<int64_t, std::nano>(nanoseconds)
69 {
70 }
71 };
72}
73
74
75#if defined(__cpp_lib_format)
76
77# include <format>
78
79template <typename T>
80 requires std::same_as<T, sparrow::zoned_time_without_timezone_seconds>
81 || std::same_as<T, sparrow::zoned_time_without_timezone_milliseconds>
82 || std::same_as<T, sparrow::zoned_time_without_timezone_microseconds>
83 || std::same_as<T, sparrow::zoned_time_without_timezone_nanoseconds>
84struct std::formatter<T>
85{
86 constexpr auto parse(std::format_parse_context& ctx)
87 {
88 return ctx.begin(); // Simple implementation
89 }
90
91 auto format(const T& time, std::format_context& ctx) const
92 {
93 return std::format_to(ctx.out(), "{}", time.count());
94 }
95};
96
97#endif