fix: remove split seconds
This commit is contained in:
parent
3c1cc92461
commit
9f7f337efd
5 changed files with 17 additions and 6 deletions
|
|
@ -269,7 +269,7 @@ impl<T> CacheEntry<T> {
|
|||
impl<T> From<T> for CacheEntry<T> {
|
||||
fn from(f: T) -> Self {
|
||||
Self::Some {
|
||||
last_update: OffsetDateTime::now_utc(),
|
||||
last_update: util::now_sec(),
|
||||
data: f,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ use serde::{Deserialize, Serialize};
|
|||
use time::macros::format_description;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use crate::deobfuscate::DeobfData;
|
||||
use crate::error::Error;
|
||||
use crate::{deobfuscate::DeobfData, util};
|
||||
|
||||
const FILENAME_FORMAT: &[time::format_description::FormatItem] =
|
||||
format_description!("[year]-[month]-[day]_[hour]-[minute]-[second]");
|
||||
|
|
@ -81,7 +81,7 @@ impl Default for Info {
|
|||
Self {
|
||||
package: "rustypipe".to_owned(),
|
||||
version: "0.1.0".to_owned(),
|
||||
date: OffsetDateTime::now_utc(),
|
||||
date: util::now_sec(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ impl Mul<u8> for TimeAgo {
|
|||
|
||||
impl From<TimeAgo> for OffsetDateTime {
|
||||
fn from(ta: TimeAgo) -> Self {
|
||||
let ts = OffsetDateTime::now_utc();
|
||||
let ts = util::now_sec();
|
||||
match ta.unit {
|
||||
TimeUnit::Second => ts - Duration::seconds(ta.n as i64),
|
||||
TimeUnit::Minute => ts - Duration::minutes(ta.n as i64),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use time::{Date, Month};
|
||||
use time::{Date, Month, OffsetDateTime};
|
||||
|
||||
pub const fn month_from_n(n: u8) -> Option<Month> {
|
||||
match n {
|
||||
|
|
@ -42,3 +42,14 @@ pub fn shift_months(date: Date, months: i32) -> Date {
|
|||
pub fn shift_years(date: Date, years: i32) -> Date {
|
||||
shift_months(date, years * 12)
|
||||
}
|
||||
|
||||
/// Get the current datetime without milli/micro/nanoseconds
|
||||
pub fn now_sec() -> OffsetDateTime {
|
||||
OffsetDateTime::now_utc()
|
||||
.replace_millisecond(0)
|
||||
.unwrap()
|
||||
.replace_microsecond(0)
|
||||
.unwrap()
|
||||
.replace_nanosecond(0)
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ mod protobuf;
|
|||
|
||||
pub mod dictionary;
|
||||
|
||||
pub use date::{month_from_n, shift_months, shift_years};
|
||||
pub use date::{month_from_n, now_sec, shift_months, shift_years};
|
||||
pub use protobuf::ProtoBuilder;
|
||||
|
||||
use std::{
|
||||
|
|
|
|||
Reference in a new issue