apply rustfmt. ugh.

This commit is contained in:
Trevor Bentley
2023-01-12 17:45:49 +01:00
parent 65982202a1
commit b84065e565
5 changed files with 417 additions and 288 deletions
+22 -20
View File
@@ -1,16 +1,13 @@
use chrono::{
DateTime,
offset::FixedOffset,
naive::NaiveDateTime,
};
use crate::git::GitFile;
use chrono::{naive::NaiveDateTime, offset::FixedOffset, DateTime};
use std::collections::HashMap;
use tera::{Filter, Function, Value, to_value, try_get_value};
use tera::{to_value, try_get_value, Filter, Function, Value};
fn ts_to_date(ts: i64, offset: Option<i64>, format: Option<String>) -> String {
let offset = offset.unwrap_or(0);
let dt = NaiveDateTime::from_timestamp_opt(ts + offset, 0).expect("Invalid timestamp");
let dt_tz: DateTime<FixedOffset> = DateTime::from_local(dt, FixedOffset::east_opt(offset as i32).expect("Invalid timezone"));
let dt_tz: DateTime<FixedOffset> =
DateTime::from_local(dt, FixedOffset::east_opt(offset as i32).expect("Invalid timezone"));
match format {
Some(f) => dt_tz.format(&f).to_string(),
None => dt_tz.format("%Y-%m-%d").to_string(),
@@ -20,32 +17,37 @@ fn ts_to_date(ts: i64, offset: Option<i64>, format: Option<String>) -> String {
fn ts_to_git_timestamp(ts: i64, offset: Option<i64>) -> String {
let offset = offset.unwrap_or(0);
let dt = chrono::naive::NaiveDateTime::from_timestamp_opt(ts + offset, 0).expect("invalid timestamp");
let dt_tz: DateTime<FixedOffset> = DateTime::from_local(dt, FixedOffset::east_opt(offset as i32).expect("Invalid timezone"));
let dt_tz: DateTime<FixedOffset> =
DateTime::from_local(dt, FixedOffset::east_opt(offset as i32).expect("Invalid timezone"));
dt_tz.format("%a %b %e %T %Y %z").to_string()
}
pub struct FileFilter;
impl Filter for FileFilter {
fn filter(&self, value: &Value, _args: &HashMap<String, Value>
) -> Result<Value, tera::Error> {
fn filter(&self, value: &Value, _args: &HashMap<String, Value>) -> Result<Value, tera::Error> {
let file_list: Vec<GitFile> = try_get_value!("only_files", "value", Vec<GitFile>, value);
let file_list: Vec<GitFile> = file_list.iter().filter_map(|x| match x.kind.as_str() {
"file" => Some(x.clone()),
_ => None,
}).collect();
let file_list: Vec<GitFile> = file_list
.iter()
.filter_map(|x| match x.kind.as_str() {
"file" => Some(x.clone()),
_ => None,
})
.collect();
Ok(to_value(file_list).unwrap())
}
}
pub struct DirFilter;
impl Filter for DirFilter {
fn filter(&self, value: &Value, _args: &HashMap<String, Value>
) -> Result<Value, tera::Error> {
fn filter(&self, value: &Value, _args: &HashMap<String, Value>) -> Result<Value, tera::Error> {
let file_list: Vec<GitFile> = try_get_value!("only_dirs", "value", Vec<GitFile>, value);
let file_list: Vec<GitFile> = file_list.iter().filter_map(|x| match x.kind.as_str() {
"dir" => Some(x.clone()),
_ => None,
}).collect();
let file_list: Vec<GitFile> = file_list
.iter()
.filter_map(|x| match x.kind.as_str() {
"dir" => Some(x.clone()),
_ => None,
})
.collect();
Ok(to_value(file_list).unwrap())
}
}