6

I would like to use org-mode not with a GTD-like system but rather as a planner/scheduler, scheduling/timestamping every captured task on capture or refile. In such a system, detailed planning of a day including specific frames of times according to the estimated duration a task will take to get done, might be advantageous.

Would it be possible to generate a time frame from an existing effort estimate property when a timestamp is created? This would mean that, when a) scheduling is called and b) I enter not only a date but also a time and c) an effort property exists, this time will automatically be turned into a time frame according to said property.

Some hints as to how this could be achieved would be more than enough, I just do not know enough elisp to get started.

Edit

after capturing the task in my refile.org would look like this:

* TODO Sample todo
 :PROPERTIES:
 :Effort:   1h
 :END:

now when refiling I look at it and decide that I will do it, say, on Friday at 10am:

* TODO Sample todo
  SCHEDULED: <2014-04-18 Fr 10:00>
  :PROPERTIES:
  :Effort:   1h
  :END:

the function that could be called now would automatically add a time range according to effort estimate:

* TODO Sample todo
 SCHEDULED: <2014-04-18 Fr 10:00-11:00>
 :PROPERTIES:
 :Effort:   1h
 :END:

Edit2

See lawlists accepted answer below for a robust solution

Mathäus
  • 63
  • 1
  • 4
  • If you could post a sample of how the end result will look, it would be easier for someone here to write it up in `elisp` format. Otherwise, someone will do a draft and then you may ask for revisions . . . because it wasn't exactly clear what the end result will look like. – lawlist Apr 13 '14 at 20:30
  • I am very sorry for being unclear and thank you for pointing that out. let me try: – Mathäus Apr 14 '14 at 15:05
  • It is now crystal clear -- thank you. – lawlist Apr 14 '14 at 16:57
  • The effort property drawer example in the org-mode documentation looks like this `(setq org-global-properties '(("Effort_ALL". "0 0:10 0:30 1:00 2:00 3:00 4:00")))`. If we use `1h`, then we need a transform function like `(car (split-string "1h" "h"))` If we use minutes (e.g., "15m"), then we need a different transform function like `(car (split-string "15m" "m"))`. Can you please give me a link to the org-mode documentation that supports the `effort` format of `h` and `m`, or provide a list of all formats that you anticipate using. Alternatively, you could use the first method (above). – lawlist Apr 14 '14 at 17:25

1 Answers1

9

To add a scheduled timestamp, use: M-x org-schedule

To add effort as a range to an existing timestamp, using the standard effort format (e.g., "0 0:10 0:30 1:00 2:00 3:00 4:00") [see http://orgmode.org/manual/Filtering_002flimiting-agenda-items.html ], the following function should do the job. NOTE org-mode version 7 uses all lowercase for the org-element-property property drawer, whereas org-mode version 8 uses all capitals -- e.g., (org-element-property :EFFORT (org-element-at-point))


org-schedule-effort was tested with org-mode version 8.2.5.c using the following example task -- not using h or m for effort. Emacs rounds 00 01 02 03 04 05 06 07 08 09 to 0 1 2 3 4 5 6 7 8 9 and timestamp format requires the former -- therefore, we need to concatenate a 0 to the beginning if less than 10.

* TODO Sample todo
  SCHEDULED: <2014-04-18 Fr 10:00>
  :PROPERTIES:
  :Effort:  1:15
  :END:

(defun org-schedule-effort ()
(interactive)
  (save-excursion
    (org-back-to-heading t)
    (let* (
        (element (org-element-at-point))
        (effort (org-element-property :EFFORT element))
        (scheduled (org-element-property :scheduled element))
        (ts-year-start (org-element-property :year-start scheduled))
        (ts-month-start (org-element-property :month-start scheduled))
        (ts-day-start (org-element-property :day-start scheduled))
        (ts-hour-start (org-element-property :hour-start scheduled))
        (ts-minute-start (org-element-property :minute-start scheduled)) )
      (org-schedule nil (concat
        (format "%s" ts-year-start)
        "-"
        (if (< ts-month-start 10)
          (concat "0" (format "%s" ts-month-start))
          (format "%s" ts-month-start))
        "-"
        (if (< ts-day-start 10)
          (concat "0" (format "%s" ts-day-start))
          (format "%s" ts-day-start))
        " "
        (if (< ts-hour-start 10)
          (concat "0" (format "%s" ts-hour-start))
          (format "%s" ts-hour-start))
        ":"
        (if (< ts-minute-start 10)
          (concat "0" (format "%s" ts-minute-start))
          (format "%s" ts-minute-start))
        "+"
        effort)) )))
lawlist
  • 13,099
  • 3
  • 49
  • 158
  • 1
    Thank you very much, this definitely is a start! However, I cannot get this to work for some reason. Tried also with a clean emacs -Q (24.4). Org-version is 8.2.5c. When I call the function with point on the sample todo (or any other todo), the time is removed completely and the scheduled date is set to 2014-04-15. This was independent of the date and time of the tasks I tried. Might this have something todo with the system language/date format being german? – Mathäus Apr 15 '14 at 14:37
  • I'll work on it some more during the day and repost the revised function -- sorry for the inconvenience. – lawlist Apr 15 '14 at 16:14
  • it is not an inconvenience! thank you for helping - I hope I am not the only one for whom such a thing might be useful. tried in a virtual machine with everything set to en_US - same outcome. cf also my pathetic attempt to add to your function above. – Mathäus Apr 15 '14 at 16:29
  • @Mathäus -- I have revised the function -- adding additional fields year, month and day -- I updated all fields (except year) to concatenate a "0" to the front if less than 10. Emacs automatically knows to add `<` and `>` to the ends of the timestamp, and it also calculates the correct day of the week. – lawlist Apr 15 '14 at 16:36
  • 1
    That works very well now. Thank you so much. I will play around with it and try to expand (an advice for org-schedule to automatically check if a time has been scheduled and an effort has been set and call your function; making it work with the agenda buffer) and report back. – Mathäus Apr 16 '14 at 01:34
  • I'm glad we got it working. If you need a new function for org-agenda that is based on this function, go ahead and give it a try yourself first -- if you get stuck and need help, post a new question along with a link to this question (like this http://stackoverflow.com/a/23067020/2112489 ) so that others can easily see where you've been and where you're going. Many org-agenda functions jump back to the original org-mode file and do something and then jump back again to the org-agenda buffer -- usually behind the scenes so the user doesn't see the change of focus between buffers . . . – lawlist Apr 16 '14 at 04:21
  • @lawlist, I liked the question and answer, but have been using plain Timestamp over Scheduled so far. I have made a new question at http://stackoverflow.com/questions/23235094/org-mode-timestamp-effort-time-range. Hope it is straightforward, it did not seem so to me. – Brady Trainor Apr 23 '14 at 05:01
  • Today on emacs 26 this function does not work for me.... Am I alone? – falematte Jun 15 '20 at 09:50
  • @falematte This is working well for me, today on emacs 27.2.5 and org-mode 9.4.5. – ngm Jun 29 '22 at 08:25