You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/06/01 13:59:22 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #10176: ARROW-11759: [C++] Kernel to extract datetime components (year, month, day, etc) from timestamp type

pitrou commented on a change in pull request #10176:
URL: https://github.com/apache/arrow/pull/10176#discussion_r643045754



##########
File path: cpp/src/arrow/compute/api_scalar.h
##########
@@ -462,5 +462,177 @@ ARROW_EXPORT
 Result<Datum> FillNull(const Datum& values, const Datum& fill_value,
                        ExecContext* ctx = NULLPTR);
 
+/// \brief Year returns year value for each element of `values`
+///
+/// \param[in] values input to extract year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Year(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Month returns month value for each element of `values`

Review comment:
       What is "month value"? Do you mean "month number"? Does it start at 0 or 1?

##########
File path: cpp/src/arrow/compute/api_scalar.h
##########
@@ -462,5 +462,177 @@ ARROW_EXPORT
 Result<Datum> FillNull(const Datum& values, const Datum& fill_value,
                        ExecContext* ctx = NULLPTR);
 
+/// \brief Year returns year value for each element of `values`
+///
+/// \param[in] values input to extract year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Year(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Month returns month value for each element of `values`
+///
+/// \param[in] values input to extract month from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Month(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Day returns day value for each element of `values`
+///
+/// \param[in] values input to extract day from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Day(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief DayOfWeek returns day of the week value for each element of `values`
+///
+/// \param[in] values input to extract dat of the week from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT Result<Datum> DayOfWeek(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief DayOfYear returns day of year value for each element of `values`
+///
+/// \param[in] values input to extract day of year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT Result<Datum> DayOfYear(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief ISOYear returns ISO year value for each element of `values`
+///
+/// \param[in] values input to extract ISO year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> ISOYear(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief ISOWeek returns ISO week of year value for each element of `values`

Review comment:
       "week number"? Does it start at 0, 1?

##########
File path: cpp/src/arrow/compute/api_scalar.h
##########
@@ -462,5 +462,177 @@ ARROW_EXPORT
 Result<Datum> FillNull(const Datum& values, const Datum& fill_value,
                        ExecContext* ctx = NULLPTR);
 
+/// \brief Year returns year value for each element of `values`
+///
+/// \param[in] values input to extract year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Year(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Month returns month value for each element of `values`
+///
+/// \param[in] values input to extract month from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Month(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Day returns day value for each element of `values`
+///
+/// \param[in] values input to extract day from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Day(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief DayOfWeek returns day of the week value for each element of `values`

Review comment:
       "Number of day in the week"? Does it start at 0, 1? For Monday, Sunday?

##########
File path: cpp/src/arrow/compute/api_scalar.h
##########
@@ -462,5 +462,177 @@ ARROW_EXPORT
 Result<Datum> FillNull(const Datum& values, const Datum& fill_value,
                        ExecContext* ctx = NULLPTR);
 
+/// \brief Year returns year value for each element of `values`
+///
+/// \param[in] values input to extract year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Year(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Month returns month value for each element of `values`
+///
+/// \param[in] values input to extract month from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Month(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Day returns day value for each element of `values`
+///
+/// \param[in] values input to extract day from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Day(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief DayOfWeek returns day of the week value for each element of `values`
+///
+/// \param[in] values input to extract dat of the week from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT Result<Datum> DayOfWeek(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief DayOfYear returns day of year value for each element of `values`

Review comment:
       "Number of day in the year"? Does it start at 0 or 1?

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal_test.cc
##########
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+#include "arrow/compute/api_scalar.h"
+#include "arrow/compute/kernels/test_util.h"
+#include "arrow/util/checked_cast.h"
+#include "arrow/util/formatting.h"
+
+namespace arrow {
+
+using internal::StringFormatter;
+
+class ScalarTemporalTest : public ::testing::Test {};
+
+namespace compute {
+
+TEST(ScalarTemporalTest, TestSimpleTemporalComponentExtraction) {
+  const char* times =
+      R"(["1970-01-01T00:00:59.123456789","2000-02-29T23:23:23.999999999",
+          "1899-01-01T00:59:20.001001001","2033-05-18T03:33:20.000000000", null])";
+  auto unit = timestamp(TimeUnit::NANO);
+  auto timestamps = ArrayFromJSON(unit, times);
+  auto iso_calendar_type =
+      struct_({field("iso_year", int64()), field("iso_week", int64()),
+               field("weekday", int64())});
+
+  auto year = "[1970, 2000, 1899, 2033, null]";
+  auto month = "[1, 2, 1, 5, null]";
+  auto day = "[1, 29, 1, 18, null]";
+  auto day_of_week = "[4, 2, 7, 3, null]";
+  auto day_of_year = "[1, 60, 1, 138, null]";
+  auto iso_year = "[1970, 2000, 1899, 2033, null]";
+  auto iso_week = "[1, 9, 52, 20, null]";
+  auto iso_calendar = ArrayFromJSON(iso_calendar_type,
+                                    R"([{"iso_year": 1970, "iso_week": 1, "weekday": 4},
+                        {"iso_year": 2000, "iso_week": 9, "weekday": 2},
+                        {"iso_year": 1899, "iso_week": 52, "weekday": 7},
+                        {"iso_year": 2033, "iso_week": 20, "weekday": 3}, null])");
+  auto quarter = "[1, 1, 1, 2, null]";
+  auto hour = "[0, 23, 0, 3, null]";
+  auto minute = "[0, 23, 59, 33, null]";
+  auto second = "[59.123456789, 23.999999999, 20.001001001, 20.0, null]";
+  auto millisecond = "[123, 999, 1, 0, null]";
+  auto microsecond = "[456, 999, 1, 0, null]";
+  auto nanosecond = "[789, 999, 1, 0, null]";
+  auto subsecond = "[123456789, 999999999, 1001001, 0, null]";
+
+  CheckScalarUnary("year", unit, times, int64(), year);
+  CheckScalarUnary("month", unit, times, int64(), month);
+  CheckScalarUnary("day", unit, times, int64(), day);
+  CheckScalarUnary("day_of_week", unit, times, int64(), day_of_week);
+  CheckScalarUnary("day_of_year", unit, times, int64(), day_of_year);
+  CheckScalarUnary("iso_year", unit, times, int64(), iso_year);
+  CheckScalarUnary("iso_week", unit, times, int64(), iso_week);
+  CheckScalarUnary("iso_calendar", timestamps, iso_calendar);
+  CheckScalarUnary("quarter", unit, times, int64(), quarter);
+  CheckScalarUnary("hour", unit, times, int64(), hour);
+  CheckScalarUnary("minute", unit, times, int64(), minute);
+  CheckScalarUnary("second", unit, times, float64(), second);
+  CheckScalarUnary("millisecond", unit, times, int64(), millisecond);
+  CheckScalarUnary("microsecond", unit, times, int64(), microsecond);
+  CheckScalarUnary("nanosecond", unit, times, int64(), nanosecond);
+  CheckScalarUnary("subsecond", unit, times, int64(), subsecond);

Review comment:
       Is there any point in `millisecond` and friends? The floating-point `second` should have enough precision to represent them all exactly.

##########
File path: docs/source/cpp/compute.rst
##########
@@ -637,6 +637,54 @@ String extraction
   e.g. 'letter' and 'digit' for the regular expression
   ``(?P<letter>[ab])(?P<digit>\\d)``.
 
+Temporal component extraction
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+These functions extract datetime components (year, month, day, etc) from timestamp type.
+Note: timezone information is currently ignored if present.
+
++--------------------+------------+-------------------+-----------------+--------+
+| Function name      | Arity      | Input types       | Output type     | Notes  |
++====================+============+===================+=================+========+
+| year               | Unary      | Temporal          | Numeric         |        |

Review comment:
       The output types should be given more precisely here.

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.

Review comment:
       Since most of this file consists of private class/function implementations, can you put them under the anonymous namespace? it avoids exposing the symbols externally.

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract month from timestamp
+
+template <typename Duration>
+struct Month {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).month()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day from timestamp
+
+template <typename Duration>
+struct Day {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).day()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of week from timestamp
+
+template <typename Duration>
+struct DayOfWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(
+        weekday(year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))))
+            .iso_encoding());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of year from timestamp
+
+template <typename Duration>
+struct DayOfYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto sd = sys_days{floor<days>(Duration{arg})};
+    return static_cast<T>((sd - sys_days(year_month_day(sd).year() / jan / 0)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO Year values from timestamp
+
+template <typename Duration>
+struct ISOYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day{sys_days{floor<days>(Duration{arg})} + days{3}}.year()));

Review comment:
       Can you add a comment explaining why adding 3 days is necessary?

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(

Review comment:
       Can you explain why two successive casts are needed?

##########
File path: docs/source/cpp/compute.rst
##########
@@ -637,6 +637,54 @@ String extraction
   e.g. 'letter' and 'digit' for the regular expression
   ``(?P<letter>[ab])(?P<digit>\\d)``.
 
+Temporal component extraction
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+These functions extract datetime components (year, month, day, etc) from timestamp type.
+Note: timezone information is currently ignored if present.
+
++--------------------+------------+-------------------+-----------------+--------+
+| Function name      | Arity      | Input types       | Output type     | Notes  |
++====================+============+===================+=================+========+
+| year               | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| month              | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| day                | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| day_of_week        | Unary      | Temporal          | Numeric         |        |

Review comment:
       Can you also add a note explaining this?

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract month from timestamp
+
+template <typename Duration>
+struct Month {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).month()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day from timestamp
+
+template <typename Duration>
+struct Day {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).day()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of week from timestamp
+
+template <typename Duration>
+struct DayOfWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(
+        weekday(year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))))
+            .iso_encoding());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of year from timestamp
+
+template <typename Duration>
+struct DayOfYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto sd = sys_days{floor<days>(Duration{arg})};
+    return static_cast<T>((sd - sys_days(year_month_day(sd).year() / jan / 0)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO Year values from timestamp
+
+template <typename Duration>
+struct ISOYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day{sys_days{floor<days>(Duration{arg})} + days{3}}.year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO week from timestamp
+
+// Based on
+// https://github.com/HowardHinnant/date/blob/6e921e1b1d21e84a5c82416ba7ecd98e33a436d0/include/date/iso_week.h#L1503
+template <typename Duration>
+struct ISOWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto dp = sys_days{floor<days>(Duration{arg})};
+    auto y = year_month_day{dp + days{3}}.year();
+    auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    if (dp < start) {
+      --y;
+      start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    }
+    return static_cast<T>(trunc<weeks>(dp - start).count() + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of quarter from timestamp
+
+template <typename Duration>
+struct Quarter {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto ymd = year_month_day(floor<days>(sys_time<Duration>(Duration{arg})));
+    return static_cast<T>((static_cast<const uint32_t>(ymd.month()) - 1) / 3 + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract hour from timestamp
+
+template <typename Duration>
+struct Hour {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<days>(t)) / std::chrono::hours(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract minute from timestamp
+
+template <typename Duration>
+struct Minute {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::hours>(t)) / std::chrono::minutes(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract second from timestamp
+
+template <typename Duration>
+struct Second {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        std::chrono::duration<double>(t - floor<std::chrono::minutes>(t)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract subsecond from timestamp
+
+template <typename Duration>
+struct Subsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::seconds>(t)) /
+                          std::chrono::nanoseconds(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract milliseconds from timestamp
+
+template <typename Duration>
+struct Millisecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::milliseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract microseconds from timestamp
+
+template <typename Duration>
+struct Microsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::microseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract nanoseconds from timestamp
+
+template <typename Duration>
+struct Nanosecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::nanoseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO calendar values from timestamp
+
+template <typename Duration, typename OutType>
+struct ISOCalendar {
+  using T = typename OutType::c_type;
+
+  static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+    using ScalarType = typename TypeTraits<OutType>::ScalarType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    if (!in.is_valid) {
+      out->is_valid = false;
+    } else {
+      const std::shared_ptr<DataType> iso_calendar_type =
+          struct_({field("iso_year", out_type), field("iso_week", out_type),
+                   field("weekday", out_type)});
+
+      const auto& in_val = internal::UnboxScalar<const TimestampType>::Unbox(in);
+      const auto dp = sys_days{floor<days>(Duration{in_val})};
+      const auto ymd = year_month_day(dp);
+      auto y = year_month_day{dp + days{3}}.year();
+      auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      if (dp < start) {
+        --y;
+        start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      }
+
+      std::vector<std::shared_ptr<Scalar>> values = {
+          std::make_shared<ScalarType>(static_cast<T>(static_cast<int32_t>(ymd.year()))),
+          std::make_shared<ScalarType>(
+              static_cast<T>(trunc<weeks>(dp - start).count() + 1)),
+          std::make_shared<ScalarType>(static_cast<T>(weekday(ymd).iso_encoding()))};
+      *checked_cast<StructScalar*>(out) = StructScalar(values, iso_calendar_type);
+    }
+    return Status::OK();
+  }
+
+  static Status Call(KernelContext* ctx, const ArrayData& in, ArrayData* out) {
+    using BuilderType = typename TypeTraits<OutType>::BuilderType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    const std::shared_ptr<DataType> iso_calendar_type =
+        struct_({field("iso_year", out_type), field("iso_week", out_type),
+                 field("weekday", out_type)});
+
+    std::unique_ptr<ArrayBuilder> array_builder;
+    RETURN_NOT_OK(MakeBuilder(ctx->memory_pool(), iso_calendar_type, &array_builder));
+    StructBuilder* struct_builder = checked_cast<StructBuilder*>(array_builder.get());
+
+    std::vector<BuilderType*> field_builders;
+    field_builders.reserve(3);
+    for (int i = 0; i < 3; i++) {
+      field_builders.push_back(
+          checked_cast<BuilderType*>(struct_builder->field_builder(i)));

Review comment:
       You can call `Reserve` here to presize the field arrays. Then you call `UnsafeAppend` below.

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal_test.cc
##########
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+#include "arrow/compute/api_scalar.h"
+#include "arrow/compute/kernels/test_util.h"
+#include "arrow/util/checked_cast.h"
+#include "arrow/util/formatting.h"
+
+namespace arrow {
+
+using internal::StringFormatter;
+
+class ScalarTemporalTest : public ::testing::Test {};
+
+namespace compute {
+
+TEST(ScalarTemporalTest, TestSimpleTemporalComponentExtraction) {
+  const char* times =
+      R"(["1970-01-01T00:00:59.123456789","2000-02-29T23:23:23.999999999",
+          "1899-01-01T00:59:20.001001001","2033-05-18T03:33:20.000000000", null])";

Review comment:
       Can you test a bit more boundary cases, especially for `day_of_week` and `iso_week`? Start of year, end of year, start of week, end of week, etc.

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract month from timestamp
+
+template <typename Duration>
+struct Month {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).month()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day from timestamp
+
+template <typename Duration>
+struct Day {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).day()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of week from timestamp
+
+template <typename Duration>
+struct DayOfWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(
+        weekday(year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))))
+            .iso_encoding());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of year from timestamp
+
+template <typename Duration>
+struct DayOfYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto sd = sys_days{floor<days>(Duration{arg})};
+    return static_cast<T>((sd - sys_days(year_month_day(sd).year() / jan / 0)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO Year values from timestamp
+
+template <typename Duration>
+struct ISOYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day{sys_days{floor<days>(Duration{arg})} + days{3}}.year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO week from timestamp
+
+// Based on
+// https://github.com/HowardHinnant/date/blob/6e921e1b1d21e84a5c82416ba7ecd98e33a436d0/include/date/iso_week.h#L1503
+template <typename Duration>
+struct ISOWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto dp = sys_days{floor<days>(Duration{arg})};
+    auto y = year_month_day{dp + days{3}}.year();
+    auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    if (dp < start) {
+      --y;
+      start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    }
+    return static_cast<T>(trunc<weeks>(dp - start).count() + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of quarter from timestamp
+
+template <typename Duration>
+struct Quarter {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto ymd = year_month_day(floor<days>(sys_time<Duration>(Duration{arg})));
+    return static_cast<T>((static_cast<const uint32_t>(ymd.month()) - 1) / 3 + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract hour from timestamp
+
+template <typename Duration>
+struct Hour {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<days>(t)) / std::chrono::hours(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract minute from timestamp
+
+template <typename Duration>
+struct Minute {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::hours>(t)) / std::chrono::minutes(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract second from timestamp
+
+template <typename Duration>
+struct Second {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        std::chrono::duration<double>(t - floor<std::chrono::minutes>(t)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract subsecond from timestamp
+
+template <typename Duration>
+struct Subsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::seconds>(t)) /
+                          std::chrono::nanoseconds(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract milliseconds from timestamp
+
+template <typename Duration>
+struct Millisecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::milliseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract microseconds from timestamp
+
+template <typename Duration>
+struct Microsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::microseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract nanoseconds from timestamp
+
+template <typename Duration>
+struct Nanosecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::nanoseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO calendar values from timestamp
+
+template <typename Duration, typename OutType>
+struct ISOCalendar {
+  using T = typename OutType::c_type;
+
+  static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+    using ScalarType = typename TypeTraits<OutType>::ScalarType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();

Review comment:
       Please use `checked_pointer_cast`.

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract month from timestamp
+
+template <typename Duration>
+struct Month {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).month()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day from timestamp
+
+template <typename Duration>
+struct Day {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).day()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of week from timestamp
+
+template <typename Duration>
+struct DayOfWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(
+        weekday(year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))))
+            .iso_encoding());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of year from timestamp
+
+template <typename Duration>
+struct DayOfYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto sd = sys_days{floor<days>(Duration{arg})};
+    return static_cast<T>((sd - sys_days(year_month_day(sd).year() / jan / 0)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO Year values from timestamp
+
+template <typename Duration>
+struct ISOYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day{sys_days{floor<days>(Duration{arg})} + days{3}}.year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO week from timestamp
+
+// Based on
+// https://github.com/HowardHinnant/date/blob/6e921e1b1d21e84a5c82416ba7ecd98e33a436d0/include/date/iso_week.h#L1503
+template <typename Duration>
+struct ISOWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto dp = sys_days{floor<days>(Duration{arg})};
+    auto y = year_month_day{dp + days{3}}.year();
+    auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    if (dp < start) {
+      --y;
+      start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    }
+    return static_cast<T>(trunc<weeks>(dp - start).count() + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of quarter from timestamp

Review comment:
       Are you sure this is the "day of quarter"? 

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract month from timestamp
+
+template <typename Duration>
+struct Month {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).month()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day from timestamp
+
+template <typename Duration>
+struct Day {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).day()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of week from timestamp
+
+template <typename Duration>
+struct DayOfWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(
+        weekday(year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))))
+            .iso_encoding());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of year from timestamp
+
+template <typename Duration>
+struct DayOfYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto sd = sys_days{floor<days>(Duration{arg})};
+    return static_cast<T>((sd - sys_days(year_month_day(sd).year() / jan / 0)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO Year values from timestamp
+
+template <typename Duration>
+struct ISOYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day{sys_days{floor<days>(Duration{arg})} + days{3}}.year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO week from timestamp
+
+// Based on
+// https://github.com/HowardHinnant/date/blob/6e921e1b1d21e84a5c82416ba7ecd98e33a436d0/include/date/iso_week.h#L1503
+template <typename Duration>
+struct ISOWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto dp = sys_days{floor<days>(Duration{arg})};
+    auto y = year_month_day{dp + days{3}}.year();
+    auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    if (dp < start) {
+      --y;
+      start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    }
+    return static_cast<T>(trunc<weeks>(dp - start).count() + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of quarter from timestamp
+
+template <typename Duration>
+struct Quarter {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto ymd = year_month_day(floor<days>(sys_time<Duration>(Duration{arg})));
+    return static_cast<T>((static_cast<const uint32_t>(ymd.month()) - 1) / 3 + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract hour from timestamp
+
+template <typename Duration>
+struct Hour {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<days>(t)) / std::chrono::hours(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract minute from timestamp
+
+template <typename Duration>
+struct Minute {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::hours>(t)) / std::chrono::minutes(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract second from timestamp
+
+template <typename Duration>
+struct Second {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        std::chrono::duration<double>(t - floor<std::chrono::minutes>(t)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract subsecond from timestamp
+
+template <typename Duration>
+struct Subsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::seconds>(t)) /
+                          std::chrono::nanoseconds(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract milliseconds from timestamp
+
+template <typename Duration>
+struct Millisecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::milliseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract microseconds from timestamp
+
+template <typename Duration>
+struct Microsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::microseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract nanoseconds from timestamp
+
+template <typename Duration>
+struct Nanosecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::nanoseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO calendar values from timestamp
+
+template <typename Duration, typename OutType>
+struct ISOCalendar {
+  using T = typename OutType::c_type;
+
+  static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+    using ScalarType = typename TypeTraits<OutType>::ScalarType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    if (!in.is_valid) {
+      out->is_valid = false;
+    } else {
+      const std::shared_ptr<DataType> iso_calendar_type =
+          struct_({field("iso_year", out_type), field("iso_week", out_type),
+                   field("weekday", out_type)});
+
+      const auto& in_val = internal::UnboxScalar<const TimestampType>::Unbox(in);
+      const auto dp = sys_days{floor<days>(Duration{in_val})};
+      const auto ymd = year_month_day(dp);
+      auto y = year_month_day{dp + days{3}}.year();
+      auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      if (dp < start) {
+        --y;
+        start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      }
+
+      std::vector<std::shared_ptr<Scalar>> values = {
+          std::make_shared<ScalarType>(static_cast<T>(static_cast<int32_t>(ymd.year()))),
+          std::make_shared<ScalarType>(
+              static_cast<T>(trunc<weeks>(dp - start).count() + 1)),
+          std::make_shared<ScalarType>(static_cast<T>(weekday(ymd).iso_encoding()))};
+      *checked_cast<StructScalar*>(out) = StructScalar(values, iso_calendar_type);
+    }
+    return Status::OK();
+  }
+
+  static Status Call(KernelContext* ctx, const ArrayData& in, ArrayData* out) {
+    using BuilderType = typename TypeTraits<OutType>::BuilderType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    const std::shared_ptr<DataType> iso_calendar_type =
+        struct_({field("iso_year", out_type), field("iso_week", out_type),
+                 field("weekday", out_type)});
+
+    std::unique_ptr<ArrayBuilder> array_builder;
+    RETURN_NOT_OK(MakeBuilder(ctx->memory_pool(), iso_calendar_type, &array_builder));
+    StructBuilder* struct_builder = checked_cast<StructBuilder*>(array_builder.get());
+
+    std::vector<BuilderType*> field_builders;
+    field_builders.reserve(3);
+    for (int i = 0; i < 3; i++) {
+      field_builders.push_back(
+          checked_cast<BuilderType*>(struct_builder->field_builder(i)));
+    }
+    auto visit_null = [&]() { return struct_builder->AppendNull(); };
+    auto visit_value = [&](int64_t arg) {
+      const auto dp = sys_days{floor<days>(Duration{arg})};
+      const auto ymd = year_month_day(dp);
+      auto y = year_month_day{dp + days{3}}.year();
+      auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      if (dp < start) {
+        --y;
+        start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      }
+
+      RETURN_NOT_OK(
+          field_builders[0]->Append(static_cast<T>(static_cast<int32_t>(ymd.year()))));
+      RETURN_NOT_OK(field_builders[1]->Append(
+          static_cast<T>(trunc<weeks>(dp - start).count() + 1)));
+      RETURN_NOT_OK(
+          field_builders[2]->Append(static_cast<T>(weekday(ymd).iso_encoding())));
+
+      return struct_builder->Append();
+    };
+    RETURN_NOT_OK(VisitArrayDataInline<OutType>(in, visit_value, visit_null));
+
+    std::shared_ptr<Array> out_array;
+    RETURN_NOT_OK(struct_builder->Finish(&out_array));
+    *out = *std::move(out_array->data());
+
+    return Status::OK();
+  }
+};
+
+// Generate a kernel given an arithmetic functor
+template <template <typename... Args> class KernelGenerator,
+          template <typename... Args> class Op, typename Duration>
+ArrayKernelExec ExecFromOp(detail::GetTypeId get_id) {
+  switch (get_id.id) {
+    case Type::INT8:
+      return KernelGenerator<Int8Type, Op<Duration>>::Exec;
+    case Type::UINT8:
+      return KernelGenerator<UInt8Type, Op<Duration>>::Exec;
+    case Type::INT16:
+      return KernelGenerator<Int16Type, Op<Duration>>::Exec;
+    case Type::UINT16:
+      return KernelGenerator<UInt16Type, Op<Duration>>::Exec;
+    case Type::INT32:
+      return KernelGenerator<Int32Type, Op<Duration>>::Exec;
+    case Type::UINT32:
+      return KernelGenerator<UInt32Type, Op<Duration>>::Exec;
+    case Type::INT64:
+    case Type::TIMESTAMP:
+      return KernelGenerator<Int64Type, Op<Duration>>::Exec;
+    case Type::UINT64:
+      return KernelGenerator<UInt64Type, Op<Duration>>::Exec;
+    case Type::FLOAT:
+      return KernelGenerator<FloatType, Op<Duration>>::Exec;
+    case Type::DOUBLE:
+      return KernelGenerator<DoubleType, Op<Duration>>::Exec;
+    default:
+      DCHECK(false);
+      return ExecFail;
+  }
+}
+
+template <template <typename...> class Op>
+std::shared_ptr<ScalarFunction> MakeTemporalFunction(
+    std::string name, const FunctionDoc* doc,
+    std::vector<std::shared_ptr<DataType>> types) {
+  auto func = std::make_shared<ScalarFunction>(name, Arity::Unary(), doc);
+
+  for (auto ty : types) {
+    for (auto unit : AllTimeUnits()) {
+      ArrayKernelExec exec;
+      switch (unit) {
+        case TimeUnit::SECOND: {
+          exec = ExecFromOp<ScalarUnaryTemporal, Op, std::chrono::seconds>(ty);
+        }
+        case TimeUnit::MILLI: {
+          exec = ExecFromOp<ScalarUnaryTemporal, Op, std::chrono::milliseconds>(ty);
+        }
+        case TimeUnit::MICRO: {
+          exec = ExecFromOp<ScalarUnaryTemporal, Op, std::chrono::microseconds>(ty);
+        }
+        case TimeUnit::NANO: {
+          exec = ExecFromOp<ScalarUnaryTemporal, Op, std::chrono::nanoseconds>(ty);
+        }
+      }
+      ScalarKernel kernel =
+          ScalarKernel({match::TimestampTypeUnit(unit)}, OutputType(ty), exec);
+      DCHECK_OK(func->AddKernel(kernel));
+    }
+  }
+  return func;
+}
+
+// Generate a kernel given an arithmetic functor
+template <template <typename... Args> class Op, typename Duration>
+ArrayKernelExec SimpleUnaryFromOp(detail::GetTypeId get_id) {
+  switch (get_id.id) {
+    case Type::INT32:
+      return SimpleUnary<Op<Duration, Int32Type>>;
+    case Type::INT64:
+      return SimpleUnary<Op<Duration, Int64Type>>;
+    default:
+      DCHECK(false);
+      return ExecFail;
+  }
+}
+
+template <template <typename...> class Op>
+std::shared_ptr<ScalarFunction> MakeSimpleUnaryTemporalFunction(
+    std::string name, const FunctionDoc* doc,
+    std::vector<std::shared_ptr<DataType>> types) {
+  auto func = std::make_shared<ScalarFunction>(name, Arity::Unary(), doc);
+
+  for (auto ty : types) {
+    for (auto unit : AllTimeUnits()) {
+      ArrayKernelExec exec;
+      switch (unit) {
+        case TimeUnit::SECOND: {
+          exec = SimpleUnaryFromOp<Op, std::chrono::seconds>(ty);
+        }
+        case TimeUnit::MILLI: {
+          exec = SimpleUnaryFromOp<Op, std::chrono::milliseconds>(ty);
+        }
+        case TimeUnit::MICRO: {
+          exec = SimpleUnaryFromOp<Op, std::chrono::microseconds>(ty);
+        }
+        case TimeUnit::NANO: {
+          exec = SimpleUnaryFromOp<Op, std::chrono::nanoseconds>(ty);
+        }
+      }
+      auto output_type =
+          struct_({field("iso_year", ty), field("iso_week", ty), field("weekday", ty)});
+      ScalarKernel kernel =
+          ScalarKernel({match::TimestampTypeUnit(unit)}, OutputType(output_type), exec);
+      DCHECK_OK(func->AddKernel(kernel));
+    }
+  }
+  return func;
+}
+
+const FunctionDoc year_doc{"Extract year values", "", {"values"}};
+const FunctionDoc month_doc{"Extract month values", "", {"values"}};
+const FunctionDoc day_doc{"Extract day values", "", {"values"}};
+const FunctionDoc day_of_week_doc{"Extract day of week values", "", {"values"}};
+const FunctionDoc day_of_year_doc{"Extract day of year values", "", {"values"}};
+const FunctionDoc iso_year_doc{"Extract ISO year values", "", {"values"}};
+const FunctionDoc iso_week_doc{"Extract ISO week values", "", {"values"}};
+const FunctionDoc iso_calendar_doc{"Extract ISO calendar values", "", {"values"}};
+const FunctionDoc quarter_doc{"Extract quarter values", "", {"values"}};
+const FunctionDoc hour_doc{"Extract hour values", "", {"values"}};
+const FunctionDoc minute_doc{"Extract minute values", "", {"values"}};
+const FunctionDoc second_doc{"Extract second values", "", {"values"}};
+const FunctionDoc millisecond_doc{"Extract millisecond values", "", {"values"}};
+const FunctionDoc microsecond_doc{"Extract microsecond values", "", {"values"}};
+const FunctionDoc nanosecond_doc{"Extract nanosecond values", "", {"values"}};
+const FunctionDoc subsecond_doc{"Extract subsecond values", "", {"values"}};
+
+void RegisterScalarTemporal(FunctionRegistry* registry) {
+  static std::vector<std::shared_ptr<DataType>> kUnsignedFloatTypes8 = {
+      uint8(), int8(),   uint16(), int16(),   uint32(),
+      int32(), uint64(), int64(),  float32(), float64()};
+  static std::vector<std::shared_ptr<DataType>> kUnsignedIntegerTypes8 = {
+      uint8(), int8(), uint16(), int16(), uint32(), int32(), uint64(), int64()};
+  static std::vector<std::shared_ptr<DataType>> kUnsignedIntegerTypes16 = {
+      uint16(), int16(), uint32(), int32(), uint64(), int64()};
+  static std::vector<std::shared_ptr<DataType>> kUnsignedIntegerTypes32 = {
+      uint32(), int32(), uint64(), int64()};
+  static std::vector<std::shared_ptr<DataType>> kSignedIntegerTypes = {int32(), int64()};

Review comment:
       I don't understand why you're having all these types. The input type is timestamp, right?

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract month from timestamp
+
+template <typename Duration>
+struct Month {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).month()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day from timestamp
+
+template <typename Duration>
+struct Day {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).day()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of week from timestamp
+
+template <typename Duration>
+struct DayOfWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(
+        weekday(year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))))
+            .iso_encoding());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of year from timestamp
+
+template <typename Duration>
+struct DayOfYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto sd = sys_days{floor<days>(Duration{arg})};
+    return static_cast<T>((sd - sys_days(year_month_day(sd).year() / jan / 0)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO Year values from timestamp
+
+template <typename Duration>
+struct ISOYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day{sys_days{floor<days>(Duration{arg})} + days{3}}.year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO week from timestamp
+
+// Based on
+// https://github.com/HowardHinnant/date/blob/6e921e1b1d21e84a5c82416ba7ecd98e33a436d0/include/date/iso_week.h#L1503
+template <typename Duration>
+struct ISOWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto dp = sys_days{floor<days>(Duration{arg})};
+    auto y = year_month_day{dp + days{3}}.year();
+    auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    if (dp < start) {
+      --y;
+      start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    }
+    return static_cast<T>(trunc<weeks>(dp - start).count() + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of quarter from timestamp
+
+template <typename Duration>
+struct Quarter {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto ymd = year_month_day(floor<days>(sys_time<Duration>(Duration{arg})));
+    return static_cast<T>((static_cast<const uint32_t>(ymd.month()) - 1) / 3 + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract hour from timestamp
+
+template <typename Duration>
+struct Hour {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<days>(t)) / std::chrono::hours(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract minute from timestamp
+
+template <typename Duration>
+struct Minute {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::hours>(t)) / std::chrono::minutes(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract second from timestamp
+
+template <typename Duration>
+struct Second {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        std::chrono::duration<double>(t - floor<std::chrono::minutes>(t)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract subsecond from timestamp
+
+template <typename Duration>
+struct Subsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::seconds>(t)) /
+                          std::chrono::nanoseconds(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract milliseconds from timestamp
+
+template <typename Duration>
+struct Millisecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::milliseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract microseconds from timestamp
+
+template <typename Duration>
+struct Microsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::microseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract nanoseconds from timestamp
+
+template <typename Duration>
+struct Nanosecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::nanoseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO calendar values from timestamp
+
+template <typename Duration, typename OutType>
+struct ISOCalendar {
+  using T = typename OutType::c_type;
+
+  static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+    using ScalarType = typename TypeTraits<OutType>::ScalarType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    if (!in.is_valid) {
+      out->is_valid = false;
+    } else {
+      const std::shared_ptr<DataType> iso_calendar_type =
+          struct_({field("iso_year", out_type), field("iso_week", out_type),
+                   field("weekday", out_type)});
+
+      const auto& in_val = internal::UnboxScalar<const TimestampType>::Unbox(in);
+      const auto dp = sys_days{floor<days>(Duration{in_val})};
+      const auto ymd = year_month_day(dp);
+      auto y = year_month_day{dp + days{3}}.year();
+      auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      if (dp < start) {
+        --y;
+        start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      }
+
+      std::vector<std::shared_ptr<Scalar>> values = {
+          std::make_shared<ScalarType>(static_cast<T>(static_cast<int32_t>(ymd.year()))),
+          std::make_shared<ScalarType>(
+              static_cast<T>(trunc<weeks>(dp - start).count() + 1)),
+          std::make_shared<ScalarType>(static_cast<T>(weekday(ymd).iso_encoding()))};
+      *checked_cast<StructScalar*>(out) = StructScalar(values, iso_calendar_type);
+    }
+    return Status::OK();
+  }
+
+  static Status Call(KernelContext* ctx, const ArrayData& in, ArrayData* out) {
+    using BuilderType = typename TypeTraits<OutType>::BuilderType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    const std::shared_ptr<DataType> iso_calendar_type =
+        struct_({field("iso_year", out_type), field("iso_week", out_type),
+                 field("weekday", out_type)});
+
+    std::unique_ptr<ArrayBuilder> array_builder;
+    RETURN_NOT_OK(MakeBuilder(ctx->memory_pool(), iso_calendar_type, &array_builder));
+    StructBuilder* struct_builder = checked_cast<StructBuilder*>(array_builder.get());
+
+    std::vector<BuilderType*> field_builders;
+    field_builders.reserve(3);
+    for (int i = 0; i < 3; i++) {
+      field_builders.push_back(
+          checked_cast<BuilderType*>(struct_builder->field_builder(i)));
+    }
+    auto visit_null = [&]() { return struct_builder->AppendNull(); };
+    auto visit_value = [&](int64_t arg) {
+      const auto dp = sys_days{floor<days>(Duration{arg})};
+      const auto ymd = year_month_day(dp);
+      auto y = year_month_day{dp + days{3}}.year();
+      auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      if (dp < start) {
+        --y;
+        start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      }
+
+      RETURN_NOT_OK(
+          field_builders[0]->Append(static_cast<T>(static_cast<int32_t>(ymd.year()))));
+      RETURN_NOT_OK(field_builders[1]->Append(
+          static_cast<T>(trunc<weeks>(dp - start).count() + 1)));
+      RETURN_NOT_OK(
+          field_builders[2]->Append(static_cast<T>(weekday(ymd).iso_encoding())));
+
+      return struct_builder->Append();
+    };
+    RETURN_NOT_OK(VisitArrayDataInline<OutType>(in, visit_value, visit_null));
+
+    std::shared_ptr<Array> out_array;
+    RETURN_NOT_OK(struct_builder->Finish(&out_array));
+    *out = *std::move(out_array->data());
+
+    return Status::OK();
+  }
+};
+
+// Generate a kernel given an arithmetic functor
+template <template <typename... Args> class KernelGenerator,
+          template <typename... Args> class Op, typename Duration>
+ArrayKernelExec ExecFromOp(detail::GetTypeId get_id) {
+  switch (get_id.id) {
+    case Type::INT8:
+      return KernelGenerator<Int8Type, Op<Duration>>::Exec;
+    case Type::UINT8:
+      return KernelGenerator<UInt8Type, Op<Duration>>::Exec;
+    case Type::INT16:
+      return KernelGenerator<Int16Type, Op<Duration>>::Exec;
+    case Type::UINT16:
+      return KernelGenerator<UInt16Type, Op<Duration>>::Exec;
+    case Type::INT32:
+      return KernelGenerator<Int32Type, Op<Duration>>::Exec;
+    case Type::UINT32:
+      return KernelGenerator<UInt32Type, Op<Duration>>::Exec;
+    case Type::INT64:
+    case Type::TIMESTAMP:
+      return KernelGenerator<Int64Type, Op<Duration>>::Exec;
+    case Type::UINT64:
+      return KernelGenerator<UInt64Type, Op<Duration>>::Exec;
+    case Type::FLOAT:
+      return KernelGenerator<FloatType, Op<Duration>>::Exec;
+    case Type::DOUBLE:
+      return KernelGenerator<DoubleType, Op<Duration>>::Exec;
+    default:
+      DCHECK(false);
+      return ExecFail;
+  }
+}
+
+template <template <typename...> class Op>
+std::shared_ptr<ScalarFunction> MakeTemporalFunction(
+    std::string name, const FunctionDoc* doc,
+    std::vector<std::shared_ptr<DataType>> types) {
+  auto func = std::make_shared<ScalarFunction>(name, Arity::Unary(), doc);
+
+  for (auto ty : types) {
+    for (auto unit : AllTimeUnits()) {
+      ArrayKernelExec exec;
+      switch (unit) {
+        case TimeUnit::SECOND: {
+          exec = ExecFromOp<ScalarUnaryTemporal, Op, std::chrono::seconds>(ty);
+        }
+        case TimeUnit::MILLI: {
+          exec = ExecFromOp<ScalarUnaryTemporal, Op, std::chrono::milliseconds>(ty);
+        }
+        case TimeUnit::MICRO: {
+          exec = ExecFromOp<ScalarUnaryTemporal, Op, std::chrono::microseconds>(ty);
+        }
+        case TimeUnit::NANO: {
+          exec = ExecFromOp<ScalarUnaryTemporal, Op, std::chrono::nanoseconds>(ty);
+        }
+      }
+      ScalarKernel kernel =
+          ScalarKernel({match::TimestampTypeUnit(unit)}, OutputType(ty), exec);
+      DCHECK_OK(func->AddKernel(kernel));
+    }
+  }
+  return func;
+}
+
+// Generate a kernel given an arithmetic functor
+template <template <typename... Args> class Op, typename Duration>
+ArrayKernelExec SimpleUnaryFromOp(detail::GetTypeId get_id) {
+  switch (get_id.id) {
+    case Type::INT32:
+      return SimpleUnary<Op<Duration, Int32Type>>;
+    case Type::INT64:
+      return SimpleUnary<Op<Duration, Int64Type>>;
+    default:
+      DCHECK(false);
+      return ExecFail;
+  }
+}
+
+template <template <typename...> class Op>
+std::shared_ptr<ScalarFunction> MakeSimpleUnaryTemporalFunction(
+    std::string name, const FunctionDoc* doc,
+    std::vector<std::shared_ptr<DataType>> types) {
+  auto func = std::make_shared<ScalarFunction>(name, Arity::Unary(), doc);
+
+  for (auto ty : types) {
+    for (auto unit : AllTimeUnits()) {
+      ArrayKernelExec exec;
+      switch (unit) {
+        case TimeUnit::SECOND: {
+          exec = SimpleUnaryFromOp<Op, std::chrono::seconds>(ty);
+        }
+        case TimeUnit::MILLI: {
+          exec = SimpleUnaryFromOp<Op, std::chrono::milliseconds>(ty);
+        }
+        case TimeUnit::MICRO: {
+          exec = SimpleUnaryFromOp<Op, std::chrono::microseconds>(ty);
+        }
+        case TimeUnit::NANO: {
+          exec = SimpleUnaryFromOp<Op, std::chrono::nanoseconds>(ty);
+        }
+      }
+      auto output_type =
+          struct_({field("iso_year", ty), field("iso_week", ty), field("weekday", ty)});
+      ScalarKernel kernel =
+          ScalarKernel({match::TimestampTypeUnit(unit)}, OutputType(output_type), exec);
+      DCHECK_OK(func->AddKernel(kernel));
+    }
+  }
+  return func;
+}
+
+const FunctionDoc year_doc{"Extract year values", "", {"values"}};
+const FunctionDoc month_doc{"Extract month values", "", {"values"}};
+const FunctionDoc day_doc{"Extract day values", "", {"values"}};
+const FunctionDoc day_of_week_doc{"Extract day of week values", "", {"values"}};
+const FunctionDoc day_of_year_doc{"Extract day of year values", "", {"values"}};
+const FunctionDoc iso_year_doc{"Extract ISO year values", "", {"values"}};
+const FunctionDoc iso_week_doc{"Extract ISO week values", "", {"values"}};
+const FunctionDoc iso_calendar_doc{"Extract ISO calendar values", "", {"values"}};
+const FunctionDoc quarter_doc{"Extract quarter values", "", {"values"}};
+const FunctionDoc hour_doc{"Extract hour values", "", {"values"}};
+const FunctionDoc minute_doc{"Extract minute values", "", {"values"}};
+const FunctionDoc second_doc{"Extract second values", "", {"values"}};
+const FunctionDoc millisecond_doc{"Extract millisecond values", "", {"values"}};
+const FunctionDoc microsecond_doc{"Extract microsecond values", "", {"values"}};
+const FunctionDoc nanosecond_doc{"Extract nanosecond values", "", {"values"}};
+const FunctionDoc subsecond_doc{"Extract subsecond values", "", {"values"}};

Review comment:
       Can you make an effort for these documentations, as for the C++ docstrings? You can take a look at how other compute functions are documented.

##########
File path: cpp/src/arrow/compute/api_scalar.h
##########
@@ -462,5 +462,177 @@ ARROW_EXPORT
 Result<Datum> FillNull(const Datum& values, const Datum& fill_value,
                        ExecContext* ctx = NULLPTR);
 
+/// \brief Year returns year value for each element of `values`
+///
+/// \param[in] values input to extract year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Year(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Month returns month value for each element of `values`
+///
+/// \param[in] values input to extract month from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Month(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Day returns day value for each element of `values`

Review comment:
       "Day number" perhaps?

##########
File path: docs/source/cpp/compute.rst
##########
@@ -637,6 +637,54 @@ String extraction
   e.g. 'letter' and 'digit' for the regular expression
   ``(?P<letter>[ab])(?P<digit>\\d)``.
 
+Temporal component extraction
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+These functions extract datetime components (year, month, day, etc) from timestamp type.
+Note: timezone information is currently ignored if present.
+
++--------------------+------------+-------------------+-----------------+--------+
+| Function name      | Arity      | Input types       | Output type     | Notes  |
++====================+============+===================+=================+========+
+| year               | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| month              | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| day                | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| day_of_week        | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| day_of_year        | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| iso_year           | Unary      | Temporal          | Numeric         | \(1)   |
++--------------------+------------+-------------------+-----------------+--------+
+| iso_week           | Unary      | Temporal          | Numeric         | \(1)   |
++--------------------+------------+-------------------+-----------------+--------+
+| iso_calendar       | Unary      | Temporal          | Scalar Struct   | \(2)   |
++--------------------+------------+-------------------+-----------------+--------+
+| quarter            | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| hour               | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| minute             | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| second             | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| millisecond        | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| microsecond        | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| nanosecond         | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| subsecond          | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+
+* \(1) The ISO 8601 definition for week 01 is the week with the first Thursday
+  of the Gregorian year (i.e. of January) in it.
+  .. _Wikipedia ISO Week date: https://en.wikipedia.org/wiki/ISO_week_date#First_week

Review comment:
       I don't think this is a valid reST hyperlink :-)

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal_test.cc
##########
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+#include "arrow/compute/api_scalar.h"
+#include "arrow/compute/kernels/test_util.h"
+#include "arrow/util/checked_cast.h"
+#include "arrow/util/formatting.h"
+
+namespace arrow {
+
+using internal::StringFormatter;
+
+class ScalarTemporalTest : public ::testing::Test {};
+
+namespace compute {
+
+TEST(ScalarTemporalTest, TestSimpleTemporalComponentExtraction) {
+  const char* times =
+      R"(["1970-01-01T00:00:59.123456789","2000-02-29T23:23:23.999999999",
+          "1899-01-01T00:59:20.001001001","2033-05-18T03:33:20.000000000", null])";
+  auto unit = timestamp(TimeUnit::NANO);
+  auto timestamps = ArrayFromJSON(unit, times);
+  auto iso_calendar_type =
+      struct_({field("iso_year", int64()), field("iso_week", int64()),
+               field("weekday", int64())});
+
+  auto year = "[1970, 2000, 1899, 2033, null]";
+  auto month = "[1, 2, 1, 5, null]";
+  auto day = "[1, 29, 1, 18, null]";
+  auto day_of_week = "[4, 2, 7, 3, null]";
+  auto day_of_year = "[1, 60, 1, 138, null]";
+  auto iso_year = "[1970, 2000, 1899, 2033, null]";
+  auto iso_week = "[1, 9, 52, 20, null]";
+  auto iso_calendar = ArrayFromJSON(iso_calendar_type,
+                                    R"([{"iso_year": 1970, "iso_week": 1, "weekday": 4},

Review comment:
       Should it be `week_day`?

##########
File path: cpp/src/arrow/compute/api_scalar.h
##########
@@ -462,5 +462,177 @@ ARROW_EXPORT
 Result<Datum> FillNull(const Datum& values, const Datum& fill_value,
                        ExecContext* ctx = NULLPTR);
 
+/// \brief Year returns year value for each element of `values`
+///
+/// \param[in] values input to extract year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Year(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Month returns month value for each element of `values`
+///
+/// \param[in] values input to extract month from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Month(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Day returns day value for each element of `values`
+///
+/// \param[in] values input to extract day from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Day(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief DayOfWeek returns day of the week value for each element of `values`
+///
+/// \param[in] values input to extract dat of the week from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT Result<Datum> DayOfWeek(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief DayOfYear returns day of year value for each element of `values`
+///
+/// \param[in] values input to extract day of year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT Result<Datum> DayOfYear(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief ISOYear returns ISO year value for each element of `values`
+///
+/// \param[in] values input to extract ISO year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> ISOYear(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief ISOWeek returns ISO week of year value for each element of `values`
+///
+/// \param[in] values input to extract ISO week of year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT Result<Datum> ISOWeek(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief ISOCalendar returns a (year, ISO week, weekday) struct for each element of
+/// `values`
+///
+/// \param[in] values input to ISO calendar struct from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT Result<Datum> ISOCalendar(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Quarter returns quarter of year value for each element of `values`

Review comment:
       I think you will be able to guess my next questions...

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal_test.cc
##########
@@ -0,0 +1,107 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+#include "arrow/compute/api_scalar.h"
+#include "arrow/compute/kernels/test_util.h"
+#include "arrow/util/checked_cast.h"
+#include "arrow/util/formatting.h"
+
+namespace arrow {
+
+using internal::StringFormatter;
+
+class ScalarTemporalTest : public ::testing::Test {};
+
+namespace compute {
+
+TEST(ScalarTemporalTest, TestSimpleTemporalComponentExtraction) {
+  const char* times =
+      R"(["1970-01-01T00:00:59.123456789","2000-02-29T23:23:23.999999999",
+          "1899-01-01T00:59:20.001001001","2033-05-18T03:33:20.000000000", null])";
+  auto unit = timestamp(TimeUnit::NANO);
+  auto timestamps = ArrayFromJSON(unit, times);
+  auto iso_calendar_type =
+      struct_({field("iso_year", int64()), field("iso_week", int64()),
+               field("weekday", int64())});
+
+  auto year = "[1970, 2000, 1899, 2033, null]";
+  auto month = "[1, 2, 1, 5, null]";
+  auto day = "[1, 29, 1, 18, null]";
+  auto day_of_week = "[4, 2, 7, 3, null]";
+  auto day_of_year = "[1, 60, 1, 138, null]";
+  auto iso_year = "[1970, 2000, 1899, 2033, null]";
+  auto iso_week = "[1, 9, 52, 20, null]";
+  auto iso_calendar = ArrayFromJSON(iso_calendar_type,
+                                    R"([{"iso_year": 1970, "iso_week": 1, "weekday": 4},
+                        {"iso_year": 2000, "iso_week": 9, "weekday": 2},
+                        {"iso_year": 1899, "iso_week": 52, "weekday": 7},
+                        {"iso_year": 2033, "iso_week": 20, "weekday": 3}, null])");
+  auto quarter = "[1, 1, 1, 2, null]";
+  auto hour = "[0, 23, 0, 3, null]";
+  auto minute = "[0, 23, 59, 33, null]";
+  auto second = "[59.123456789, 23.999999999, 20.001001001, 20.0, null]";
+  auto millisecond = "[123, 999, 1, 0, null]";
+  auto microsecond = "[456, 999, 1, 0, null]";
+  auto nanosecond = "[789, 999, 1, 0, null]";
+  auto subsecond = "[123456789, 999999999, 1001001, 0, null]";
+
+  CheckScalarUnary("year", unit, times, int64(), year);
+  CheckScalarUnary("month", unit, times, int64(), month);
+  CheckScalarUnary("day", unit, times, int64(), day);
+  CheckScalarUnary("day_of_week", unit, times, int64(), day_of_week);
+  CheckScalarUnary("day_of_year", unit, times, int64(), day_of_year);
+  CheckScalarUnary("iso_year", unit, times, int64(), iso_year);
+  CheckScalarUnary("iso_week", unit, times, int64(), iso_week);
+  CheckScalarUnary("iso_calendar", timestamps, iso_calendar);
+  CheckScalarUnary("quarter", unit, times, int64(), quarter);
+  CheckScalarUnary("hour", unit, times, int64(), hour);
+  CheckScalarUnary("minute", unit, times, int64(), minute);
+  CheckScalarUnary("second", unit, times, float64(), second);
+  CheckScalarUnary("millisecond", unit, times, int64(), millisecond);
+  CheckScalarUnary("microsecond", unit, times, int64(), microsecond);
+  CheckScalarUnary("nanosecond", unit, times, int64(), nanosecond);
+  CheckScalarUnary("subsecond", unit, times, int64(), subsecond);
+}
+
+TEST(ScalarTemporalTest, TestZonedTemporalComponentExtraction) {
+  std::string timezone = "Etc/UTC-2";
+  const char* times =
+      R"(["1970-01-01T00:00:59.123456789","2000-02-29T23:23:23.999999999",
+          "1899-01-01T00:59:20.001001001","2033-05-18T03:33:20.000000000", null])";
+  auto unit = timestamp(TimeUnit::NANO, timezone);
+  auto timestamps = ArrayFromJSON(unit, times);
+
+  ASSERT_RAISES(Invalid, Year(timestamps));
+  ASSERT_RAISES(Invalid, Month(timestamps));
+  ASSERT_RAISES(Invalid, Day(timestamps));
+  ASSERT_RAISES(Invalid, DayOfWeek(timestamps));
+  ASSERT_RAISES(Invalid, DayOfYear(timestamps));
+  ASSERT_RAISES(Invalid, ISOYear(timestamps));
+  ASSERT_RAISES(Invalid, ISOWeek(timestamps));
+  ASSERT_RAISES(Invalid, ISOCalendar(timestamps));
+  ASSERT_RAISES(Invalid, Quarter(timestamps));
+  ASSERT_RAISES(Invalid, Hour(timestamps));
+  ASSERT_RAISES(Invalid, Minute(timestamps));
+  ASSERT_RAISES(Invalid, Second(timestamps));
+  ASSERT_RAISES(Invalid, Millisecond(timestamps));
+  ASSERT_RAISES(Invalid, Microsecond(timestamps));
+  ASSERT_RAISES(Invalid, Nanosecond(timestamps));
+  ASSERT_RAISES(Invalid, Subsecond(timestamps));

Review comment:
       Why are these invalid? IMHO, the timezone should simply ignored.

##########
File path: cpp/src/arrow/compute/api_scalar.h
##########
@@ -462,5 +462,177 @@ ARROW_EXPORT
 Result<Datum> FillNull(const Datum& values, const Datum& fill_value,
                        ExecContext* ctx = NULLPTR);
 
+/// \brief Year returns year value for each element of `values`
+///
+/// \param[in] values input to extract year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Year(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Month returns month value for each element of `values`
+///
+/// \param[in] values input to extract month from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Month(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief Day returns day value for each element of `values`
+///
+/// \param[in] values input to extract day from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT
+Result<Datum> Day(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief DayOfWeek returns day of the week value for each element of `values`
+///
+/// \param[in] values input to extract dat of the week from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT Result<Datum> DayOfWeek(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief DayOfYear returns day of year value for each element of `values`
+///
+/// \param[in] values input to extract day of year from
+/// \param[in] ctx the function execution context, optional
+/// \return the resulting datum
+///
+/// \since 4.0.0
+/// \note API not yet finalized
+ARROW_EXPORT Result<Datum> DayOfYear(const Datum& values, ExecContext* ctx = NULLPTR);
+
+/// \brief ISOYear returns ISO year value for each element of `values`

Review comment:
       What is a "ISO year"?

##########
File path: docs/source/cpp/compute.rst
##########
@@ -637,6 +637,54 @@ String extraction
   e.g. 'letter' and 'digit' for the regular expression
   ``(?P<letter>[ab])(?P<digit>\\d)``.
 
+Temporal component extraction
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+These functions extract datetime components (year, month, day, etc) from timestamp type.
+Note: timezone information is currently ignored if present.
+
++--------------------+------------+-------------------+-----------------+--------+
+| Function name      | Arity      | Input types       | Output type     | Notes  |
++====================+============+===================+=================+========+
+| year               | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| month              | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| day                | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| day_of_week        | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| day_of_year        | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| iso_year           | Unary      | Temporal          | Numeric         | \(1)   |
++--------------------+------------+-------------------+-----------------+--------+
+| iso_week           | Unary      | Temporal          | Numeric         | \(1)   |
++--------------------+------------+-------------------+-----------------+--------+
+| iso_calendar       | Unary      | Temporal          | Scalar Struct   | \(2)   |
++--------------------+------------+-------------------+-----------------+--------+
+| quarter            | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| hour               | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| minute             | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| second             | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| millisecond        | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| microsecond        | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| nanosecond         | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+| subsecond          | Unary      | Temporal          | Numeric         |        |
++--------------------+------------+-------------------+-----------------+--------+
+
+* \(1) The ISO 8601 definition for week 01 is the week with the first Thursday
+  of the Gregorian year (i.e. of January) in it.
+  .. _Wikipedia ISO Week date: https://en.wikipedia.org/wiki/ISO_week_date#First_week
+
+* \(2) Struct with fields ISO year, ISO week number, and weekday.

Review comment:
       Can you give the field names precisely? You'll find other examples of this in this documentation file.

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract month from timestamp
+
+template <typename Duration>
+struct Month {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).month()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day from timestamp
+
+template <typename Duration>
+struct Day {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).day()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of week from timestamp
+
+template <typename Duration>
+struct DayOfWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(
+        weekday(year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))))
+            .iso_encoding());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of year from timestamp
+
+template <typename Duration>
+struct DayOfYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto sd = sys_days{floor<days>(Duration{arg})};

Review comment:
       I'm curious: why do you use `floor<days>(sys_time<Duration>(Duration{arg}))` above and `sys_days{floor<days>(Duration{arg})}` here? What's the difference?

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract month from timestamp
+
+template <typename Duration>
+struct Month {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).month()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day from timestamp
+
+template <typename Duration>
+struct Day {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).day()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of week from timestamp
+
+template <typename Duration>
+struct DayOfWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(
+        weekday(year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))))
+            .iso_encoding());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of year from timestamp
+
+template <typename Duration>
+struct DayOfYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto sd = sys_days{floor<days>(Duration{arg})};
+    return static_cast<T>((sd - sys_days(year_month_day(sd).year() / jan / 0)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO Year values from timestamp
+
+template <typename Duration>
+struct ISOYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day{sys_days{floor<days>(Duration{arg})} + days{3}}.year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO week from timestamp
+
+// Based on
+// https://github.com/HowardHinnant/date/blob/6e921e1b1d21e84a5c82416ba7ecd98e33a436d0/include/date/iso_week.h#L1503
+template <typename Duration>
+struct ISOWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto dp = sys_days{floor<days>(Duration{arg})};
+    auto y = year_month_day{dp + days{3}}.year();
+    auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    if (dp < start) {
+      --y;
+      start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    }
+    return static_cast<T>(trunc<weeks>(dp - start).count() + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of quarter from timestamp
+
+template <typename Duration>
+struct Quarter {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto ymd = year_month_day(floor<days>(sys_time<Duration>(Duration{arg})));
+    return static_cast<T>((static_cast<const uint32_t>(ymd.month()) - 1) / 3 + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract hour from timestamp
+
+template <typename Duration>
+struct Hour {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<days>(t)) / std::chrono::hours(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract minute from timestamp
+
+template <typename Duration>
+struct Minute {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::hours>(t)) / std::chrono::minutes(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract second from timestamp
+
+template <typename Duration>
+struct Second {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        std::chrono::duration<double>(t - floor<std::chrono::minutes>(t)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract subsecond from timestamp
+
+template <typename Duration>
+struct Subsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::seconds>(t)) /
+                          std::chrono::nanoseconds(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract milliseconds from timestamp
+
+template <typename Duration>
+struct Millisecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::milliseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract microseconds from timestamp
+
+template <typename Duration>
+struct Microsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::microseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract nanoseconds from timestamp
+
+template <typename Duration>
+struct Nanosecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::nanoseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO calendar values from timestamp
+
+template <typename Duration, typename OutType>
+struct ISOCalendar {
+  using T = typename OutType::c_type;
+
+  static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+    using ScalarType = typename TypeTraits<OutType>::ScalarType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    if (!in.is_valid) {
+      out->is_valid = false;
+    } else {
+      const std::shared_ptr<DataType> iso_calendar_type =
+          struct_({field("iso_year", out_type), field("iso_week", out_type),
+                   field("weekday", out_type)});
+
+      const auto& in_val = internal::UnboxScalar<const TimestampType>::Unbox(in);
+      const auto dp = sys_days{floor<days>(Duration{in_val})};
+      const auto ymd = year_month_day(dp);
+      auto y = year_month_day{dp + days{3}}.year();
+      auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      if (dp < start) {
+        --y;
+        start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      }
+
+      std::vector<std::shared_ptr<Scalar>> values = {
+          std::make_shared<ScalarType>(static_cast<T>(static_cast<int32_t>(ymd.year()))),
+          std::make_shared<ScalarType>(
+              static_cast<T>(trunc<weeks>(dp - start).count() + 1)),
+          std::make_shared<ScalarType>(static_cast<T>(weekday(ymd).iso_encoding()))};
+      *checked_cast<StructScalar*>(out) = StructScalar(values, iso_calendar_type);
+    }
+    return Status::OK();
+  }
+
+  static Status Call(KernelContext* ctx, const ArrayData& in, ArrayData* out) {
+    using BuilderType = typename TypeTraits<OutType>::BuilderType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    const std::shared_ptr<DataType> iso_calendar_type =
+        struct_({field("iso_year", out_type), field("iso_week", out_type),
+                 field("weekday", out_type)});
+
+    std::unique_ptr<ArrayBuilder> array_builder;
+    RETURN_NOT_OK(MakeBuilder(ctx->memory_pool(), iso_calendar_type, &array_builder));
+    StructBuilder* struct_builder = checked_cast<StructBuilder*>(array_builder.get());
+
+    std::vector<BuilderType*> field_builders;
+    field_builders.reserve(3);
+    for (int i = 0; i < 3; i++) {
+      field_builders.push_back(
+          checked_cast<BuilderType*>(struct_builder->field_builder(i)));
+    }
+    auto visit_null = [&]() { return struct_builder->AppendNull(); };
+    auto visit_value = [&](int64_t arg) {
+      const auto dp = sys_days{floor<days>(Duration{arg})};
+      const auto ymd = year_month_day(dp);
+      auto y = year_month_day{dp + days{3}}.year();
+      auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      if (dp < start) {
+        --y;
+        start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      }
+
+      RETURN_NOT_OK(
+          field_builders[0]->Append(static_cast<T>(static_cast<int32_t>(ymd.year()))));
+      RETURN_NOT_OK(field_builders[1]->Append(
+          static_cast<T>(trunc<weeks>(dp - start).count() + 1)));
+      RETURN_NOT_OK(
+          field_builders[2]->Append(static_cast<T>(weekday(ymd).iso_encoding())));
+
+      return struct_builder->Append();
+    };
+    RETURN_NOT_OK(VisitArrayDataInline<OutType>(in, visit_value, visit_null));
+
+    std::shared_ptr<Array> out_array;
+    RETURN_NOT_OK(struct_builder->Finish(&out_array));
+    *out = *std::move(out_array->data());
+
+    return Status::OK();
+  }
+};
+
+// Generate a kernel given an arithmetic functor
+template <template <typename... Args> class KernelGenerator,
+          template <typename... Args> class Op, typename Duration>
+ArrayKernelExec ExecFromOp(detail::GetTypeId get_id) {
+  switch (get_id.id) {

Review comment:
       Why is this useful? The only input type accepted is timestamp, right?

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract month from timestamp
+
+template <typename Duration>
+struct Month {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).month()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day from timestamp
+
+template <typename Duration>
+struct Day {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).day()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of week from timestamp
+
+template <typename Duration>
+struct DayOfWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(
+        weekday(year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))))
+            .iso_encoding());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of year from timestamp
+
+template <typename Duration>
+struct DayOfYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto sd = sys_days{floor<days>(Duration{arg})};
+    return static_cast<T>((sd - sys_days(year_month_day(sd).year() / jan / 0)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO Year values from timestamp
+
+template <typename Duration>
+struct ISOYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day{sys_days{floor<days>(Duration{arg})} + days{3}}.year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO week from timestamp
+
+// Based on
+// https://github.com/HowardHinnant/date/blob/6e921e1b1d21e84a5c82416ba7ecd98e33a436d0/include/date/iso_week.h#L1503
+template <typename Duration>
+struct ISOWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto dp = sys_days{floor<days>(Duration{arg})};
+    auto y = year_month_day{dp + days{3}}.year();
+    auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    if (dp < start) {
+      --y;
+      start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    }
+    return static_cast<T>(trunc<weeks>(dp - start).count() + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of quarter from timestamp
+
+template <typename Duration>
+struct Quarter {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto ymd = year_month_day(floor<days>(sys_time<Duration>(Duration{arg})));
+    return static_cast<T>((static_cast<const uint32_t>(ymd.month()) - 1) / 3 + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract hour from timestamp
+
+template <typename Duration>
+struct Hour {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<days>(t)) / std::chrono::hours(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract minute from timestamp
+
+template <typename Duration>
+struct Minute {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::hours>(t)) / std::chrono::minutes(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract second from timestamp
+
+template <typename Duration>
+struct Second {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        std::chrono::duration<double>(t - floor<std::chrono::minutes>(t)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract subsecond from timestamp
+
+template <typename Duration>
+struct Subsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::seconds>(t)) /
+                          std::chrono::nanoseconds(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract milliseconds from timestamp
+
+template <typename Duration>
+struct Millisecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::milliseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract microseconds from timestamp
+
+template <typename Duration>
+struct Microsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::microseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract nanoseconds from timestamp
+
+template <typename Duration>
+struct Nanosecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::nanoseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO calendar values from timestamp
+
+template <typename Duration, typename OutType>
+struct ISOCalendar {
+  using T = typename OutType::c_type;
+
+  static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+    using ScalarType = typename TypeTraits<OutType>::ScalarType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    if (!in.is_valid) {
+      out->is_valid = false;
+    } else {
+      const std::shared_ptr<DataType> iso_calendar_type =
+          struct_({field("iso_year", out_type), field("iso_week", out_type),
+                   field("weekday", out_type)});
+
+      const auto& in_val = internal::UnboxScalar<const TimestampType>::Unbox(in);
+      const auto dp = sys_days{floor<days>(Duration{in_val})};
+      const auto ymd = year_month_day(dp);
+      auto y = year_month_day{dp + days{3}}.year();
+      auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      if (dp < start) {
+        --y;
+        start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      }

Review comment:
       Can you try to factor out code that's repeated between the `Scalar` and `ArrayData` implementations?

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -0,0 +1,614 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/builder.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/util/time.h"
+#include "arrow/vendored/datetime.h"
+
+namespace arrow {
+
+namespace compute {
+namespace internal {
+
+using applicator::ScalarUnaryNotNull;
+using applicator::SimpleUnary;
+using arrow_vendored::date::days;
+using arrow_vendored::date::floor;
+using arrow_vendored::date::hh_mm_ss;
+using arrow_vendored::date::sys_days;
+using arrow_vendored::date::sys_time;
+using arrow_vendored::date::trunc;
+using arrow_vendored::date::weekday;
+using arrow_vendored::date::weeks;
+using arrow_vendored::date::year_month_day;
+using arrow_vendored::date::years;
+using arrow_vendored::date::literals::dec;
+using arrow_vendored::date::literals::jan;
+using arrow_vendored::date::literals::last;
+using arrow_vendored::date::literals::mon;
+using arrow_vendored::date::literals::thu;
+
+// Based on ScalarUnaryNotNullStateful. Adds timezone awareness.
+template <typename OutType, typename Op>
+struct ScalarUnaryStatefulTemporal {
+  using ThisType = ScalarUnaryStatefulTemporal<OutType, Op>;
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  Op op;
+  explicit ScalarUnaryStatefulTemporal(Op op) : op(std::move(op)) {}
+
+  template <typename Type>
+  struct ArrayExec {
+    static Status Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
+                       Datum* out) {
+      const std::string timezone =
+          std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+      Status st = Status::OK();
+      ArrayData* out_arr = out->mutable_array();
+      auto out_data = out_arr->GetMutableValues<OutValue>(1);
+
+      if (timezone.empty()) {
+        VisitArrayValuesInline<Int64Type>(
+            arg0,
+            [&](int64_t v) {
+              *out_data++ = functor.op.template Call<OutValue>(ctx, v, &st);
+            },
+            [&]() {
+              // null
+              ++out_data;
+            });
+      } else {
+        st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+      }
+      return st;
+    }
+  };
+
+  Status Scalar(KernelContext* ctx, const Scalar& arg0, Datum* out) {
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(arg0.type)->timezone();
+    Status st = Status::OK();
+    if (timezone.empty()) {
+      if (arg0.is_valid) {
+        int64_t arg0_val = UnboxScalar<Int64Type>::Unbox(arg0);
+        BoxScalar<OutType>::Box(this->op.template Call<OutValue>(ctx, arg0_val, &st),
+                                out->scalar().get());
+      }
+    } else {
+      st = Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                           timezone);
+    }
+    return st;
+  }
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    if (batch[0].kind() == Datum::ARRAY) {
+      return ArrayExec<OutType>::Exec(*this, ctx, *batch[0].array(), out);
+    } else {
+      return Scalar(ctx, *batch[0].scalar(), out);
+    }
+  }
+};
+
+template <typename OutType, typename Op>
+struct ScalarUnaryTemporal {
+  using OutValue = typename GetOutputType<OutType>::T;
+
+  static Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    // Seed kernel with dummy state
+    ScalarUnaryStatefulTemporal<OutType, Op> kernel({});
+    return kernel.Exec(ctx, batch, out);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract year from timestamp
+
+template <typename Duration>
+struct Year {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract month from timestamp
+
+template <typename Duration>
+struct Month {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).month()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day from timestamp
+
+template <typename Duration>
+struct Day {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const uint32_t>(
+        year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))).day()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of week from timestamp
+
+template <typename Duration>
+struct DayOfWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(
+        weekday(year_month_day(floor<days>(sys_time<Duration>(Duration{arg}))))
+            .iso_encoding());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of year from timestamp
+
+template <typename Duration>
+struct DayOfYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto sd = sys_days{floor<days>(Duration{arg})};
+    return static_cast<T>((sd - sys_days(year_month_day(sd).year() / jan / 0)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO Year values from timestamp
+
+template <typename Duration>
+struct ISOYear {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    return static_cast<T>(static_cast<const int32_t>(
+        year_month_day{sys_days{floor<days>(Duration{arg})} + days{3}}.year()));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO week from timestamp
+
+// Based on
+// https://github.com/HowardHinnant/date/blob/6e921e1b1d21e84a5c82416ba7ecd98e33a436d0/include/date/iso_week.h#L1503
+template <typename Duration>
+struct ISOWeek {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto dp = sys_days{floor<days>(Duration{arg})};
+    auto y = year_month_day{dp + days{3}}.year();
+    auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    if (dp < start) {
+      --y;
+      start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+    }
+    return static_cast<T>(trunc<weeks>(dp - start).count() + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract day of quarter from timestamp
+
+template <typename Duration>
+struct Quarter {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    const auto ymd = year_month_day(floor<days>(sys_time<Duration>(Duration{arg})));
+    return static_cast<T>((static_cast<const uint32_t>(ymd.month()) - 1) / 3 + 1);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract hour from timestamp
+
+template <typename Duration>
+struct Hour {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<days>(t)) / std::chrono::hours(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract minute from timestamp
+
+template <typename Duration>
+struct Minute {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::hours>(t)) / std::chrono::minutes(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract second from timestamp
+
+template <typename Duration>
+struct Second {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        std::chrono::duration<double>(t - floor<std::chrono::minutes>(t)).count());
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract subsecond from timestamp
+
+template <typename Duration>
+struct Subsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>((t - floor<std::chrono::seconds>(t)) /
+                          std::chrono::nanoseconds(1));
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract milliseconds from timestamp
+
+template <typename Duration>
+struct Millisecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::milliseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract microseconds from timestamp
+
+template <typename Duration>
+struct Microsecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::microseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract nanoseconds from timestamp
+
+template <typename Duration>
+struct Nanosecond {
+  template <typename T>
+  static T Call(KernelContext*, int64_t arg, Status*) {
+    Duration t = Duration{arg};
+    return static_cast<T>(
+        ((t - floor<std::chrono::seconds>(t)) / std::chrono::nanoseconds(1)) % 1000);
+  }
+};
+
+// ----------------------------------------------------------------------
+// Extract ISO calendar values from timestamp
+
+template <typename Duration, typename OutType>
+struct ISOCalendar {
+  using T = typename OutType::c_type;
+
+  static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+    using ScalarType = typename TypeTraits<OutType>::ScalarType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    if (!in.is_valid) {
+      out->is_valid = false;
+    } else {
+      const std::shared_ptr<DataType> iso_calendar_type =
+          struct_({field("iso_year", out_type), field("iso_week", out_type),
+                   field("weekday", out_type)});
+
+      const auto& in_val = internal::UnboxScalar<const TimestampType>::Unbox(in);
+      const auto dp = sys_days{floor<days>(Duration{in_val})};
+      const auto ymd = year_month_day(dp);
+      auto y = year_month_day{dp + days{3}}.year();
+      auto start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      if (dp < start) {
+        --y;
+        start = sys_days((y - years{1}) / dec / thu[last]) + (mon - thu);
+      }
+
+      std::vector<std::shared_ptr<Scalar>> values = {
+          std::make_shared<ScalarType>(static_cast<T>(static_cast<int32_t>(ymd.year()))),
+          std::make_shared<ScalarType>(
+              static_cast<T>(trunc<weeks>(dp - start).count() + 1)),
+          std::make_shared<ScalarType>(static_cast<T>(weekday(ymd).iso_encoding()))};
+      *checked_cast<StructScalar*>(out) = StructScalar(values, iso_calendar_type);
+    }
+    return Status::OK();
+  }
+
+  static Status Call(KernelContext* ctx, const ArrayData& in, ArrayData* out) {
+    using BuilderType = typename TypeTraits<OutType>::BuilderType;
+    const auto& out_type = TypeTraits<OutType>::type_singleton();
+
+    const std::string timezone =
+        std::static_pointer_cast<const TimestampType>(in.type)->timezone();
+    if (!timezone.empty()) {
+      return Status::Invalid("Timezone aware timestamps not supported. Timezone found: ",
+                             timezone);
+    }
+
+    const std::shared_ptr<DataType> iso_calendar_type =
+        struct_({field("iso_year", out_type), field("iso_week", out_type),
+                 field("weekday", out_type)});
+
+    std::unique_ptr<ArrayBuilder> array_builder;
+    RETURN_NOT_OK(MakeBuilder(ctx->memory_pool(), iso_calendar_type, &array_builder));
+    StructBuilder* struct_builder = checked_cast<StructBuilder*>(array_builder.get());

Review comment:
       You can also call `Reserve` here to presize the result array. 




-- 
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:
users@infra.apache.org