mirror of
https://github.com/nushell/nushell.git
synced 2025-04-09 21:28:55 +02:00
fix dfr datetime conversion (#7264)
# Description Closes #7257 This fixes an issue where dataframes would always try to convert datetimes with milliseconds. Since the timeunit is passed in, I make use of it and try to choose the appropriate divisor. # User-Facing Changes # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
parent
3caab5de36
commit
b7e5790cd1
@ -498,7 +498,7 @@ pub fn create_column(
|
|||||||
|
|
||||||
Ok(Column::new(casted.name().into(), values))
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::Datetime(_, _) => {
|
DataType::Datetime(time_unit, _) => {
|
||||||
let casted = series.datetime().map_err(|e| {
|
let casted = series.datetime().map_err(|e| {
|
||||||
ShellError::GenericError(
|
ShellError::GenericError(
|
||||||
"Error casting column to datetime".into(),
|
"Error casting column to datetime".into(),
|
||||||
@ -508,15 +508,19 @@ pub fn create_column(
|
|||||||
Vec::new(),
|
Vec::new(),
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let values = casted
|
let values = casted
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.skip(from_row)
|
.skip(from_row)
|
||||||
.take(size)
|
.take(size)
|
||||||
.map(|v| match v {
|
.map(|v| match v {
|
||||||
Some(a) => {
|
Some(a) => {
|
||||||
// elapsed time in milliseconds since 1970-01-01
|
let unit_divisor = match time_unit {
|
||||||
let seconds = a / 1000;
|
TimeUnit::Nanoseconds => 1_000_000_000,
|
||||||
|
TimeUnit::Microseconds => 1_000_000,
|
||||||
|
TimeUnit::Milliseconds => 1_000,
|
||||||
|
};
|
||||||
|
// elapsed time in nano/micro/milliseconds since 1970-01-01
|
||||||
|
let seconds = a / unit_divisor;
|
||||||
let naive_datetime = match NaiveDateTime::from_timestamp_opt(seconds, 0) {
|
let naive_datetime = match NaiveDateTime::from_timestamp_opt(seconds, 0) {
|
||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
None => {
|
None => {
|
||||||
|
Loading…
Reference in New Issue
Block a user