]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/gandiva/precompiled/epoch_time_point_test.cc
import quincy 17.2.0
[ceph.git] / 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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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
16 // under the License.
17
18 #include <ctime>
19
20 #include <gtest/gtest.h>
21 #include "./epoch_time_point.h"
22 #include "gandiva/precompiled/testing.h"
23 #include "gandiva/precompiled/types.h"
24
25 #include "gandiva/date_utils.h"
26
27 namespace gandiva {
28
29 TEST(TestEpochTimePoint, TestTm) {
30 auto ts = StringToTimestamp("2015-05-07 10:20:34");
31 EpochTimePoint tp(ts);
32
33 struct tm* tm_ptr;
34 #if defined(_WIN32)
35 __time64_t tsec = ts / 1000;
36 tm_ptr = _gmtime64(&tsec);
37 #else
38 struct tm tm;
39 time_t tsec = ts / 1000;
40 tm_ptr = gmtime_r(&tsec, &tm);
41 #endif
42
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);
51 }
52
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")));
56
57 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddYears(0),
58 EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")));
59
60 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddYears(-1),
61 EpochTimePoint(StringToTimestamp("2014-05-05 10:20:34")));
62 }
63
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")));
67
68 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddMonths(11),
69 EpochTimePoint(StringToTimestamp("2016-04-05 10:20:34")));
70
71 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddMonths(0),
72 EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")));
73
74 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddMonths(-1),
75 EpochTimePoint(StringToTimestamp("2015-04-05 10:20:34")));
76
77 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddMonths(-10),
78 EpochTimePoint(StringToTimestamp("2014-07-05 10:20:34")));
79 }
80
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")));
84
85 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddDays(11),
86 EpochTimePoint(StringToTimestamp("2015-05-16 10:20:34")));
87
88 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddDays(0),
89 EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")));
90
91 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddDays(-1),
92 EpochTimePoint(StringToTimestamp("2015-05-04 10:20:34")));
93
94 EXPECT_EQ(EpochTimePoint(StringToTimestamp("2015-05-05 10:20:34")).AddDays(-10),
95 EpochTimePoint(StringToTimestamp("2015-04-25 10:20:34")));
96 }
97
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")));
101 }
102
103 } // namespace gandiva