Browse Source

Order events when adding

master
Julio Biason 5 years ago
parent
commit
fd19faca53
  1. 4
      README.md
  2. 40
      src/eventlist/event.rs
  3. 1
      src/eventlist/eventlist.rs
  4. 2
      src/main.rs

4
README.md

@ -24,13 +24,13 @@ tell you that you have 15 days up to it.
- [x] List events
- [ ] Add Events with time
- [ ] List events with time
- [ ] Sort events by ETA
- [x] Sort events by ETA
- [ ] Option to remove events
- [ ] Move the app "db" to a fixed space
- [x] Replace `dbg!` with [env_logger](https://crates.io/crates/env_logger)
(reasoning: Although `dbg!` is nice and dandy, it can't be disabled, and
that's bad UI)
- [ ] Remove `unwrap()`s (for example, in the argument parsing).
- [ ] Remove `unwrap()`s
## License

40
src/eventlist/event.rs

@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::cmp::Ordering;
use std::convert::From;
use std::fmt;
@ -54,6 +55,17 @@ impl From<&EventDateType> for DateTime<Utc> {
}
}
impl From<&EventDateType> for String {
fn from(origin: &EventDateType) -> String {
match origin {
EventDateType::AllDay(d) => format!("{}{}{}0000", d.year, d.month, d.day),
EventDateType::AtTime(d, t) => {
format!("{}{}{}{}{}", d.year, d.month, d.day, t.hour, t.min)
}
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Event {
id: String,
@ -102,3 +114,31 @@ impl fmt::Display for Event {
)
}
}
impl Eq for Event {}
impl PartialEq for Event {
fn eq(&self, other: &Self) -> bool {
let self_str = String::from(&self.due);
let other_str = String::from(&other.due);
self_str == other_str
}
}
impl PartialOrd for Event {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let self_str = String::from(&self.due);
let other_str = String::from(&other.due);
Some(self_str.cmp(&other_str))
}
}
impl Ord for Event {
fn cmp(&self, other: &Self) -> Ordering {
let self_str = String::from(&self.due);
let other_str = String::from(&other.due);
self_str.cmp(&other_str)
}
}

1
src/eventlist/eventlist.rs

@ -56,6 +56,7 @@ impl EventList {
pub fn push(&mut self, event: Event) {
self.events.push(event);
self.events.sort();
}
pub fn save(&self) {

2
src/main.rs

@ -32,7 +32,7 @@ fn main() {
match command {
args::Action::List => list(),
args::Action::Add(description, date) => add_with_date(&description, &date),
_ => println!("Unknown command"),
_ => println!("Command not implemented yet"),
}
}
}

Loading…
Cancel
Save