refactor!: made timeago module private
This commit is contained in:
parent
800073df48
commit
2241223c9f
8 changed files with 11 additions and 19 deletions
|
|
@ -38,7 +38,7 @@ pub fn generate_dictionary() {
|
||||||
use crate::{
|
use crate::{
|
||||||
model::AlbumType,
|
model::AlbumType,
|
||||||
param::Language,
|
param::Language,
|
||||||
timeago::{DateCmp, TaToken, TimeUnit},
|
util::timeago::{DateCmp, TaToken, TimeUnit},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The dictionary contains the information required to parse dates and numbers
|
/// The dictionary contains the information required to parse dates and numbers
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@ use time::OffsetDateTime;
|
||||||
use crate::{
|
use crate::{
|
||||||
error::{Error, ExtractionError},
|
error::{Error, ExtractionError},
|
||||||
model::{paginator::Paginator, ChannelId, Playlist, PlaylistVideo},
|
model::{paginator::Paginator, ChannelId, Playlist, PlaylistVideo},
|
||||||
timeago,
|
util::{self, timeago, TryRemove},
|
||||||
util::{self, TryRemove},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{response, ClientType, MapResponse, MapResult, QBrowse, QContinuation, RustyPipeQuery};
|
use super::{response, ClientType, MapResponse, MapResult, QBrowse, QContinuation, RustyPipeQuery};
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,7 @@ use crate::{
|
||||||
text::{AccessibilityText, Text, TextComponent},
|
text::{AccessibilityText, Text, TextComponent},
|
||||||
MapResult,
|
MapResult,
|
||||||
},
|
},
|
||||||
timeago,
|
util::{self, timeago, TryRemove},
|
||||||
util::{self, TryRemove},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[serde_as]
|
#[serde_as]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@ use crate::{
|
||||||
model::{paginator::Paginator, ChannelTag, Chapter, Comment, VideoDetails, VideoItem},
|
model::{paginator::Paginator, ChannelTag, Chapter, Comment, VideoDetails, VideoItem},
|
||||||
param::Language,
|
param::Language,
|
||||||
serializer::MapResult,
|
serializer::MapResult,
|
||||||
timeago,
|
util::{self, timeago, TryRemove},
|
||||||
util::{self, TryRemove},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,4 @@ pub mod error;
|
||||||
pub mod model;
|
pub mod model;
|
||||||
pub mod param;
|
pub mod param;
|
||||||
pub mod report;
|
pub mod report;
|
||||||
pub mod timeago;
|
|
||||||
pub mod validate;
|
pub mod validate;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
model::AlbumType,
|
model::AlbumType,
|
||||||
param::Language,
|
param::Language,
|
||||||
timeago::{DateCmp, TaToken, TimeUnit},
|
util::timeago::{DateCmp, TaToken, TimeUnit},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The dictionary contains the information required to parse dates and numbers
|
/// The dictionary contains the information required to parse dates and numbers
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ mod date;
|
||||||
mod protobuf;
|
mod protobuf;
|
||||||
|
|
||||||
pub mod dictionary;
|
pub mod dictionary;
|
||||||
|
pub mod timeago;
|
||||||
|
|
||||||
pub use date::{now_sec, shift_months, shift_years};
|
pub use date::{now_sec, shift_months, shift_years};
|
||||||
pub use protobuf::{string_from_pb, ProtoBuilder};
|
pub use protobuf::{string_from_pb, ProtoBuilder};
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,6 @@
|
||||||
//!
|
//!
|
||||||
//! This module can parse these dates using an embedded dictionary which
|
//! This module can parse these dates using an embedded dictionary which
|
||||||
//! contains date/time unit tokens for all supported languages.
|
//! contains date/time unit tokens for all supported languages.
|
||||||
//!
|
|
||||||
//! Note that this module is public so it can be tested from outside
|
|
||||||
//! the crate, which is important for including new languages, too.
|
|
||||||
//!
|
|
||||||
//! It is not intended to be used to parse textual dates that are not from YouTube.
|
|
||||||
|
|
||||||
use std::ops::Mul;
|
use std::ops::Mul;
|
||||||
|
|
||||||
|
|
@ -70,12 +65,12 @@ pub enum TimeUnit {
|
||||||
|
|
||||||
/// Value of a parsed TimeAgo token, used in the dictionary
|
/// Value of a parsed TimeAgo token, used in the dictionary
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub(crate) struct TaToken {
|
pub struct TaToken {
|
||||||
pub n: u8,
|
pub n: u8,
|
||||||
pub unit: Option<TimeUnit>,
|
pub unit: Option<TimeUnit>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum DateCmp {
|
pub enum DateCmp {
|
||||||
Y,
|
Y,
|
||||||
M,
|
M,
|
||||||
D,
|
D,
|
||||||
|
|
@ -202,7 +197,7 @@ pub fn parse_timeago_dt(lang: Language, textual_date: &str) -> Option<OffsetDate
|
||||||
parse_timeago(lang, textual_date).map(|ta| ta.into())
|
parse_timeago(lang, textual_date).map(|ta| ta.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_timeago_or_warn(
|
pub fn parse_timeago_or_warn(
|
||||||
lang: Language,
|
lang: Language,
|
||||||
textual_date: &str,
|
textual_date: &str,
|
||||||
warnings: &mut Vec<String>,
|
warnings: &mut Vec<String>,
|
||||||
|
|
@ -214,7 +209,7 @@ pub(crate) fn parse_timeago_or_warn(
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_timeago_dt_or_warn(
|
pub fn parse_timeago_dt_or_warn(
|
||||||
lang: Language,
|
lang: Language,
|
||||||
textual_date: &str,
|
textual_date: &str,
|
||||||
warnings: &mut Vec<String>,
|
warnings: &mut Vec<String>,
|
||||||
|
|
@ -284,7 +279,7 @@ pub fn parse_textual_date_to_dt(lang: Language, textual_date: &str) -> Option<Of
|
||||||
parse_textual_date(lang, textual_date).map(|ta| ta.into())
|
parse_textual_date(lang, textual_date).map(|ta| ta.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_textual_date_or_warn(
|
pub fn parse_textual_date_or_warn(
|
||||||
lang: Language,
|
lang: Language,
|
||||||
textual_date: &str,
|
textual_date: &str,
|
||||||
warnings: &mut Vec<String>,
|
warnings: &mut Vec<String>,
|
||||||
Reference in a new issue