Abdullahsab3 commented on code in PR #5826:
URL: https://github.com/apache/arrow-rs/pull/5826#discussion_r1622863186
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -577,10 +579,95 @@ fn timestamp_to_date32<T: ArrowTimestampType>(
/// (i.e. casting `6.4999` to Decimal(10, 1) becomes `6.5`). Prior to
version `26.0.0`,
/// casting would truncate instead (i.e. outputs `6.4` instead)
///
-/// Unsupported Casts
+/// Unsupported Casts (check with `can_cast_types` before calling):
/// * To or from `StructArray`
/// * List to primitive
/// * Interval and duration
+///
+/// # Timestamps and Timezones
+///
+/// Timestamps are stored with an optional timezone in Arrow.
+///
+/// ## Casting timestamps to a timestamp without timezone / UTC
+/// ```
+/// # use arrow_array::Int64Array;
+/// # use arrow_array::types::TimestampSecondType;
+/// # use arrow_cast::{cast, display};
+/// # use arrow_array::cast::AsArray;
+/// # use arrow_schema::{DataType, TimeUnit};
+/// // can use "UTC" if chrono-tz feature is enabled, here use offset based
timezone
+/// let data_type = DataType::Timestamp(TimeUnit::Second, None);
+/// let a = Int64Array::from(vec![1_000_000_000, 2_000_000_000,
3_000_000_000]);
+/// let b = cast(&a, &data_type).unwrap();
+/// let b = b.as_primitive::<TimestampSecondType>(); // downcast to result type
+/// assert_eq!(2_000_000_000, b.value(1)); // values are the same as the type
has no timezone
+/// // use display to show them (note has no trailing Z)
+/// assert_eq!("2033-05-18T03:33:20", display::array_value_to_string(&b,
1).unwrap());
+/// ```
+///
+/// ## Casting timestamps to a timestamp with timezone
+///
+/// Similarly to the previous example, if you cast numeric values to a
timestamp
+/// with timezone, the cast kernel will not change the underlying values
+/// but display and othe functions will interpret them as being in the
provided timezone.
Review Comment:
other functions
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]