-
-
Save rust-play/b08021e751bf8fb984013fd48803b297 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use chrono::*; | |
const SECOND_IN_MICROSECONDS: i64 = 1_000_000; | |
const MICROSECOND_IN_NANOSECONDS: i64 = 1_000; | |
fn s(μs: i64) -> i64 { (μs / SECOND_IN_MICROSECONDS) as i64 } | |
fn ns(μs: i64) -> u32 { (μs.rem_euclid(SECOND_IN_MICROSECONDS) * MICROSECOND_IN_NANOSECONDS) as u32 } | |
fn main() { | |
let past_ms = -150_151_152_153_154; | |
let future_ms = 150_151_152_153_154; | |
let past = Utc.timestamp(s(past_ms), ns(past_ms)); | |
println!("{past}"); | |
let future = Utc.timestamp(s(future_ms), ns(future_ms)); | |
println!("{future}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related to Dart gist.