jorgecarleitao commented 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=0a092c28cbab66265843990de833b570)): ```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; println!("{}", days); 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, 2932896]; let a = int96_to_i64_ns(value); } #[test] fn test_micros() { let value = [0, 0, 2932896]; let a = int96_to_i64_us(value); } } ``` where `2932896` is the number of days of "9999-12-31" since epoch: ```bash python -c "import datetime; print((datetime.datetime(year=9999,month=12,day=31) - datetime.datetime(year=1970,month=1,day=1)).days)" ``` -- 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]
