Verified Commit 6a1628e8 authored by Maxime Buquet's avatar Maxime Buquet
Browse files

Some more rustfmt


Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <pep@bouah.net>
parent 6b2b957d
......@@ -4,13 +4,13 @@
// Distributed under terms of the LGPLv3+ license.
//
use chrono::{Date, Duration, Utc};
use crate::errors::ChronophageError as Error;
use chrono::{Date, Duration, Utc};
use serde::{ser::SerializeMap, Serialize, Serializer};
use crate::types::{EntryType, Task as BaseTask, TimesheetDay, TimesheetItem};
use std::fmt;
use try_from::TryFrom;
use crate::types::{EntryType, Task as BaseTask, TimesheetDay, TimesheetItem};
/// Tasks in Collabora Chronophage are more restricted than standard gtimelog
/// tasks. They must contain 4 identifiers, and these identifiers have specific
......@@ -170,10 +170,7 @@ pub struct Day {
impl Day {
pub fn new(date: Date<Utc>, items: Vec<Entry>) -> Day {
Day {
date,
items,
}
Day { date, items }
}
}
......@@ -181,7 +178,7 @@ impl Day {
// Vec<Day> the same way. There must be a better way. Halp.
#[derive(Debug, Clone, PartialEq)]
pub struct Days {
pub days: Vec<Day>
pub days: Vec<Day>,
}
impl Days {
......@@ -214,16 +211,18 @@ impl Serialize for Days {
S: Serializer,
{
let mut map = serializer.serialize_map(Some(self.days.len()))?;
self.days.iter().try_for_each(|day| -> Result<(), S::Error> {
let s_date = day.date.format("%Y-%m-%d").to_string();
let s_items = day.items.iter().fold(String::new(), |mut s, item| {
s.push_str(String::from(item).as_str());
s.push_str("\n");
s
});
map.serialize_entry(&s_date, &s_items)?;
Ok(())
})?;
self.days
.iter()
.try_for_each(|day| -> Result<(), S::Error> {
let s_date = day.date.format("%Y-%m-%d").to_string();
let s_items = day.items.iter().fold(String::new(), |mut s, item| {
s.push_str(String::from(item).as_str());
s.push_str("\n");
s
});
map.serialize_entry(&s_date, &s_items)?;
Ok(())
})?;
map.end()
}
}
......@@ -262,10 +261,10 @@ impl TryFrom<TimesheetDay> for Day {
#[cfg(test)]
mod test {
use super::{Day, Days, Entry, Task};
use chrono::{Date, Duration, NaiveDate, Utc};
use crate::errors::ChronophageError as Error;
use serde_urlencoded;
use crate::types::{Task as BaseTask, TimesheetDay, TimesheetItem};
use chrono::{Date, Duration, NaiveDate, Utc};
use serde_urlencoded;
use try_from::TryFrom;
......@@ -342,23 +341,21 @@ mod test {
#[test]
fn serialize_day() {
let days = Days::from(
Day::new(
Date::from_utc(NaiveDate::from_ymd(2018, 7, 5), Utc),
vec![
Entry::new(
Duration::minutes(5),
Task::new("foo", "bar", "baz", "qxx"),
Some("Test"),
),
Entry::new(
Duration::hours(7),
Task::new("foo", "bar", "baz", "qxx"),
Some("Test"),
),
],
)
);
let days = Days::from(Day::new(
Date::from_utc(NaiveDate::from_ymd(2018, 7, 5), Utc),
vec![
Entry::new(
Duration::minutes(5),
Task::new("foo", "bar", "baz", "qxx"),
Some("Test"),
),
Entry::new(
Duration::hours(7),
Task::new("foo", "bar", "baz", "qxx"),
Some("Test"),
),
],
));
let result = "2018-07-05=0%3A05+foo%3A+bar%3A+baz%3A+qxx%3A+Test%0A7%3A00+foo%3A+bar%3A+baz%3A+qxx%3A+Test%0A";
......
......@@ -10,7 +10,8 @@ pub mod timelog;
pub mod timesheet;
pub use self::chronophage::{
Day as ChronophageDay, Days as ChronophageDays, Entry as ChronophageEntry, Task as ChronophageTask,
Day as ChronophageDay, Days as ChronophageDays, Entry as ChronophageEntry,
Task as ChronophageTask,
};
pub use self::task::Task;
pub use self::timelog::{EntryType, TimelogDay, TimelogEntry};
......
......@@ -4,9 +4,9 @@
// Distributed under terms of the LGPLv3+ license.
//
use crate::types::Task;
use chrono::{Date, DateTime, Utc};
use std::cmp::Ordering;
use crate::types::Task;
/// There are multiple types of entries to use in timelogs. This defines a
/// standard (`Full`) entry, and a slack (`Slack`) entry.
......@@ -117,8 +117,8 @@ pub struct TimelogDay {
#[cfg(test)]
mod test {
use chrono::{TimeZone, Utc};
use crate::types::{EntryType, Task, TimelogEntry};
use chrono::{TimeZone, Utc};
#[test]
fn new_slack() {
......
......@@ -4,8 +4,8 @@
// Distributed under terms of the LGPLv3+ license.
//
use chrono::{Date, Duration, Utc};
use crate::types::{EntryType, Task, TimelogDay, TimelogEntry};
use chrono::{Date, Duration, Utc};
///
#[derive(Debug, PartialEq)]
......@@ -81,8 +81,8 @@ impl From<TimelogDay> for TimesheetDay {
#[cfg(test)]
mod test {
use chrono::{Date, Duration, NaiveDate, TimeZone, Utc};
use crate::types::{Task, TimelogDay, TimelogEntry, TimesheetDay, TimesheetItem};
use chrono::{Date, Duration, NaiveDate, TimeZone, Utc};
#[test]
fn test_timesheet_from_day_empty() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment