jpedroantunes commented on a change in pull request #9890:
URL: https://github.com/apache/arrow/pull/9890#discussion_r624670276



##########
File path: cpp/src/gandiva/precompiled/time_test.cc
##########
@@ -743,4 +743,89 @@ TEST(TestTime, TestLastDay) {
   EXPECT_EQ(StringToTimestamp("2015-12-31 00:00:00"), out);
 }
 
+TEST(TestTime, TestToTimestamp) {
+  auto ts = StringToTimestamp("1970-01-01 00:00:00");
+  EXPECT_EQ(ts, to_timestamp_int32(0));
+  EXPECT_EQ(ts, to_timestamp_int64(0));
+  EXPECT_EQ(ts, to_timestamp_float32(0));
+  EXPECT_EQ(ts, to_timestamp_float64(0));
+
+  ts = StringToTimestamp("1970-01-01 00:00:01");
+  EXPECT_EQ(ts, to_timestamp_int32(1));
+  EXPECT_EQ(ts, to_timestamp_int64(1));
+  EXPECT_EQ(ts, to_timestamp_float32(1));
+  EXPECT_EQ(ts, to_timestamp_float64(1));
+
+  ts = StringToTimestamp("1970-01-01 00:01:00");
+  EXPECT_EQ(ts, to_timestamp_int32(60));
+  EXPECT_EQ(ts, to_timestamp_int64(60));
+  EXPECT_EQ(ts, to_timestamp_float32(60));
+  EXPECT_EQ(ts, to_timestamp_float64(60));
+
+  ts = StringToTimestamp("1970-01-01 01:00:00");
+  EXPECT_EQ(ts, to_timestamp_int32(3600));
+  EXPECT_EQ(ts, to_timestamp_int64(3600));
+  EXPECT_EQ(ts, to_timestamp_float32(3600));
+  EXPECT_EQ(ts, to_timestamp_float64(3600));
+
+  ts = StringToTimestamp("1970-01-02 00:00:00");
+  EXPECT_EQ(ts, to_timestamp_int32(86400));
+  EXPECT_EQ(ts, to_timestamp_int64(86400));
+  EXPECT_EQ(ts, to_timestamp_float32(86400));
+  EXPECT_EQ(ts, to_timestamp_float64(86400));
+
+  // tests with fractional part
+  ts = StringToTimestamp("1970-01-01 00:00:01") + 500;
+  EXPECT_EQ(ts, to_timestamp_float32(1.500f));
+  EXPECT_EQ(ts, to_timestamp_float64(1.500));
+
+  ts = StringToTimestamp("1970-01-01 00:01:01") + 600;
+  EXPECT_EQ(ts, to_timestamp_float32(61.600f));
+  EXPECT_EQ(ts, to_timestamp_float64(61.600));
+
+  ts = StringToTimestamp("1970-01-01 01:00:01") + 400;
+  EXPECT_EQ(ts, to_timestamp_float32(3601.400f));
+  EXPECT_EQ(ts, to_timestamp_float64(3601.400));
+}
+
+TEST(TestTime, TestToTimeNumeric) {
+
+  auto ts = StringToTimestamp("1970-01-02 00:00:00") / 1000;
+  EXPECT_EQ(0, to_time_int32(ts));
+  EXPECT_EQ(0, to_time_int64(ts));
+  EXPECT_EQ(0, to_time_float32(ts));
+  EXPECT_EQ(0, to_time_float64(ts));
+
+  ts = StringToTimestamp("1970-01-01 00:00:01") / 1000;
+  EXPECT_EQ(1000, to_time_int32(ts));
+  EXPECT_EQ(1000, to_time_int64(ts));
+  EXPECT_EQ(1000, to_time_float32(ts));
+  EXPECT_EQ(1000, to_time_float64(ts));
+
+  ts = StringToTimestamp("1970-01-01 01:00:00") / 1000;
+  EXPECT_EQ(3600000, to_time_int32(ts));
+  EXPECT_EQ(3600000, to_time_int64(ts));
+  EXPECT_EQ(3600000, to_time_float32(ts));
+  EXPECT_EQ(3600000, to_time_float64(ts));
+
+  ts = StringToTimestamp("1970-01-01 23:59:59") / 1000;
+  EXPECT_EQ(86399000, to_time_int32(ts));
+  EXPECT_EQ(86399000, to_time_int64(ts));
+  EXPECT_EQ(86399000, to_time_float32(ts));
+  EXPECT_EQ(86399000, to_time_float64(ts));
+
+  // tests with fractional part
+  ts = StringToTimestamp("1970-01-01 00:00:01") + 500;
+  EXPECT_EQ(ts, to_time_float32(ts/1000.0));
+  EXPECT_EQ(ts, to_time_float64(ts/1000.0));
+
+  ts = StringToTimestamp("1970-01-01 00:01:01") + 600;
+  EXPECT_EQ(ts, to_time_float32(ts/1000.0));
+  EXPECT_EQ(ts, to_time_float64(ts/1000.0));
+
+  ts = StringToTimestamp("1970-01-01 01:00:01") + 400;

Review comment:
       Sure @projjal !
   With these tests I have now one question:
   - Do we need to handle overflow? Using high timestamp values is causing 
overflow for int32 and float32 test cases.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to