jorgecarleitao edited a comment on issue #1360: URL: https://github.com/apache/arrow-datafusion/issues/1360#issuecomment-979484813
I boiled down the conversion in a minimal example ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=165008d8376dd2274bdf953cd58d5d8b)): ```rust // to nanos pub fn int96_to_i64_ns(value: [u32; 3]) -> i64 { let nanoseconds = value[0] as i64 + ((value[1] as i64) << 32); let days = value[2] as i64; const JULIAN_DAY_OF_EPOCH: i64 = 2_440_588; const SECONDS_PER_DAY: i64 = 86_400; const NANOS_PER_SECOND: i64 = 1_000_000_000; let seconds = (days - JULIAN_DAY_OF_EPOCH) * SECONDS_PER_DAY; seconds * NANOS_PER_SECOND + nanoseconds } // to micros pub fn int96_to_i64_us(value: [u32; 3]) -> i64 { let nanoseconds = value[0] as i64 + ((value[1] as i64) << 32); let days = value[2] as i64; const JULIAN_DAY_OF_EPOCH: i64 = 2_440_588; const SECONDS_PER_DAY: i64 = 86_400; const MICROS_PER_SECOND: i64 = 1_000_000; let seconds = (days - JULIAN_DAY_OF_EPOCH) * SECONDS_PER_DAY; seconds * MICROS_PER_SECOND + nanoseconds / 1000 } #[cfg(test)] mod tests { use super::*; #[test] fn test_nanos() { let value = [0, 0, 5373484]; let a = int96_to_i64_ns(value); } #[test] fn test_micros() { let value = [0, 0, 5373484]; let a = int96_to_i64_us(value); } } ``` where `5373484` is the number of days of "9999-12-31" since the julian epoch. `test_nanos` does not pass while `test_micros` passes EDIT: fixed `2932896` to `2440588 + 2932896 = 5373484` since int96 is days since julian, not unix, epoch ; it does not change the conclusion, though. -- 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]
