PoiScript / orgize

A Rust library for parsing org-mode files.
https://poiscript.github.io/orgize/
MIT License
289 stars 35 forks source link

Unable to access Timestamps for Repeating Tasks #57

Closed RyanGreenup closed 10 months ago

RyanGreenup commented 2 years ago

Problem

I've had some difficulty accessing the scheduled timestamp for repeated tasks and I'm not sure if this is a bug or if there is a different way to query for these repeated tasks.

What I've tried

I couldn't find anything in the docs and the json output of the below MWE only contains scheduled (in lower case) for the non-repeating tasks.

Further Info

This may be related to #27, #28, #29.

Minimum Working Example

Rust

Click Me ```rust use orgize::{ elements::{Datetime, Timestamp}, Org, }; use serde_json::to_string; fn main() { let org = Org::parse( r#" ** TODO Call Father SCHEDULED: <2008-02-10 Sun ++1w> Marking this DONE shifts the date by at least one week, but also by as many weeks as it takes to get this date into the future. However, it stays on a Sunday, even if you called and marked it done on Saturday. ** TODO Empty kitchen trash SCHEDULED: <2008-02-08 Fri 20:00 ++1d> Marking this DONE shifts the date by at least one day, and also by as many days as it takes to get the timestamp into the future. Since there is a time in the timestamp, the next deadline in the future will be on today's date if you complete the task before 20:00. ** TODO Check the batteries in the smoke detectors SCHEDULED: <2005-11-01 Tue .+1m> Marking this DONE shifts the date to one month after today. ** TODO Wash my hands SCHEDULED: <2019-04-05 08:00 Sun .+1h> Marking this DONE shifts the date to exactly one hour from now. ** TODO Task with repeater SCHEDULED: <2022-04-17 Sun +1w> ** TODO Task without repeater SCHEDULED: <2022-04-17 Sun> "#,); // Loop over the headlines for h in org.headlines() { let title = &h.title(&org).raw as &str; println!("\n\n{}\n-----------", title); match &h.title(&org).planning { Some(p) => println!("{:#?}", p), None => println!("No Planning Module"), } // Try and extract the timestamp match h.title(&org).scheduled() { Some(_t) => println!("Timestamp"), None => println!("No Timestamp"), }; } let org_json = to_string(&org).unwrap(); println!("{}", org_json); } ```

TOML

Click Me ```toml [package] name = "orgize_example" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] orgize = "0.9.0" serde_json = "*" colored = "*" chrono = "*" clap = { version = "3.1.6", features = ["derive"] } ```

Output

Raw

Click Me ``` Call Father ----------- No Planning Module No Timestamp Empty kitchen trash ----------- No Planning Module No Timestamp Check the batteries in the smoke detectors ----------- No Planning Module No Timestamp Wash my hands ----------- No Planning Module No Timestamp Task with repeater ----------- No Planning Module No Timestamp Task without repeater ----------- Planning { deadline: None, scheduled: Some( Active { start: Datetime { year: 2022, month: 4, day: 17, dayname: "Sun", hour: None, minute: None, }, repeater: None, delay: None, }, ), closed: None, } Timestamp {"type":"document","pre_blank":1,"children":[{"type":"headline","level":2,"children":[{"type":"title","level":2,"keyword":"TODO","raw":"Call Father","post_blank":0,"children":[{"type":"text","value":"Call Father"}]},{"type":"section","children":[{"type":"paragraph","post_blank":1,"children":[{"type":"text","value":" SCHEDULED: <2008-02-10 Sun ++1w>\n Marking this DONE shifts the date by at least one week, but also\n by as many weeks as it takes to get this date into the future.\n However, it stays on a Sunday, even if you called and marked it\n done on Saturday."}]}]}]},{"type":"headline","level":2,"children":[{"type":"title","level":2,"keyword":"TODO","raw":"Empty kitchen trash","post_blank":0,"children":[{"type":"text","value":"Empty kitchen trash"}]},{"type":"section","children":[{"type":"paragraph","post_blank":1,"children":[{"type":"text","value":" SCHEDULED: <2008-02-08 Fri 20:00 ++1d>\n Marking this DONE shifts the date by at least one day, and also\n by as many days as it takes to get the timestamp into the future.\n Since there is a time in the timestamp, the next deadline in the\n future will be on today's date if you complete the task before\n 20:00."}]}]}]},{"type":"headline","level":2,"children":[{"type":"title","level":2,"keyword":"TODO","raw":"Check the batteries in the smoke detectors","post_blank":0,"children":[{"type":"text","value":"Check the batteries in the smoke detectors"}]},{"type":"section","children":[{"type":"paragraph","post_blank":1,"children":[{"type":"text","value":" SCHEDULED: <2005-11-01 Tue .+1m>\n Marking this DONE shifts the date to one month after today."}]}]}]},{"type":"headline","level":2,"children":[{"type":"title","level":2,"keyword":"TODO","raw":"Wash my hands","post_blank":0,"children":[{"type":"text","value":"Wash my hands"}]},{"type":"section","children":[{"type":"paragraph","post_blank":1,"children":[{"type":"text","value":" SCHEDULED: <2019-04-05 08:00 Sun .+1h>\n Marking this DONE shifts the date to exactly one hour from now."}]}]}]},{"type":"headline","level":2,"children":[{"type":"title","level":2,"keyword":"TODO","raw":"Task with repeater","post_blank":0,"children":[{"type":"text","value":"Task with repeater"}]},{"type":"section","children":[{"type":"paragraph","post_blank":1,"children":[{"type":"text","value":"SCHEDULED: <2022-04-17 Sun +1w>"}]}]}]},{"type":"headline","level":2,"children":[{"type":"title","level":2,"keyword":"TODO","raw":"Task without repeater","planning":{"scheduled":{"timestamp_type":"active","start":{"year":2022,"month":4,"day":17,"dayname":"Sun"}}},"post_blank":1,"children":[{"type":"text","value":"Task without repeater"}]}]}]} ```

Json

Click Me ```json { "type": "document", "pre_blank": 1, "children": [ { "type": "headline", "level": 2, "children": [ { "type": "title", "level": 2, "keyword": "TODO", "raw": "Call Father", "post_blank": 0, "children": [ { "type": "text", "value": "Call Father" } ] }, { "type": "section", "children": [ { "type": "paragraph", "post_blank": 1, "children": [ { "type": "text", "value": " SCHEDULED: <2008-02-10 Sun ++1w>\n Marking this DONE shifts the date by at least one week, but also\n by as many weeks as it takes to get this date into the future.\n However, it stays on a Sunday, even if you called and marked it\n done on Saturday." } ] } ] } ] }, { "type": "headline", "level": 2, "children": [ { "type": "title", "level": 2, "keyword": "TODO", "raw": "Empty kitchen trash", "post_blank": 0, "children": [ { "type": "text", "value": "Empty kitchen trash" } ] }, { "type": "section", "children": [ { "type": "paragraph", "post_blank": 1, "children": [ { "type": "text", "value": " SCHEDULED: <2008-02-08 Fri 20:00 ++1d>\n Marking this DONE shifts the date by at least one day, and also\n by as many days as it takes to get the timestamp into the future.\n Since there is a time in the timestamp, the next deadline in the\n future will be on today's date if you complete the task before\n 20:00." } ] } ] } ] }, { "type": "headline", "level": 2, "children": [ { "type": "title", "level": 2, "keyword": "TODO", "raw": "Check the batteries in the smoke detectors", "post_blank": 0, "children": [ { "type": "text", "value": "Check the batteries in the smoke detectors" } ] }, { "type": "section", "children": [ { "type": "paragraph", "post_blank": 1, "children": [ { "type": "text", "value": " SCHEDULED: <2005-11-01 Tue .+1m>\n Marking this DONE shifts the date to one month after today." } ] } ] } ] }, { "type": "headline", "level": 2, "children": [ { "type": "title", "level": 2, "keyword": "TODO", "raw": "Wash my hands", "post_blank": 0, "children": [ { "type": "text", "value": "Wash my hands" } ] }, { "type": "section", "children": [ { "type": "paragraph", "post_blank": 1, "children": [ { "type": "text", "value": " SCHEDULED: <2019-04-05 08:00 Sun .+1h>\n Marking this DONE shifts the date to exactly one hour from now." } ] } ] } ] }, { "type": "headline", "level": 2, "children": [ { "type": "title", "level": 2, "keyword": "TODO", "raw": "Task with repeater", "post_blank": 0, "children": [ { "type": "text", "value": "Task with repeater" } ] }, { "type": "section", "children": [ { "type": "paragraph", "post_blank": 1, "children": [ { "type": "text", "value": "SCHEDULED: <2022-04-17 Sun +1w>" } ] } ] } ] }, { "type": "headline", "level": 2, "children": [ { "type": "title", "level": 2, "keyword": "TODO", "raw": "Task without repeater", "planning": { "scheduled": { "timestamp_type": "active", "start": { "year": 2022, "month": 4, "day": 17, "dayname": "Sun" } } }, "post_blank": 1, "children": [ { "type": "text", "value": "Task without repeater" } ] } ] } ] } ```
shimano-yoshio commented 2 years ago

I found rpearters are not implemented in src/elements/timestamp.rs.

calmofthestorm commented 2 years ago

There's https://github.com/PoiScript/orgize/pull/32 for it.

shimano-yoshio commented 2 years ago

Thanks! Your PR was smoothly patched and is working! But I changed src/elements/mod.r to use newly added public sutructs and unums.

in src/elements/mod.rs, lin 53

timestamp::{Datetime, Delay, DelayMark, Repeater, RepeaterMark, TimeUnit, Timestamp},
PoiScript commented 10 months ago

repeater/delay in timestamp is supported in v0.10.0-alpha.4