MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_timestamp_cast_utf8

Function test_timestamp_cast_utf8

arrow/tests/array_cast.rs:592–623  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

590
591#[test]
592fn test_timestamp_cast_utf8() {
593 let array: PrimitiveArray<TimestampMicrosecondType> =
594 vec![Some(37800000000), None, Some(86339000000)].into();
595 let out = cast(&array, &DataType::Utf8).unwrap();
596
597 let expected = StringArray::from(vec![
598 Some("1970-01-01T10:30:00"),
599 None,
600 Some("1970-01-01T23:58:59"),
601 ]);
602
603 assert_eq!(
604 out.as_any().downcast_ref::<StringArray>().unwrap(),
605 &expected
606 );
607
608 let array: PrimitiveArray<TimestampMicrosecondType> =
609 vec![Some(37800000000), None, Some(86339000000)].into();
610 let array = array.with_timezone("Australia/Sydney".to_string());
611 let out = cast(&array, &DataType::Utf8).unwrap();
612
613 let expected = StringArray::from(vec![
614 Some("1970-01-01T20:30:00+10:00"),
615 None,
616 Some("1970-01-02T09:58:59+10:00"),
617 ]);
618
619 assert_eq!(
620 out.as_any().downcast_ref::<StringArray>().unwrap(),
621 &expected
622 );
623}
624
625fn format_timezone(tz: &str) -> Result<String, ArrowError> {
626 let array = Arc::new(TimestampSecondArray::from(vec![Some(11111111), None]).with_timezone(tz));

Callers

nothing calls this directly

Calls 2

castFunction · 0.85
with_timezoneMethod · 0.45

Tested by

no test coverage detected