Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved UX of creating TimestampNanosecondArray with timezones #3088

Merged
merged 3 commits into from
Nov 11, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,13 @@ impl<T: ArrowTimestampType> PrimitiveArray<T> {
}

/// Construct a timestamp array with new timezone
pub fn with_timezone(&self, timezone: String) -> Self {
self.with_timezone_opt(Some(timezone))
pub fn with_timezone(&self, timezone: impl Into<String>) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @src255 @alamb

self.with_timezone_opt(Some(timezone.into()))
}

/// Construct a timestamp array with UTC
pub fn with_timezone_utc(&self) -> Self {
self.with_timezone("+00:00")
}

/// Construct a timestamp array with an optional timezone
Expand Down Expand Up @@ -1322,6 +1327,21 @@ mod tests {
);
}

#[test]
fn test_timestamp_utc_fmt_debug() {
let arr: PrimitiveArray<TimestampMillisecondType> =
TimestampMillisecondArray::from(vec![
1546214400000,
1546214400000,
-1546214400000,
])
.with_timezone_utc();
assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, Some(\"+00:00\"))>\n[\n 2018-12-31T00:00:00,\n 2018-12-31T00:00:00,\n 1921-01-02T00:00:00,\n]",
format!("{:?}", arr)
);
}

#[test]
fn test_timestamp_with_tz_fmt_debug() {
let arr: PrimitiveArray<TimestampMillisecondType> =
Expand Down