Compare commits

..

3 Commits

3 changed files with 14 additions and 5 deletions

View File

@ -11,7 +11,7 @@ pub enum TimeMetrics {
impl TimeMetrics { impl TimeMetrics {
pub fn from(metric: impl Into<&'static str>, duration: i64) -> Self { pub fn from(metric: impl Into<&'static str>, duration: i64) -> Self {
match metric.into() { match metric.into() {
"min" | "minutes" | "minute" | "минута" | "минуты" | "минут" | "мин" => { "m" | "min" | "minutes" | "minute" | "минута" | "минуты" | "минут" | "мин" | "м" => {
Self::Minutes(duration) Self::Minutes(duration)
} }
"h" | "hours" | "hour" | "час" | "часов" | "ч" => Self::Hours(duration), "h" | "hours" | "hour" | "час" | "часов" | "ч" => Self::Hours(duration),
@ -21,7 +21,7 @@ impl TimeMetrics {
"w" | "weeks" | "week" | "недель" | "недели" | "неделя" | "н" => { "w" | "weeks" | "week" | "недель" | "недели" | "неделя" | "н" => {
Self::Weeks(duration) Self::Weeks(duration)
} }
"m" | "months" | "month" | "месяц" | "месяца" | "месяцев" | "мес" => { "M" | "months" | "month" | "месяц" | "месяца" | "месяцев" | "мес" | "М" => {
Self::Mounths(duration) Self::Mounths(duration)
} }
_ => Self::Days(duration), _ => Self::Days(duration),

View File

@ -10,7 +10,7 @@ pub type ExtractedDuration = (NaiveDateTime, String, i64);
pub fn get_duration(time: TimeValues) -> ExtractedDuration { pub fn get_duration(time: TimeValues) -> ExtractedDuration {
let time_duration = time.0.extract(); let time_duration = time.0.extract();
let unmute_date = unrestrict_date(time_duration); let unmute_date = unrestrict_date(time);
let postfix = CountableTime::from_value(time_duration) let postfix = CountableTime::from_value(time_duration)
.get_postfix(time.0) .get_postfix(time.0)
.unwrap(); .unwrap();

View File

@ -1,6 +1,15 @@
use chrono::{Duration, Local, NaiveDateTime}; use chrono::{Duration, Local, NaiveDateTime};
use crate::types::{enums::time_metrics::TimeMetrics, TimeValues};
#[inline] #[inline]
pub fn unrestrict_date(days: i64) -> NaiveDateTime { pub fn unrestrict_date(duration: TimeValues) -> NaiveDateTime {
Local::now().naive_utc() + Duration::days(days) let mute_duration = match duration.0 {
TimeMetrics::Minutes(min) => Duration::minutes(min),
TimeMetrics::Hours(hrs) => Duration::hours(hrs),
TimeMetrics::Days(day) => Duration::days(day),
TimeMetrics::Weeks(wks) => Duration::weeks(wks),
TimeMetrics::Mounths(mon) => Duration::weeks(mon * 4),
};
Local::now().naive_utc() + mute_duration
} }