fix: remove split seconds

This commit is contained in:
ThetaDev 2022-10-18 23:06:19 +02:00
parent 3c1cc92461
commit 9f7f337efd
5 changed files with 17 additions and 6 deletions

View file

@ -269,7 +269,7 @@ impl<T> CacheEntry<T> {
impl<T> From<T> for CacheEntry<T> { impl<T> From<T> for CacheEntry<T> {
fn from(f: T) -> Self { fn from(f: T) -> Self {
Self::Some { Self::Some {
last_update: OffsetDateTime::now_utc(), last_update: util::now_sec(),
data: f, data: f,
} }
} }

View file

@ -11,8 +11,8 @@ use serde::{Deserialize, Serialize};
use time::macros::format_description; use time::macros::format_description;
use time::OffsetDateTime; use time::OffsetDateTime;
use crate::deobfuscate::DeobfData;
use crate::error::Error; use crate::error::Error;
use crate::{deobfuscate::DeobfData, util};
const FILENAME_FORMAT: &[time::format_description::FormatItem] = const FILENAME_FORMAT: &[time::format_description::FormatItem] =
format_description!("[year]-[month]-[day]_[hour]-[minute]-[second]"); format_description!("[year]-[month]-[day]_[hour]-[minute]-[second]");
@ -81,7 +81,7 @@ impl Default for Info {
Self { Self {
package: "rustypipe".to_owned(), package: "rustypipe".to_owned(),
version: "0.1.0".to_owned(), version: "0.1.0".to_owned(),
date: OffsetDateTime::now_utc(), date: util::now_sec(),
} }
} }
} }

View file

@ -84,7 +84,7 @@ impl Mul<u8> for TimeAgo {
impl From<TimeAgo> for OffsetDateTime { impl From<TimeAgo> for OffsetDateTime {
fn from(ta: TimeAgo) -> Self { fn from(ta: TimeAgo) -> Self {
let ts = OffsetDateTime::now_utc(); let ts = util::now_sec();
match ta.unit { match ta.unit {
TimeUnit::Second => ts - Duration::seconds(ta.n as i64), TimeUnit::Second => ts - Duration::seconds(ta.n as i64),
TimeUnit::Minute => ts - Duration::minutes(ta.n as i64), TimeUnit::Minute => ts - Duration::minutes(ta.n as i64),

View file

@ -1,4 +1,4 @@
use time::{Date, Month}; use time::{Date, Month, OffsetDateTime};
pub const fn month_from_n(n: u8) -> Option<Month> { pub const fn month_from_n(n: u8) -> Option<Month> {
match n { match n {
@ -42,3 +42,14 @@ pub fn shift_months(date: Date, months: i32) -> Date {
pub fn shift_years(date: Date, years: i32) -> Date { pub fn shift_years(date: Date, years: i32) -> Date {
shift_months(date, years * 12) 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()
}

View file

@ -3,7 +3,7 @@ mod protobuf;
pub mod dictionary; 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; pub use protobuf::ProtoBuilder;
use std::{ use std::{