mirror of
https://github.com/YGGverse/rssto.git
synced 2026-04-01 01:25:29 +00:00
initial commit
This commit is contained in:
parent
fc4f0d6d1c
commit
0506b4dcb2
11 changed files with 455 additions and 1 deletions
29
src/time.rs
Normal file
29
src/time.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
|
||||
pub struct Time(String);
|
||||
|
||||
impl Time {
|
||||
pub fn init(format: String) -> Self {
|
||||
Self(format)
|
||||
}
|
||||
|
||||
pub fn format(&self, value: Option<&str>) -> String {
|
||||
match value {
|
||||
Some(v) => chrono::DateTime::parse_from_rfc2822(v)
|
||||
.unwrap()
|
||||
.format(&self.0)
|
||||
.to_string(),
|
||||
None => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn now(&self) -> String {
|
||||
utc().format(&self.0).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn utc() -> DateTime<Utc> {
|
||||
let s = std::time::SystemTime::now();
|
||||
let c: chrono::DateTime<chrono::Utc> = s.into();
|
||||
c
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue