Browse Source

some nanos-related things

master
Jonathan Strong 6 years ago
parent
commit
b9b1306da1
1 changed files with 7 additions and 0 deletions
  1. +7
    -0
      src/lib.rs

+ 7
- 0
src/lib.rs View File

@@ -58,10 +58,16 @@ const CHANNEL_SIZE: usize = 2_097_152;


/// converts a chrono::DateTime to an integer timestamp (ns) /// converts a chrono::DateTime to an integer timestamp (ns)
/// ///
#[inline]
pub fn nanos(t: DateTime<Utc>) -> u64 { pub fn nanos(t: DateTime<Utc>) -> u64 {
(t.timestamp() as u64) * 1_000_000_000_u64 + (t.timestamp_subsec_nanos() as u64) (t.timestamp() as u64) * 1_000_000_000_u64 + (t.timestamp_subsec_nanos() as u64)
} }


#[inline]
pub fn inanos(t: DateTime<Utc>) -> i64 {
t.timestamp() * 1_000_000_000i64 + t.timestamp_subsec_nanos() as i64
}

//#[cfg(not(any(test, feature = "test")))] //#[cfg(not(any(test, feature = "test")))]
pub fn file_logger(path: &str, level: Severity) -> slog::Logger { pub fn file_logger(path: &str, level: Severity) -> slog::Logger {
let mut builder = FileLoggerBuilder::new(path); let mut builder = FileLoggerBuilder::new(path);
@@ -91,6 +97,7 @@ pub fn async_file_logger(path: &str, level: Severity) -> slog::Logger {
slog::Logger::root(async_drain.fuse(), o!()) slog::Logger::root(async_drain.fuse(), o!())
} }


//#[deprecated(since="0.4.3", note="Use `nanos(DateTime<Utc>) -> u64` instead")]
pub fn dt_nanos(t: DateTime<Utc>) -> i64 { pub fn dt_nanos(t: DateTime<Utc>) -> i64 {
(t.timestamp() as i64) * 1_000_000_000_i64 + (t.timestamp_subsec_nanos() as i64) (t.timestamp() as i64) * 1_000_000_000_i64 + (t.timestamp_subsec_nanos() as i64)
} }


Loading…
Cancel
Save