sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
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
22
#include "
sparrow/layout/temporal_types.hpp
"
23
24
namespace
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
30
struct
days_time_interval
31
{
32
chrono::days
days
;
33
std::chrono::duration<int32_t, std::milli>
time
;
34
};
35
36
#pragma pack(pop)
37
38
constexpr
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
45
struct
month_day_nanoseconds_interval
46
{
47
chrono::months
months
;
48
chrono::days
days
;
49
std::chrono::duration<int64_t, std::nano>
nanoseconds
;
50
};
51
52
#pragma pack(pop)
53
54
constexpr
bool
55
operator==
(
const
month_day_nanoseconds_interval
& lhs,
const
month_day_nanoseconds_interval
& rhs)
56
{
57
return
lhs.
months
== rhs.
months
&& lhs.
days
== rhs.
days
&& lhs.
nanoseconds
== rhs.
nanoseconds
;
58
}
59
}
60
61
namespace
std
62
{
63
#if defined(__cpp_lib_format)
64
template
<>
65
struct
formatter<sparrow::days_time_interval>
66
{
67
constexpr
auto
parse(std::format_parse_context& ctx)
68
{
69
return
ctx.begin();
// Simple implementation
70
}
71
72
auto
format(
const
sparrow::days_time_interval& interval, std::format_context& ctx)
const
73
{
74
std::ostringstream oss;
75
oss << interval.
days
.count() <<
" days/"
<< interval.
time
.count() <<
" ms"
;
76
const
std::string interval_str = oss.str();
77
return
std::format_to(ctx.out(),
"{}"
, interval_str);
78
}
79
};
80
81
template
<>
82
struct
formatter<sparrow::month_day_nanoseconds_interval>
83
{
84
constexpr
auto
parse(std::format_parse_context& ctx)
85
{
86
return
ctx.begin();
// Simple implementation
87
}
88
89
auto
format(
const
sparrow::month_day_nanoseconds_interval& interval, std::format_context& ctx)
const
90
{
91
std::ostringstream oss;
92
oss << interval.
months
.count() <<
" months/"
<< interval.
days
.count() <<
" days/"
93
<< interval.
nanoseconds
.count() <<
" ns"
;
94
const
std::string interval_str = oss.str();
95
return
std::format_to(ctx.out(),
"{}"
, interval_str);
96
}
97
};
98
#endif
99
}
std::chrono::duration
sparrow::chrono::days
std::chrono::duration< int32_t, std::ratio< 86400 > > days
Definition
temporal_types.hpp:21
sparrow::chrono::months
std::chrono::duration< int32_t, std::ratio< 2629746 > > months
Definition
temporal_types.hpp:22
sparrow
Definition
array.hpp:21
sparrow::operator==
SPARROW_API bool operator==(const array &lhs, const array &rhs)
Compares the content of two arrays.
std
Extensions to the C++ standard library.
Definition
float16_t.hpp:1916
sparrow::days_time_interval
Definition
interval_types.hpp:31
sparrow::days_time_interval::time
std::chrono::duration< int32_t, std::milli > time
Definition
interval_types.hpp:33
sparrow::days_time_interval::days
chrono::days days
Definition
interval_types.hpp:32
sparrow::month_day_nanoseconds_interval
Definition
interval_types.hpp:46
sparrow::month_day_nanoseconds_interval::months
chrono::months months
Definition
interval_types.hpp:47
sparrow::month_day_nanoseconds_interval::days
chrono::days days
Definition
interval_types.hpp:48
sparrow::month_day_nanoseconds_interval::nanoseconds
std::chrono::duration< int64_t, std::nano > nanoseconds
Definition
interval_types.hpp:49
temporal_types.hpp
sparrow
layout
interval_types.hpp
Generated by
1.17.0