mirror of
https://git.proxmox.com/git/proxmox
synced 2025-06-27 11:15:08 +00:00
time: remove lazy_static dependency
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
This commit is contained in:
parent
25f83bce19
commit
669c39c59f
@ -6,13 +6,13 @@ edition.workspace = true
|
|||||||
license.workspace = true
|
license.workspace = true
|
||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
description = "time utilities and TmEditor"
|
description = "time utilities and TmEditor"
|
||||||
|
rust-version.workspace = true
|
||||||
|
|
||||||
exclude.workspace = true
|
exclude.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
bitflags.workspace = true
|
bitflags.workspace = true
|
||||||
lazy_static.workspace = true
|
|
||||||
nom = "7"
|
nom = "7"
|
||||||
|
|
||||||
[target.'cfg(not(target_arch="wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch="wasm32"))'.dependencies]
|
||||||
|
@ -1,79 +1,77 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use nom::{bytes::complete::take_while1, character::complete::space0, combinator::opt};
|
use nom::{bytes::complete::take_while1, character::complete::space0, combinator::opt};
|
||||||
|
|
||||||
use crate::parse_helpers::{parse_complete_line, parse_error, parse_u64, IResult};
|
use crate::parse_helpers::{parse_complete_line, parse_error, parse_u64, IResult};
|
||||||
|
|
||||||
lazy_static! {
|
static TIME_SPAN_UNITS: LazyLock<HashMap<&'static str, f64>> = LazyLock::new(|| {
|
||||||
static ref TIME_SPAN_UNITS: HashMap<&'static str, f64> = {
|
let mut map = HashMap::new();
|
||||||
let mut map = HashMap::new();
|
|
||||||
|
|
||||||
let second = 1.0;
|
let second = 1.0;
|
||||||
|
|
||||||
map.insert("seconds", second);
|
map.insert("seconds", second);
|
||||||
map.insert("second", second);
|
map.insert("second", second);
|
||||||
map.insert("sec", second);
|
map.insert("sec", second);
|
||||||
map.insert("s", second);
|
map.insert("s", second);
|
||||||
|
|
||||||
let msec = second / 1000.0;
|
let msec = second / 1000.0;
|
||||||
|
|
||||||
map.insert("msec", msec);
|
map.insert("msec", msec);
|
||||||
map.insert("ms", msec);
|
map.insert("ms", msec);
|
||||||
|
|
||||||
let usec = msec / 1000.0;
|
let usec = msec / 1000.0;
|
||||||
|
|
||||||
map.insert("usec", usec);
|
map.insert("usec", usec);
|
||||||
map.insert("us", usec);
|
map.insert("us", usec);
|
||||||
map.insert("µs", usec);
|
map.insert("µs", usec);
|
||||||
|
|
||||||
let nsec = usec / 1000.0;
|
let nsec = usec / 1000.0;
|
||||||
|
|
||||||
map.insert("nsec", nsec);
|
map.insert("nsec", nsec);
|
||||||
map.insert("ns", nsec);
|
map.insert("ns", nsec);
|
||||||
|
|
||||||
let minute = second * 60.0;
|
let minute = second * 60.0;
|
||||||
|
|
||||||
map.insert("minutes", minute);
|
map.insert("minutes", minute);
|
||||||
map.insert("minute", minute);
|
map.insert("minute", minute);
|
||||||
map.insert("min", minute);
|
map.insert("min", minute);
|
||||||
map.insert("m", minute);
|
map.insert("m", minute);
|
||||||
|
|
||||||
let hour = minute * 60.0;
|
let hour = minute * 60.0;
|
||||||
|
|
||||||
map.insert("hours", hour);
|
map.insert("hours", hour);
|
||||||
map.insert("hour", hour);
|
map.insert("hour", hour);
|
||||||
map.insert("hr", hour);
|
map.insert("hr", hour);
|
||||||
map.insert("h", hour);
|
map.insert("h", hour);
|
||||||
|
|
||||||
let day = hour * 24.0;
|
let day = hour * 24.0;
|
||||||
|
|
||||||
map.insert("days", day);
|
map.insert("days", day);
|
||||||
map.insert("day", day);
|
map.insert("day", day);
|
||||||
map.insert("d", day);
|
map.insert("d", day);
|
||||||
|
|
||||||
let week = day * 7.0;
|
let week = day * 7.0;
|
||||||
|
|
||||||
map.insert("weeks", week);
|
map.insert("weeks", week);
|
||||||
map.insert("week", week);
|
map.insert("week", week);
|
||||||
map.insert("w", week);
|
map.insert("w", week);
|
||||||
|
|
||||||
let month = 30.44 * day;
|
let month = 30.44 * day;
|
||||||
|
|
||||||
map.insert("months", month);
|
map.insert("months", month);
|
||||||
map.insert("month", month);
|
map.insert("month", month);
|
||||||
map.insert("M", month);
|
map.insert("M", month);
|
||||||
|
|
||||||
let year = 365.25 * day;
|
let year = 365.25 * day;
|
||||||
|
|
||||||
map.insert("years", year);
|
map.insert("years", year);
|
||||||
map.insert("year", year);
|
map.insert("year", year);
|
||||||
map.insert("y", year);
|
map.insert("y", year);
|
||||||
|
|
||||||
map
|
map
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
/// A time spans defines a time duration
|
/// A time spans defines a time duration
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone, Debug)]
|
||||||
|
Loading…
Reference in New Issue
Block a user