This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new be093cb442 Simplify datetime conversion (#5006)
be093cb442 is described below
commit be093cb44243a23b637754e06b13ccb4de2f6512
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Mon Oct 30 20:27:51 2023 +0000
Simplify datetime conversion (#5006)
* Simplify datetime conversion
* Update test
* Review feedback
---
parquet_derive/src/parquet_field.rs | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/parquet_derive/src/parquet_field.rs
b/parquet_derive/src/parquet_field.rs
index 0ac95c2864..bb33b31968 100644
--- a/parquet_derive/src/parquet_field.rs
+++ b/parquet_derive/src/parquet_field.rs
@@ -427,13 +427,9 @@ impl Field {
quote! {
::chrono::naive::NaiveDateTime::from_timestamp_millis(vals[i]).unwrap() }
}
Some(ThirdPartyType::ChronoNaiveDate) => {
+ // NaiveDateTime::UNIX_EPOCH.num_days_from_ce() == 719163
quote! {
-
::chrono::naive::NaiveDate::from_num_days_from_ce_opt(vals[i]
- + ((::chrono::naive::NaiveDate::from_ymd_opt(1970, 1,
1).unwrap()
- .signed_duration_since(
- ::chrono::naive::NaiveDate::from_ymd_opt(0, 12,
31).unwrap()
- )
- ).num_days()) as i32).unwrap()
+
::chrono::naive::NaiveDate::from_num_days_from_ce_opt(vals[i].saturating_add(719163)).unwrap()
}
}
Some(ThirdPartyType::Uuid) => {
@@ -1339,11 +1335,7 @@ mod test {
panic!("Schema and struct disagree on type for {}",
stringify!{ henceforth });
}
for (i, r) in &mut
records[..num_records].iter_mut().enumerate() {
- r.henceforth =
::chrono::naive::NaiveDate::from_num_days_from_ce_opt(vals[i]
- + ((::chrono::naive::NaiveDate::from_ymd_opt(1970, 1,
1).unwrap()
- .signed_duration_since(
- ::chrono::naive::NaiveDate::from_ymd_opt(0, 12,
31).unwrap()
- )).num_days()) as i32).unwrap();
+ r.henceforth =
::chrono::naive::NaiveDate::from_num_days_from_ce_opt(vals[i].saturating_add(719163)).unwrap();
}
}
}).to_string());