sparrow 0.3.0
Loading...
Searching...
No Matches
interval_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 implied.
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#if defined(__cpp_lib_format)
19# include <format>
20#endif
21
23
24namespace sparrow
25{
26
27// We pack the structures to ensure that they are the same size on all platforms
28#pragma pack(push, 1)
29
35
36#pragma pack(pop)
37
38 inline bool operator==(const days_time_interval& lhs, const days_time_interval& rhs)
39 {
40 return lhs.days == rhs.days && lhs.time == rhs.time;
41 }
42
43#pragma pack(push, 1)
44
51
52#pragma pack(pop)
53
55 {
56 return lhs.months == rhs.months && lhs.days == rhs.days && lhs.nanoseconds == rhs.nanoseconds;
57 }
58}
59
60namespace std
61{
62#if defined(__cpp_lib_format)
63 template <>
64 struct formatter<sparrow::days_time_interval>
65 {
66 constexpr auto parse(std::format_parse_context& ctx)
67 {
68 return ctx.begin(); // Simple implementation
69 }
70
71 auto format(const sparrow::days_time_interval& interval, std::format_context& ctx) const
72 {
73 std::ostringstream oss;
74 oss << interval.days.count() << " days/" << interval.time.count() << " ms";
75 const std::string interval_str = oss.str();
76 return std::format_to(ctx.out(), "{}", interval_str);
77 }
78 };
79
80 template <>
81 struct formatter<sparrow::month_day_nanoseconds_interval>
82 {
83 constexpr auto parse(std::format_parse_context& ctx)
84 {
85 return ctx.begin(); // Simple implementation
86 }
87
88 auto format(const sparrow::month_day_nanoseconds_interval& interval, std::format_context& ctx) const
89 {
90 std::ostringstream oss;
91 oss << interval.months.count() << " months/" << interval.days.count() << " days/"
92 << interval.nanoseconds.count() << " ns";
93 const std::string interval_str = oss.str();
94 return std::format_to(ctx.out(), "{}", interval_str);
95 }
96 };
97#endif
98}
std::chrono::duration< int32_t, std::ratio< 86400 > > days
std::chrono::duration< int32_t, std::ratio< 2629746 > > months
SPARROW_API bool operator==(const array &lhs, const array &rhs)
Compares the content of two arrays.
std::chrono::duration< int32_t, std::milli > time
std::chrono::duration< int64_t, std::nano > nanoseconds