Date helper

This commit is contained in:
Dominik Werder
2025-05-14 16:27:39 +02:00
parent 0c89877c83
commit 3faf8de131
4 changed files with 36 additions and 33 deletions

View File

@@ -2,7 +2,7 @@
name = "daqbuf-netpod"
version = "0.0.4"
authors = ["Dominik Werder <dominik.werder@gmail.com>"]
edition = "2021"
edition = "2024"
[lib]
path = "src/netpod.rs"
@@ -15,6 +15,7 @@ humantime = "2.1.0"
humantime-serde = "1.1.1"
bytes = "1.8.0"
chrono = { version = "0.4.19", features = ["serde"] }
time = { version = "0.3.41", features = ["macros", "parsing"] }
futures-util = "0.3.14"
tracing = "0.1.37"
url = "2.5.3"

View File

@@ -77,7 +77,7 @@ pub mod log_macros_branch {
pub use branch_info as info;
pub use branch_trace as trace;
pub use branch_warn as warn;
pub use tracing::{self, event, span, Level};
pub use tracing::{self, Level, event, span};
}
pub mod log_macros {
@@ -134,13 +134,13 @@ pub mod log_macros {
}
pub mod log {
pub use tracing::{self, event, span, Level};
pub use tracing::{self, Level, event, span};
pub use tracing::{debug, error, info, trace, warn};
}
pub mod log_direct {
pub use crate::{debug, error, info, trace, warn};
pub use tracing::{self, event, span, Level};
pub use tracing::{self, Level, event, span};
}
use bytes::Bytes;
@@ -165,12 +165,12 @@ use std::net::SocketAddr;
use std::path::PathBuf;
use std::pin::Pin;
use std::str::FromStr;
use std::sync::atomic;
use std::sync::atomic::AtomicPtr;
use std::sync::LazyLock;
use std::sync::Once;
use std::sync::RwLock;
use std::sync::RwLockWriteGuard;
use std::sync::atomic;
use std::sync::atomic::AtomicPtr;
use std::task::Context;
use std::task::Poll;
use std::time::Duration;
@@ -258,6 +258,7 @@ autoerr::create_error_v1!(
UnknownSeriesKind(i64),
BadInt(#[from] std::num::ParseIntError),
ChronoParse(#[from] chrono::ParseError),
TimeParse(#[from] time::error::Parse),
HumantimeDurationParse(#[from] humantime::DurationError),
MissingQueryParameters,
MissingSeries,
@@ -720,9 +721,9 @@ impl<const N: usize> From<StringFix<N>> for String {
mod string_fix_impl_serde {
use crate::StringFix;
use serde::de::Visitor;
use serde::Deserialize;
use serde::Serialize;
use serde::de::Visitor;
use std::fmt;
impl<const N: usize> Serialize for StringFix<N> {
@@ -1021,11 +1022,7 @@ pub struct Cluster {
impl Cluster {
pub fn decompress_default(&self) -> bool {
if self.is_central_storage {
false
} else {
true
}
if self.is_central_storage { false } else { true }
}
pub fn scylla_st(&self) -> Option<&ScyllaConfig> {
@@ -1436,19 +1433,11 @@ impl ByteOrder {
}
pub fn is_le(&self) -> bool {
if let Self::Little = self {
true
} else {
false
}
if let Self::Little = self { true } else { false }
}
pub fn is_be(&self) -> bool {
if let Self::Big = self {
true
} else {
false
}
if let Self::Big = self { true } else { false }
}
}
@@ -1837,9 +1826,9 @@ impl fmt::Display for DtNano {
mod dt_nano_serde {
use super::DtNano;
use de::Visitor;
use serde::de;
use serde::Deserialize;
use serde::Serialize;
use serde::de;
use std::fmt;
impl Serialize for DtNano {
@@ -1927,9 +1916,9 @@ mod ts_nano_ser {
use chrono::TimeZone;
use chrono::Utc;
use de::Visitor;
use serde::de;
use serde::Deserialize;
use serde::Serialize;
use serde::de;
use std::fmt;
impl Serialize for TsNano {
@@ -2676,11 +2665,7 @@ impl BinnedRange<TsNano> {
} else {
let f1 = (bin_len_req.ms() - v1.ms()) / bin_len_req.ms();
let f2 = (v2.ms() - bin_len_req.ms()) / bin_len_req.ms();
if f1 < f2 {
v1
} else {
v2
}
if f1 < f2 { v1 } else { v2 }
}
} else {
DtMs::from_ms_u64(v1.ms())
@@ -3103,6 +3088,10 @@ impl TsMs {
Self(self.0 + 1)
}
pub fn add_dt_ms(&self, dt: DtMs) -> Self {
Self(self.0 + dt.0)
}
pub fn fmt(&self) -> TsMsFmt {
TsMsFmt { ts: self.clone() }
}

View File

@@ -1,12 +1,12 @@
use crate::query::PulseRangeQuery;
use crate::query::TimeRangeQuery;
use crate::timeunits::SEC;
use crate::AppendToUrl;
use crate::Dim0Kind;
use crate::Error;
use crate::FromUrl;
use crate::TsNano;
use crate::MS;
use crate::TsNano;
use crate::query::PulseRangeQuery;
use crate::query::TimeRangeQuery;
use crate::timeunits::SEC;
use chrono::DateTime;
use chrono::TimeZone;
use chrono::Utc;
@@ -92,6 +92,15 @@ impl NanoRange {
}
}
pub fn from_strings(beg: &str, end: &str) -> Result<Self, Error> {
// let format = time::format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]Z");
// let beg = time::UtcDateTime::parse(beg, &format)?;
// let beg = beg.into();
let beg = beg.parse::<DateTime<Utc>>()?;
let end = end.parse::<DateTime<Utc>>()?;
Ok(Self::from_date_time(beg, end))
}
pub fn from_ms_u64(beg: u64, end: u64) -> Self {
Self {
beg: MS * beg,

View File

@@ -68,6 +68,10 @@ impl RetentionTime {
}
pub fn to_index_db_i32(&self) -> i32 {
self.to_index_db_u16() as i32
}
pub fn to_index_db_u16(&self) -> u16 {
match self {
RetentionTime::Short => 2,
RetentionTime::Medium => 4,