Fix menu date display
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -1,4 +1,3 @@
|
||||
use chrono::Local;
|
||||
use mensa::{Mealplan, Mensa, MensaName};
|
||||
use prettytable::{row, Cell, Row, Table};
|
||||
|
||||
@@ -30,24 +29,23 @@ fn exec_arguments(args: &cli::Args) {
|
||||
fn exec_arg_helper(args: &cli::Args, m: &impl Mealplan) {
|
||||
if let Some(menus) = m.nth(args.days, args.vegetarian) {
|
||||
if args.plaintext {
|
||||
for i in menus.iter() {
|
||||
for i in menus.1.iter() {
|
||||
i.print_short_info();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if args.oneline {
|
||||
menus.first().unwrap().print_very_short_info();
|
||||
menus.1.first().unwrap().print_very_short_info();
|
||||
return;
|
||||
}
|
||||
|
||||
// Default case --> print fancy
|
||||
if let Some(dt) = Local::now().checked_add_days(chrono::Days::new(args.days as u64)) {
|
||||
println!("Datum: {}", dt.date_naive());
|
||||
}
|
||||
println!("Datum: {}", menus.0);
|
||||
println!("{}", m.name());
|
||||
table_short(
|
||||
menus
|
||||
.1
|
||||
.iter()
|
||||
.map(|&x| x.get_short_info())
|
||||
.collect::<Vec<(&str, String, &str)>>(),
|
||||
|
23
src/mensa.rs
23
src/mensa.rs
@@ -12,8 +12,8 @@ pub enum MensaName {
|
||||
pub trait Mealplan {
|
||||
fn id(&self) -> &str;
|
||||
fn name(&self) -> &str;
|
||||
fn today(&self) -> Vec<&Menu>;
|
||||
fn nth(&self, days: u8, vegetarian: bool) -> Option<Vec<&Menu>>;
|
||||
fn today(&self) -> (String, Vec<&Menu>);
|
||||
fn nth(&self, days: u8, vegetarian: bool) -> Option<(String, Vec<&Menu>)>;
|
||||
}
|
||||
|
||||
fn get_nth_date(days: u8) -> Option<chrono::DateTime<Local>> {
|
||||
@@ -70,35 +70,40 @@ impl Mealplan for Mensa {
|
||||
&&self.canteen.canteen
|
||||
}
|
||||
|
||||
fn today(&self) -> Vec<&Menu> {
|
||||
fn today(&self) -> (String, Vec<&Menu>) {
|
||||
let local = format!("{}", Local::now().format("%Y-%m-%d"));
|
||||
(
|
||||
local.clone(),
|
||||
self.canteen
|
||||
.menus
|
||||
.iter()
|
||||
.filter(|&x| x.menu_date == local)
|
||||
.collect()
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn nth(&self, days: u8, vegetarian: bool) -> Option<Vec<&Menu>> {
|
||||
fn nth(&self, days: u8, vegetarian: bool) -> Option<(String, Vec<&Menu>)> {
|
||||
match get_nth_date(days) {
|
||||
Some(dt) => {
|
||||
let local = format!("{}", dt.format("%Y-%m-%d"));
|
||||
if vegetarian {
|
||||
Some(
|
||||
Some((
|
||||
local.clone(),
|
||||
self.canteen
|
||||
.menus
|
||||
.iter()
|
||||
.filter(|&x| x.menu_date == local && x.menu_line.contains("veg"))
|
||||
.collect(),
|
||||
)
|
||||
))
|
||||
} else {
|
||||
Some(
|
||||
Some((
|
||||
local.clone(),
|
||||
self.canteen
|
||||
.menus
|
||||
.iter()
|
||||
.filter(|&x| x.menu_date == local)
|
||||
.collect(),
|
||||
)
|
||||
))
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
|
Reference in New Issue
Block a user