Verified Commit 1e2d1892 authored by Maxime Buquet's avatar Maxime Buquet
Browse files

Fix ordering of entries when splitting by day


Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <pep@bouah.net>
parent 8597eab5
......@@ -7,13 +7,14 @@
use chrono::{Duration, NaiveTime};
use errors::Error;
use std::cmp::Ordering;
use types::{TimelogDay, TimelogEntry};
pub fn split_by_days(
entries: Vec<TimelogEntry>,
mut entries: Vec<TimelogEntry>,
vmidnight: NaiveTime,
) -> Result<Vec<TimelogDay>, Error> {
// TODO: Sort entries
entries.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal));
let mut last_date = None;
Ok(entries.into_iter().fold(vec![], |mut acc, entry| {
......@@ -176,7 +177,6 @@ mod test {
}
#[test]
#[ignore]
fn test_split_by_days_order() {
let vmidnight = NaiveTime::parse_from_str("00:00", "%H:%M").unwrap();
let entries = vec![
......
......@@ -5,6 +5,7 @@
//
use chrono::{DateTime, Utc};
use std::cmp::Ordering;
use types::{FullEntry, SlackEntry};
#[derive(Debug, Clone, PartialEq)]
......@@ -19,6 +20,12 @@ pub struct TimelogEntry {
pub entry: EntryType,
}
impl PartialOrd for TimelogEntry {
fn partial_cmp(&self, other: &TimelogEntry) -> Option<Ordering> {
self.datetime.partial_cmp(&other.datetime)
}
}
impl TimelogEntry {
pub fn new_full(
datetime: DateTime<Utc>,
......
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