summaryrefslogtreecommitdiffstats
path: root/src/actions/unroll.rs
blob: 882da7e2c09cd8d1515549caea00cf17c275235f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::path::Path;

use crate::khline::KhLine;
use crate::KhResult;
use crate::cli::UnrollArgs;

pub fn action_unroll(args: &UnrollArgs) -> KhResult<()> {
  let filepath = &args.path;
  do_unroll(filepath)?;

  Ok(())
}

fn do_unroll(filepath: &Path) -> KhResult<()> {
  let path = filepath.to_str().ok_or_else(|| "str to path failed")?;
  let khline = path.parse::<KhLine>()?;
  let cal = khline.to_cal()?;

  for event in cal.events_iter() {
    if event.is_recur_master() {
      let recurs = event.get_recur_datetimes();
      for datetime in recurs {
        println!("{} {}", datetime.timestamp(), cal.get_path_as_string().unwrap_or_else(|| "".to_string()));
      }
    }
  }
  Ok(())
}