feat: avoid using vector to get default value (#2323)

This commit is contained in:
Yingwen
2023-09-05 10:33:29 +08:00
committed by Ruihang Xia
parent f71aa373c1
commit 3eccb36047
3 changed files with 98 additions and 28 deletions

View File

@@ -54,6 +54,18 @@ impl Timestamp {
}
}
/// Creates current timestamp in specific time `unit`.
pub fn current_time(unit: TimeUnit) -> Timestamp {
let now = chrono::Utc::now();
let value = match unit {
TimeUnit::Second => now.timestamp(),
TimeUnit::Millisecond => now.timestamp_millis(),
TimeUnit::Microsecond => now.timestamp_micros(),
TimeUnit::Nanosecond => now.timestamp_nanos(),
};
Timestamp { value, unit }
}
/// Subtracts a duration from timestamp.
/// # Note
/// The result time unit remains unchanged even if `duration` has a different unit with `self`.