iceberg-cpp
Loading...
Searching...
No Matches
temporal_util.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <chrono>
23#include <cstdint>
24#include <string_view>
25
26#include "iceberg/iceberg_export.h"
27#include "iceberg/result.h"
28#include "iceberg/type_fwd.h"
29
30namespace iceberg::internal {
31
32inline constexpr int64_t kNanosPerMicro = 1000;
33inline constexpr int64_t kMicrosPerMilli = 1000;
34inline constexpr int64_t kMicrosPerSecond = 1000 * kMicrosPerMilli;
35inline constexpr int64_t kSecondsPerMinute = 60;
36inline constexpr int64_t kMinutesPerHour = 60;
37inline constexpr int64_t kHoursPerDay = 24;
38inline constexpr int64_t kSecondsPerHour = kMinutesPerHour * kSecondsPerMinute;
39inline constexpr int64_t kSecondsPerDay = kHoursPerDay * kSecondsPerHour;
40inline constexpr int64_t kMicrosPerDay = kSecondsPerDay * kMicrosPerSecond;
41inline constexpr int64_t kNanosPerMilli = kMicrosPerMilli * kNanosPerMicro;
42inline constexpr int64_t kNanosPerSecond = kMicrosPerSecond * kNanosPerMicro;
43inline constexpr int64_t kNanosPerDay = kMicrosPerDay * kNanosPerMicro;
44
45inline constexpr auto kEpochYmd = std::chrono::year{1970} / std::chrono::January / 1;
46inline constexpr auto kEpochDays = std::chrono::sys_days{kEpochYmd};
47
48} // namespace iceberg::internal
49
50namespace iceberg {
51
52class ICEBERG_EXPORT TemporalUtils {
53 public:
55 static int64_t NanosToMicros(int64_t nanos);
56
58 static Result<int64_t> MicrosToNanos(int64_t micros);
59
66 static Result<int32_t> ParseDay(std::string_view str);
67
76 static Result<int64_t> ParseTime(std::string_view str);
77
86 static Result<int64_t> ParseTimeNs(std::string_view str);
87
96 static Result<int64_t> ParseTimestamp(std::string_view str);
97
106 static Result<int64_t> ParseTimestampNs(std::string_view str);
107
116 static Result<int64_t> ParseTimestampWithZone(std::string_view str);
117
126 static Result<int64_t> ParseTimestampNsWithZone(std::string_view str);
127
142 static Result<bool> IsUtcOffset(std::string_view str);
143
145 static Result<Literal> ExtractYear(const Literal& literal);
146
148 static Result<Literal> ExtractMonth(const Literal& literal);
149
151 static Result<Literal> ExtractDay(const Literal& literal);
152
154 static Result<Literal> ExtractHour(const Literal& literal);
155};
156
157} // namespace iceberg
Literal is a literal value that is associated with a primitive type.
Definition literal.h:39
Definition temporal_util.h:52