Browse Source

pub fn nanos_utc(t: i64) -> DateTime<Utc>

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

+ 7
- 1
src/lib.rs View File

@@ -29,7 +29,7 @@ extern crate zmq;


extern crate pubsub as pub_sub; extern crate pubsub as pub_sub;


use chrono::{DateTime, Utc};
use chrono::{DateTime, Utc, TimeZone as ChronoTZ};
#[allow(unused_imports)] #[allow(unused_imports)]
use sloggers::Build; use sloggers::Build;
#[allow(unused_imports)] #[allow(unused_imports)]
@@ -104,10 +104,16 @@ 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)
} }


#[inline]
pub fn dur_nanos(d: ::std::time::Duration) -> i64 { pub fn dur_nanos(d: ::std::time::Duration) -> i64 {
(d.as_secs() * 1_000_000_000_u64 + (d.subsec_nanos() as u64)) as i64 (d.as_secs() * 1_000_000_000_u64 + (d.subsec_nanos() as u64)) as i64
} }


#[inline]
pub fn nanos_utc(t: i64) -> DateTime<Utc> {
Utc.timestamp(t / 1_000_000_000, (t % 1_000_000_000) as u32)
}

pub fn short_uuid(id: &Uuid) -> String { pub fn short_uuid(id: &Uuid) -> String {
if cfg!(feature = "disable-short-uuid") { if cfg!(feature = "disable-short-uuid") {
id.to_string() id.to_string()


Loading…
Cancel
Save