diff options
| author | klensy <klensy@users.noreply.github.com> | 2024-11-02 15:08:53 +0300 |
|---|---|---|
| committer | klensy <klensy@users.noreply.github.com> | 2024-11-03 15:51:39 +0300 |
| commit | be3a635fe777d4aac653994749ad47e650e71c1e (patch) | |
| tree | f1f2f0584916400b7e298beca0de5834b549bf19 /compiler/rustc_incremental | |
| parent | db034cee00570a9b82ea8b9e9e95221dbd745698 (diff) | |
| download | rust-be3a635fe777d4aac653994749ad47e650e71c1e.tar.gz rust-be3a635fe777d4aac653994749ad47e650e71c1e.zip | |
replace manual time convertions with std ones
Diffstat (limited to 'compiler/rustc_incremental')
| -rw-r--r-- | compiler/rustc_incremental/src/persist/fs.rs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/compiler/rustc_incremental/src/persist/fs.rs b/compiler/rustc_incremental/src/persist/fs.rs index 8769c4173c8..f6c3e8ebbcb 100644 --- a/compiler/rustc_incremental/src/persist/fs.rs +++ b/compiler/rustc_incremental/src/persist/fs.rs @@ -585,23 +585,17 @@ fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime fn timestamp_to_string(timestamp: SystemTime) -> BaseNString { let duration = timestamp.duration_since(UNIX_EPOCH).unwrap(); - let micros = duration.as_secs() * 1_000_000 + (duration.subsec_nanos() as u64) / 1000; + let micros: u64 = duration.as_micros().try_into().unwrap(); micros.to_base_fixed_len(CASE_INSENSITIVE) } fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> { - let micros_since_unix_epoch = u64::from_str_radix(s, INT_ENCODE_BASE as u32); - - if micros_since_unix_epoch.is_err() { - return Err("timestamp not an int"); - } - - let micros_since_unix_epoch = micros_since_unix_epoch.unwrap(); + let micros_since_unix_epoch = match u64::from_str_radix(s, INT_ENCODE_BASE as u32) { + Ok(micros) => micros, + Err(_) => return Err("timestamp not an int"), + }; - let duration = Duration::new( - micros_since_unix_epoch / 1_000_000, - 1000 * (micros_since_unix_epoch % 1_000_000) as u32, - ); + let duration = Duration::from_micros(micros_since_unix_epoch); Ok(UNIX_EPOCH + duration) } |
