]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/gandiva/precompiled/epoch_time_point_test.cc
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
20 #include <gtest/gtest.h>
21 #include "./epoch_time_point.h"
22 #include "gandiva/precompiled/testing.h"
23 #include "gandiva/precompiled/types.h"
25 #include "gandiva/date_utils.h"
29 TEST(TestEpochTimePoint
, TestTm
) {
30 auto ts
= StringToTimestamp("2015-05-07 10:20:34");
31 EpochTimePoint
tp(ts
);
35 __time64_t tsec
= ts
/ 1000;
36 tm_ptr
= _gmtime64(&tsec
);
39 time_t tsec
= ts
/ 1000;
40 tm_ptr
= gmtime_r(&tsec
, &tm
);
43 EXPECT_EQ(tp
.TmYear(), tm_ptr
->tm_year
);
44 EXPECT_EQ(tp
.TmMon(), tm_ptr
->tm_mon
);
45 EXPECT_EQ(tp
.TmYday(), tm_ptr
->tm_yday
);
46 EXPECT_EQ(tp
.TmMday(), tm_ptr
->tm_mday
);
47 EXPECT_EQ(tp
.TmWday(), tm_ptr
->tm_wday
);
48 EXPECT_EQ(tp
.TmHour(), tm_ptr
->tm_hour
);
49 EXPECT_EQ(tp
.TmMin(), tm_ptr
->tm_min
);
50 EXPECT_EQ(tp
.TmSec(), tm_ptr
->tm_sec
);
53 TEST(TestEpochTimePoint
, TestAddYears
) {
54 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddYears(2),
55 EpochTimePoint(StringToTimestamp("2017-05-05 10:20:34")));
57 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddYears(0),
58 EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")));
60 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddYears(-1),
61 EpochTimePoint(StringToTimestamp("2014-05-05 10:20:34")));
64 TEST(TestEpochTimePoint
, TestAddMonths
) {
65 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddMonths(2),
66 EpochTimePoint(StringToTimestamp("2015-07-05 10:20:34")));
68 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddMonths(11),
69 EpochTimePoint(StringToTimestamp("2016-04-05 10:20:34")));
71 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddMonths(0),
72 EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")));
74 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddMonths(-1),
75 EpochTimePoint(StringToTimestamp("2015-04-05 10:20:34")));
77 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddMonths(-10),
78 EpochTimePoint(StringToTimestamp("2014-07-05 10:20:34")));
81 TEST(TestEpochTimePoint
, TestAddDays
) {
82 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddDays(2),
83 EpochTimePoint(StringToTimestamp("2015-05-07 10:20:34")));
85 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddDays(11),
86 EpochTimePoint(StringToTimestamp("2015-05-16 10:20:34")));
88 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddDays(0),
89 EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")));
91 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddDays(-1),
92 EpochTimePoint(StringToTimestamp("2015-05-04 10:20:34")));
94 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddDays(-10),
95 EpochTimePoint(StringToTimestamp("2015-04-25 10:20:34")));
98 TEST(TestEpochTimePoint
, TestClearTimeOfDay
) {
99 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).ClearTimeOfDay(),
100 EpochTimePoint(StringToTimestamp("2015-05-05 00:00:00")));
103 } // namespace gandiva