palak-9202 commented on code in PR #13428:
URL: https://github.com/apache/arrow/pull/13428#discussion_r920799751


##########
cpp/src/gandiva/gdv_function_stubs_test.cc:
##########
@@ -993,4 +993,61 @@ TEST(TestGdvFnStubs, TestTranslate) {
   EXPECT_EQ(expected, std::string(result, out_len));
 }
 
+TEST(TestGdvFnStubs, TestToUtcTimezone) {
+  gandiva::ExecutionContext context;
+  auto context_ptr = reinterpret_cast<int64_t>(&context);
+  gdv_int32 len_ist = static_cast<gdv_int32>(strlen("Asia/Kolkata"));
+  gdv_int32 len_pst = static_cast<gdv_int32>(strlen("America/Los_Angeles"));
+
+  //2012-02-28 15:30:00
+  gdv_timestamp ts = 1330443000000;
+  gdv_timestamp ts2 =
+      to_utc_timezone_timestamp(context_ptr, ts, "Asia/Kolkata", len_ist);
+  EXPECT_EQ(1330423200000, ts2);
+
+  //1970-01-01 5:00:00
+  ts = 18000000;
+  ts2 = to_utc_timezone_timestamp(context_ptr, ts, "Asia/Kolkata", len_ist);
+  EXPECT_EQ(ts2, -1800000);
+
+  //daylight savings check
+  //2018-03-11 01:00:00
+  ts =         1520730000000;
+  ts2 = to_utc_timezone_timestamp(context_ptr, ts, "America/Los_Angeles", 
len_pst);
+  EXPECT_EQ(ts2, 1520758800000);
+
+  //2018-03-12 01:00:00
+  ts = 1331712000000;
+  ts2 = to_utc_timezone_timestamp(context_ptr, ts, "America/Los_Angeles", 
len_pst);
+  EXPECT_EQ(ts2, 1331737200000);
+
+  //Failure case
+  ts2 = to_utc_timezone_timestamp(context_ptr, ts, "America/LA", 10);
+  EXPECT_THAT(context.get_error(), "'America/LA' is an invalid time zone 
name.");
+}
+
+TEST(TestGdvFnStubs, TestFromUtcTimezone) {
+  ExecutionContext context;
+  auto context_ptr = reinterpret_cast<int64_t>(&context);
+  gdv_int32 len_ist = static_cast<gdv_int32>(strlen("Asia/Kolkata"));
+  gdv_int32 len_pst = static_cast<gdv_int32>(strlen("America/Los_Angeles"));
+
+  gdv_timestamp ts = 36000000;
+  gdv_timestamp ts2 =
+      from_utc_timezone_timestamp(context_ptr, ts, "Asia/Kolkata", len_ist);
+  EXPECT_EQ(ts2, 55800000);
+
+  ts = -1800000;
+  ts2 = from_utc_timezone_timestamp(context_ptr, ts, "Asia/Kolkata", len_ist);
+  EXPECT_EQ(ts2, 18000000);
+
+  ts = 1520758800000;
+  ts2 = from_utc_timezone_timestamp(context_ptr, ts, "America/Los_Angeles", 
len_pst);
+  EXPECT_EQ(ts2, 1520730000000);
+
+  ts = 1331737200000;
+  ts2 = from_utc_timezone_timestamp(context_ptr, ts, "America/Los_Angeles", 
len_pst);
+  EXPECT_EQ(ts2, 1331712000000);
+}

Review Comment:
   I've added all the suggested changes



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to