test-org-clock.el 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. ;;; test-org-clock.el --- Tests for org-clock.el
  2. ;; Copyright (C) 2012, 2014, 2015, 2019 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; Released under the GNU General Public License version 3
  5. ;; see: http://www.gnu.org/licenses/gpl-3.0.html
  6. ;;;; Comments
  7. ;;; Code:
  8. (defun org-test-clock-create-timestamp (input &optional inactive with-time)
  9. "Create a timestamp out of a date/time prompt string.
  10. INPUT is a string as expected in a date/time prompt, i.e \"+2d\"
  11. or \"2/5\".
  12. When optional argument INACTIVE is non-nil, return an inactive
  13. timestamp. When optional argument WITH-TIME is non-nil, also
  14. insert hours and minutes.
  15. Return the timestamp as a string."
  16. (org-element-interpret-data
  17. (let ((time (decode-time
  18. (apply #'encode-time
  19. (mapcar (lambda (el) (or el 0))
  20. (org-read-date-analyze
  21. input nil (decode-time (current-time))))))))
  22. (list 'timestamp
  23. (list :type (if inactive 'inactive 'active)
  24. :minute-start (and with-time (nth 1 time))
  25. :hour-start (and with-time (nth 2 time))
  26. :day-start (nth 3 time)
  27. :month-start (nth 4 time)
  28. :year-start (nth 5 time))))))
  29. (defun org-test-clock-create-clock (input1 &optional input2)
  30. "Create a clock line out of two date/time prompts.
  31. INPUT1 and INPUT2 are strings as expected in a date/time prompt,
  32. i.e \"+2d\" or \"2/5\". They respectively refer to start and end
  33. range. INPUT2 can be omitted if clock hasn't finished yet.
  34. Return the clock line as a string."
  35. (let* ((beg (org-test-clock-create-timestamp input1 t t))
  36. (end (and input2 (org-test-clock-create-timestamp input2 t t)))
  37. (sec-diff (and input2
  38. (floor (- (org-time-string-to-seconds end)
  39. (org-time-string-to-seconds beg))))))
  40. (concat org-clock-string " " beg
  41. (when end
  42. (concat "--" end " => "
  43. (format "%2d:%02d"
  44. (/ sec-diff 3600)
  45. (/ (mod sec-diff 3600) 60))))
  46. "\n")))
  47. (defun test-org-clock-clocktable-contents (options &optional initial)
  48. "Return contents of a Clock table for current buffer
  49. OPTIONS is a string of Clock table options. Optional argument
  50. INITIAL is a string specifying initial contents within the Clock
  51. table.
  52. Caption is ignored in contents. The clocktable doesn't appear in
  53. the buffer."
  54. (declare (indent 2))
  55. (goto-char (point-min))
  56. (save-excursion
  57. (insert "#+BEGIN: clocktable " options "\n")
  58. (when initial (insert initial))
  59. (unless (string-suffix-p "\n" initial) (insert "\n"))
  60. (insert "#+END:\n"))
  61. (unwind-protect
  62. (save-excursion
  63. (let ((org-duration-format 'h:mm)) (org-update-dblock))
  64. (forward-line)
  65. ;; Skip caption.
  66. (when (looking-at "#\\+CAPTION:") (forward-line))
  67. (buffer-substring-no-properties
  68. (point) (progn (search-forward "#+END:") (line-end-position 0))))
  69. ;; Remove clocktable.
  70. (delete-region (point) (search-forward "#+END:\n"))))
  71. ;;; Clock drawer
  72. (ert-deftest test-org-clock/into-drawer ()
  73. "Test `org-clock-into-drawer' specifications."
  74. ;; When `org-clock-into-drawer' is nil, do not use a clock drawer.
  75. (should-not
  76. (org-test-with-temp-text "* H"
  77. (let ((org-clock-into-drawer nil)
  78. (org-log-into-drawer nil))
  79. (org-clock-into-drawer))))
  80. (should-not
  81. (org-test-with-temp-text "* H"
  82. (let ((org-clock-into-drawer nil)
  83. (org-log-into-drawer t))
  84. (org-clock-into-drawer))))
  85. (should-not
  86. (org-test-with-temp-text "* H"
  87. (let ((org-clock-into-drawer nil)
  88. (org-log-into-drawer "BAR"))
  89. (org-clock-into-drawer))))
  90. ;; When `org-clock-into-drawer' is a string, use it
  91. ;; unconditionally.
  92. (should
  93. (equal "FOO"
  94. (org-test-with-temp-text "* H"
  95. (let ((org-clock-into-drawer "FOO")
  96. (org-log-into-drawer nil))
  97. (org-clock-into-drawer)))))
  98. (should
  99. (equal "FOO"
  100. (org-test-with-temp-text "* H"
  101. (let ((org-clock-into-drawer "FOO")
  102. (org-log-into-drawer t))
  103. (org-clock-into-drawer)))))
  104. (should
  105. (equal "FOO"
  106. (org-test-with-temp-text "* H"
  107. (let ((org-clock-into-drawer "FOO")
  108. (org-log-into-drawer "BAR"))
  109. (org-clock-into-drawer)))))
  110. ;; When `org-clock-into-drawer' is an integer, return it.
  111. (should
  112. (= 1
  113. (org-test-with-temp-text "* H"
  114. (let ((org-clock-into-drawer 1)
  115. (org-log-into-drawer nil))
  116. (org-clock-into-drawer)))))
  117. (should
  118. (= 1
  119. (org-test-with-temp-text "* H"
  120. (let ((org-clock-into-drawer 1)
  121. (org-log-into-drawer t))
  122. (org-clock-into-drawer)))))
  123. (should
  124. (= 1
  125. (org-test-with-temp-text "* H"
  126. (let ((org-clock-into-drawer 1)
  127. (org-log-into-drawer "BAR"))
  128. (org-clock-into-drawer)))))
  129. ;; Otherwise, any non-nil value defaults to `org-log-into-drawer' or
  130. ;; "LOGBOOK" if it is nil.
  131. (should
  132. (equal "LOGBOOK"
  133. (org-test-with-temp-text "* H"
  134. (let ((org-clock-into-drawer t)
  135. (org-log-into-drawer nil))
  136. (org-clock-into-drawer)))))
  137. (should
  138. (equal "LOGBOOK"
  139. (org-test-with-temp-text "* H"
  140. (let ((org-clock-into-drawer t)
  141. (org-log-into-drawer t))
  142. (org-clock-into-drawer)))))
  143. (should
  144. (equal "FOO"
  145. (org-test-with-temp-text "* H"
  146. (let ((org-clock-into-drawer t)
  147. (org-log-into-drawer "FOO"))
  148. (org-clock-into-drawer)))))
  149. ;; A non-nil "CLOCK_INTO_DRAWER" property overrides
  150. ;; `org-clock-into-drawer' value.
  151. (should
  152. (equal "LOGBOOK"
  153. (org-test-with-temp-text
  154. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:END:"
  155. (let ((org-clock-into-drawer nil)
  156. (org-log-into-drawer nil))
  157. (org-clock-into-drawer)))))
  158. (should
  159. (equal "FOO"
  160. (org-test-with-temp-text
  161. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: FOO\n:END:"
  162. (let ((org-clock-into-drawer nil)
  163. (org-log-into-drawer nil))
  164. (org-clock-into-drawer)))))
  165. (should-not
  166. (org-test-with-temp-text
  167. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:"
  168. (let ((org-clock-into-drawer t)
  169. (org-log-into-drawer nil))
  170. (org-clock-into-drawer))))
  171. ;; "CLOCK_INTO_DRAWER" can be inherited.
  172. (should
  173. (equal "LOGBOOK"
  174. (org-test-with-temp-text
  175. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:END:\n** H2<point>"
  176. (let ((org-clock-into-drawer nil)
  177. (org-log-into-drawer nil))
  178. (org-clock-into-drawer)))))
  179. (should
  180. (equal "FOO"
  181. (org-test-with-temp-text
  182. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: FOO\n:END:\n** H2<point>"
  183. (let ((org-clock-into-drawer nil)
  184. (org-log-into-drawer nil))
  185. (org-clock-into-drawer)))))
  186. (should-not
  187. (org-test-with-temp-text
  188. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:\n** H2<point>"
  189. (let ((org-clock-into-drawer t)
  190. (org-log-into-drawer nil))
  191. (org-clock-into-drawer)))))
  192. (ert-deftest test-org-clock/drawer-name ()
  193. "Test `org-clock-drawer-name' specifications."
  194. ;; A nil value for `org-clock-into-drawer' means no drawer is
  195. ;; expected whatsoever.
  196. (should-not
  197. (org-test-with-temp-text "* H"
  198. (let ((org-clock-into-drawer nil)
  199. (org-log-into-drawer nil))
  200. (org-clock-drawer-name))))
  201. (should-not
  202. (org-test-with-temp-text "* H"
  203. (let ((org-clock-into-drawer nil)
  204. (org-log-into-drawer t))
  205. (org-clock-drawer-name))))
  206. (should-not
  207. (org-test-with-temp-text "* H"
  208. (let ((org-clock-into-drawer nil)
  209. (org-log-into-drawer "FOO"))
  210. (org-clock-drawer-name))))
  211. ;; A string value for `org-clock-into-drawer' means to use it
  212. ;; unconditionally.
  213. (should
  214. (equal "FOO"
  215. (org-test-with-temp-text "* H"
  216. (let ((org-clock-into-drawer "FOO")
  217. (org-log-into-drawer nil))
  218. (org-clock-drawer-name)))))
  219. (should
  220. (equal "FOO"
  221. (org-test-with-temp-text "* H"
  222. (let ((org-clock-into-drawer "FOO")
  223. (org-log-into-drawer t))
  224. (org-clock-drawer-name)))))
  225. (should
  226. (equal "FOO"
  227. (org-test-with-temp-text "* H"
  228. (let ((org-clock-into-drawer "FOO")
  229. (org-log-into-drawer "BAR"))
  230. (org-clock-drawer-name)))))
  231. ;; When the value in `org-clock-into-drawer' is a number, re-use
  232. ;; `org-log-into-drawer' or use default "LOGBOOK" value.
  233. (should
  234. (equal "FOO"
  235. (org-test-with-temp-text "* H"
  236. (let ((org-clock-into-drawer 1)
  237. (org-log-into-drawer "FOO"))
  238. (org-clock-drawer-name)))))
  239. (should
  240. (equal "LOGBOOK"
  241. (org-test-with-temp-text "* H"
  242. (let ((org-clock-into-drawer 1)
  243. (org-log-into-drawer t))
  244. (org-clock-drawer-name)))))
  245. (should
  246. (equal "LOGBOOK"
  247. (org-test-with-temp-text "* H"
  248. (let ((org-clock-into-drawer 1)
  249. (org-log-into-drawer nil))
  250. (org-clock-drawer-name))))))
  251. ;;; Clocktable
  252. (ert-deftest test-org-clock/clocktable/insert ()
  253. "Test insert clocktable dynamic block with `org-dynamic-block-insert-dblock'."
  254. (should
  255. (equal
  256. "| Headline | Time |
  257. |--------------+--------|
  258. | *Total time* | *1:00* |
  259. |--------------+--------|
  260. | H1 | 1:00 |"
  261. (org-test-with-temp-text "* H1\n<point>"
  262. (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
  263. (goto-line 2)
  264. (require 'org-clock)
  265. (org-dynamic-block-insert-dblock "clocktable")
  266. (goto-line 1)
  267. (unwind-protect
  268. (save-excursion
  269. (when (search-forward "#+CAPTION:") (forward-line))
  270. (buffer-substring-no-properties
  271. (point) (progn (search-forward "#+END:") (line-end-position 0))))
  272. (delete-region (point) (search-forward "#+END:\n")))))))
  273. (ert-deftest test-org-clock/clocktable/ranges ()
  274. "Test ranges in Clock table."
  275. ;; Relative time: Previous two days.
  276. (should
  277. (equal
  278. "| Headline | Time | |
  279. |------------------------------+--------+------|
  280. | *Total time* | *8:00* | |
  281. |------------------------------+--------+------|
  282. | Relative times in clocktable | 8:00 | |
  283. | Foo | | 8:00 |"
  284. (org-test-with-temp-text
  285. "* Relative times in clocktable\n** Foo\n<point>"
  286. (insert (org-test-clock-create-clock "-3d 8:00" "-3d 12:00"))
  287. (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
  288. (insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
  289. (test-org-clock-clocktable-contents
  290. ":tstart \"<-2d>\" :tend \"<today>\" :indent nil"))))
  291. ;; Relative time: Yesterday until now.
  292. (should
  293. (equal
  294. "| Headline | Time | |
  295. |------------------------------+--------+------|
  296. | *Total time* | *6:00* | |
  297. |------------------------------+--------+------|
  298. | Relative times in clocktable | 6:00 | |
  299. | Foo | | 6:00 |"
  300. (org-test-with-temp-text
  301. "* Relative times in clocktable\n** Foo\n<point>"
  302. (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
  303. (insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
  304. (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
  305. (test-org-clock-clocktable-contents
  306. ":tstart \"<yesterday>\" :tend \"<tomorrow>\" :indent nil"))))
  307. ;; Test `untilnow' block.
  308. (should
  309. (equal
  310. "| Headline | Time | |
  311. |------------------------------+--------+------|
  312. | *Total time* | *6:00* | |
  313. |------------------------------+--------+------|
  314. | Relative times in clocktable | 6:00 | |
  315. | Foo | | 6:00 |"
  316. (org-test-with-temp-text
  317. "* Relative times in clocktable\n** Foo\n<point>"
  318. (insert (org-test-clock-create-clock "-10y 15:00" "-10y 18:00"))
  319. (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
  320. (test-org-clock-clocktable-contents ":block untilnow :indent nil")))))
  321. (ert-deftest test-org-clock/clocktable/match ()
  322. "Test \":match\" parameter in Clock table."
  323. ;; Test match filtering.
  324. (should
  325. (equal
  326. "| Headline | Time | |
  327. |--------------+--------+------|
  328. | *Total time* | *2:00* | |
  329. |--------------+--------+------|
  330. | H1 | | 2:00 |"
  331. (org-test-with-temp-text "** H1\n\n*** H2 :tag:\n\n*** H3\n<point>"
  332. (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
  333. (goto-line 4)
  334. (insert (org-test-clock-create-clock ". 2:00" ". 4:00"))
  335. (test-org-clock-clocktable-contents ":match \"tag\" :indent nil")))))
  336. (ert-deftest test-org-clock/clocktable/tags ()
  337. "Test \":tags\" parameter in Clock table."
  338. ;; Test tags column.
  339. (should
  340. (equal
  341. "| Tags | Headline | Time | |
  342. |------+--------------+--------+------|
  343. | | *Total time* | *1:00* | |
  344. |------+--------------+--------+------|
  345. | tag | H1 | | 1:00 |"
  346. (org-test-with-temp-text "** H1 :tag:\n\n*** H2 \n<point>"
  347. (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
  348. (goto-line 4)
  349. (test-org-clock-clocktable-contents ":tags t :indent nil")))))
  350. (ert-deftest test-org-clock/clocktable/scope ()
  351. "Test \":scope\" parameter in Clock table."
  352. ;; Test `file-with-archives' scope. In particular, preserve "TBLFM"
  353. ;; line, and ignore "file" column.
  354. (should
  355. (equal
  356. "| Headline | Time | |
  357. |--------------+--------+-----|
  358. | *Total time* | *8:40* | foo |
  359. |--------------+--------+-----|
  360. | Test | 8:40 | foo |
  361. #+TBLFM: $3=string(\"foo\")"
  362. (org-test-with-temp-text-in-file
  363. "* Test
  364. CLOCK: [2012-03-29 Thu 8:00]--[2012-03-29 Thu 16:40] => 8:40"
  365. (test-org-clock-clocktable-contents ":scope file-with-archives"
  366. "#+TBLFM: $3=string(\"foo\")"))))
  367. ;; Test "function" scope.
  368. (should
  369. (string-match-p
  370. (regexp-quote "| ALL *Total time* | *1:00* |")
  371. (org-test-with-temp-text-in-file
  372. "* Test
  373. CLOCK: [2012-03-29 Thu 16:00]--[2012-03-29 Thu 17:00] => 1:00"
  374. (let ((the-file (buffer-file-name)))
  375. (org-test-with-temp-text-in-file ""
  376. (test-org-clock-clocktable-contents
  377. (format ":scope (lambda () (list %S))" the-file))))))))
  378. (ert-deftest test-org-clock/clocktable/maxlevel ()
  379. "Test \":maxlevel\" parameter in Clock table."
  380. (should
  381. (equal "| Headline | Time | |
  382. |--------------+--------+------|
  383. | *Total time* | *6:00* | |
  384. |--------------+--------+------|
  385. | Foo | 6:00 | |
  386. | \\_ Bar | | 2:00 |"
  387. (org-test-with-temp-text
  388. "* Foo
  389. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  390. ** Bar
  391. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  392. (test-org-clock-clocktable-contents ":maxlevel 3"))))
  393. (should
  394. (equal "| Headline | Time | |
  395. |--------------+--------+------|
  396. | *Total time* | *6:00* | |
  397. |--------------+--------+------|
  398. | Foo | 6:00 | |
  399. | \\_ Bar | | 2:00 |"
  400. (org-test-with-temp-text
  401. "* Foo
  402. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  403. ** Bar
  404. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  405. (test-org-clock-clocktable-contents ":maxlevel 2"))))
  406. (should
  407. (equal "| Headline | Time |
  408. |--------------+--------|
  409. | *Total time* | *6:00* |
  410. |--------------+--------|
  411. | Foo | 6:00 |"
  412. (org-test-with-temp-text
  413. "* Foo
  414. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  415. ** Bar
  416. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  417. (test-org-clock-clocktable-contents ":maxlevel 1"))))
  418. ;; Special ":maxlevel 0" case: only report total file time.
  419. (should
  420. (equal "| Headline | Time |
  421. |--------------+--------|
  422. | *Total time* | *6:00* |
  423. |--------------+--------|"
  424. (org-test-with-temp-text
  425. "* Foo
  426. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  427. ** Bar
  428. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  429. (test-org-clock-clocktable-contents ":maxlevel 0")))))
  430. (ert-deftest test-org-clock/clocktable/formula ()
  431. "Test \":formula\" parameter in Clock table."
  432. ;; Test ":formula %". Handle various duration formats.
  433. (should
  434. (equal
  435. "| Headline | Time | % |
  436. |--------------+--------+-------|
  437. | *Total time* | *6:00* | 100.0 |
  438. |--------------+--------+-------|
  439. | Foo | 4:00 | 66.7 |
  440. | Bar | 2:00 | 33.3 |"
  441. (org-test-with-temp-text
  442. "* Foo
  443. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  444. * Bar
  445. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  446. (test-org-clock-clocktable-contents ":maxlevel 1 :formula %"))))
  447. (should
  448. (equal
  449. "| Headline | Time | % |
  450. |--------------+---------+-------|
  451. | *Total time* | *28:00* | 100.0 |
  452. |--------------+---------+-------|
  453. | Foo | 26:00 | 92.9 |
  454. | Bar | 2:00 | 7.1 |"
  455. (org-test-with-temp-text
  456. "* Foo
  457. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  458. * Bar
  459. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  460. (test-org-clock-clocktable-contents ":maxlevel 1 :formula %"))))
  461. ;; Properly align column with different depths.
  462. (should
  463. (equal "| Headline | Time | | | % |
  464. |---------------+--------+------+------+-------|
  465. | *Total time* | *1:00* | | | 100.0 |
  466. |---------------+--------+------+------+-------|
  467. | foo | 1:00 | | | 100.0 |
  468. | \\_ sub | | 0:15 | | 25.0 |
  469. | \\_ sub2 | | 0:15 | | 25.0 |
  470. | \\_ sub3 | | 0:30 | | 50.0 |
  471. | \\_ subsub1 | | | 0:15 | 25.0 |
  472. | \\_ subsub1 | | | 0:15 | 25.0 |"
  473. (org-test-with-temp-text
  474. "* foo
  475. ** sub
  476. :LOGBOOK:
  477. CLOCK: [2017-03-18 Sat 15:00]--[2017-03-18 Sat 15:15] => 0:15
  478. :END:
  479. ** sub2
  480. :LOGBOOK:
  481. CLOCK: [2017-03-18 Sat 15:15]--[2017-03-18 Sat 15:30] => 0:15
  482. :END:
  483. ** sub3
  484. *** subsub1
  485. :LOGBOOK:
  486. CLOCK: [2017-03-18 Sat 13:00]--[2017-03-18 Sat 13:15] => 0:15
  487. :END:
  488. *** subsub1
  489. :LOGBOOK:
  490. CLOCK: [2017-03-18 Sat 14:00]--[2017-03-18 Sat 14:15] => 0:15
  491. :END:"
  492. (test-org-clock-clocktable-contents ":maxlevel 3 :formula %")))))
  493. (ert-deftest test-org-clock/clocktable/lang ()
  494. "Test \":lang\" parameter in Clock table."
  495. ;; Test foreign translation
  496. (should
  497. (equal
  498. "| Headline | Time |
  499. |--------------+---------|
  500. | *Total time* | *26:00* |
  501. |--------------+---------|
  502. | Foo | 26:00 |"
  503. (org-test-with-temp-text
  504. "* Foo
  505. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  506. (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))))
  507. (should
  508. (equal
  509. "| En-tête | Durée |
  510. |----------------+---------|
  511. | *Durée totale* | *26:00* |
  512. |----------------+---------|
  513. | Foo | 26:00 |"
  514. (org-test-with-temp-text
  515. "* Foo
  516. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  517. (test-org-clock-clocktable-contents ":maxlevel 1 :lang fr"))))
  518. ;; No :lang parameter is equivalent to "en".
  519. (should
  520. (equal
  521. (org-test-with-temp-text
  522. "* Foo
  523. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  524. (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))
  525. (org-test-with-temp-text
  526. "* Foo
  527. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  528. (test-org-clock-clocktable-contents ":maxlevel 1"))))
  529. ;; Unknown translation fall backs to "en".
  530. (should
  531. (equal
  532. "| Headline | Time |
  533. |--------------+---------|
  534. | *Total time* | *26:00* |
  535. |--------------+---------|
  536. | Foo | 26:00 |"
  537. (org-test-with-temp-text
  538. "* Foo
  539. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  540. (test-org-clock-clocktable-contents ":maxlevel 1 :lang foo")))))
  541. (ert-deftest test-org-clock/clocktable/link ()
  542. "Test \":link\" parameter in Clock table."
  543. ;; If there is no file attached to the document, link directly to
  544. ;; the headline.
  545. (should
  546. (equal
  547. "| Headline | Time |
  548. |--------------+---------|
  549. | *Total time* | *26:00* |
  550. |--------------+---------|
  551. | [[Foo][Foo]] | 26:00 |"
  552. (org-test-with-temp-text
  553. "* Foo
  554. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  555. (test-org-clock-clocktable-contents ":link t"))))
  556. ;; Otherwise, link to the headline in the current file.
  557. (should
  558. (equal
  559. "| Headline | Time |
  560. |-------------------------------+---------|
  561. | *Total time* | *26:00* |
  562. |-------------------------------+---------|
  563. | [[file:filename::Foo][Foo]] | 26:00 |"
  564. (org-test-with-temp-text-in-file
  565. "* Foo
  566. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  567. (let ((file (buffer-file-name)))
  568. (replace-regexp-in-string
  569. (regexp-quote file) "filename"
  570. (test-org-clock-clocktable-contents ":link t :lang en"))))))
  571. ;; Ignore TODO keyword, priority cookie, COMMENT and tags in
  572. ;; headline.
  573. (should
  574. (equal
  575. "| Headline | Time |
  576. |--------------+---------|
  577. | *Total time* | *26:00* |
  578. |--------------+---------|
  579. | [[Foo][Foo]] | 26:00 |"
  580. (org-test-with-temp-text
  581. "* TODO Foo
  582. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  583. (test-org-clock-clocktable-contents ":link t"))))
  584. (should
  585. (equal
  586. "| Headline | Time |
  587. |--------------+---------|
  588. | *Total time* | *26:00* |
  589. |--------------+---------|
  590. | [[Foo][Foo]] | 26:00 |"
  591. (org-test-with-temp-text
  592. "* [#A] Foo
  593. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  594. (test-org-clock-clocktable-contents ":link t"))))
  595. (should
  596. (equal
  597. "| Headline | Time |
  598. |--------------+---------|
  599. | *Total time* | *26:00* |
  600. |--------------+---------|
  601. | [[Foo][Foo]] | 26:00 |"
  602. (org-test-with-temp-text
  603. "* COMMENT Foo
  604. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  605. (test-org-clock-clocktable-contents ":link t"))))
  606. (should
  607. (equal
  608. "| Headline | Time |
  609. |--------------+---------|
  610. | *Total time* | *26:00* |
  611. |--------------+---------|
  612. | [[Foo][Foo]] | 26:00 |"
  613. (org-test-with-temp-text
  614. "* Foo :tag:
  615. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  616. (test-org-clock-clocktable-contents ":link t"))))
  617. ;; Remove statistics cookie from headline description.
  618. (should
  619. (equal
  620. "| Headline | Time |
  621. |--------------+---------|
  622. | *Total time* | *26:00* |
  623. |--------------+---------|
  624. | [[Foo][Foo]] | 26:00 |"
  625. (org-test-with-temp-text
  626. "* Foo [50%]
  627. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  628. (test-org-clock-clocktable-contents ":link t"))))
  629. (should
  630. (equal
  631. "| Headline | Time |
  632. |--------------+---------|
  633. | *Total time* | *26:00* |
  634. |--------------+---------|
  635. | [[Foo][Foo]] | 26:00 |"
  636. (org-test-with-temp-text
  637. "* Foo [1/2]
  638. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  639. (test-org-clock-clocktable-contents ":link t"))))
  640. ;; Replace links with their description, or turn them into plain
  641. ;; links if there is no description.
  642. (should
  643. (equal
  644. "| Headline | Time |
  645. |-----------------------------------------+---------|
  646. | *Total time* | *26:00* |
  647. |-----------------------------------------+---------|
  648. | [[Foo [[https://orgmode.org\\][Org mode]\\]][Foo Org mode]] | 26:00 |"
  649. (org-test-with-temp-text
  650. "* Foo [[https://orgmode.org][Org mode]]
  651. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  652. (test-org-clock-clocktable-contents ":link t :lang en"))))
  653. (should
  654. (equal
  655. "| Headline | Time |
  656. |------------------------------+---------|
  657. | *Total time* | *26:00* |
  658. |------------------------------+---------|
  659. | [[Foo [[https://orgmode.org]\\]][Foo https://orgmode.org]] | 26:00 |"
  660. (org-test-with-temp-text
  661. "* Foo [[https://orgmode.org]]
  662. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  663. (test-org-clock-clocktable-contents ":link t :lang en")))))
  664. (ert-deftest test-org-clock/clocktable/compact ()
  665. "Test \":compact\" parameter in Clock table."
  666. ;; With :compact, all headlines are in the same column.
  667. (should
  668. (equal
  669. "| Headline | Time |
  670. |--------------+---------|
  671. | *Total time* | *26:00* |
  672. |--------------+---------|
  673. | Foo | 26:00 |"
  674. (org-test-with-temp-text
  675. "* Foo
  676. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  677. (test-org-clock-clocktable-contents ":compact t"))))
  678. (should
  679. (equal
  680. "| Headline | Time |
  681. |--------------+---------|
  682. | *Total time* | *52:00* |
  683. |--------------+---------|
  684. | Foo | 52:00 |
  685. | \\_ Bar | 26:00 |"
  686. (org-test-with-temp-text
  687. "* Foo
  688. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  689. ** Bar
  690. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  691. (test-org-clock-clocktable-contents ":compact t"))))
  692. ;; :maxlevel does not affect :compact parameter.
  693. (should
  694. (equal
  695. "| Headline | Time |
  696. |--------------+---------|
  697. | *Total time* | *52:00* |
  698. |--------------+---------|
  699. | Foo | 52:00 |
  700. | \\_ Bar | 26:00 |"
  701. (org-test-with-temp-text
  702. "* Foo
  703. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  704. ** Bar
  705. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  706. (test-org-clock-clocktable-contents ":compact t :maxlevel 2"))))
  707. ;; :compact implies a non-nil :indent parameter.
  708. (should
  709. (equal
  710. "| Headline | Time |
  711. |--------------+---------|
  712. | *Total time* | *52:00* |
  713. |--------------+---------|
  714. | Foo | 52:00 |
  715. | \\_ Bar | 26:00 |"
  716. (org-test-with-temp-text
  717. "* Foo
  718. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  719. ** Bar
  720. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  721. (test-org-clock-clocktable-contents ":compact t :indent nil"))))
  722. ;; :compact implies a nil :level parameter.
  723. (should
  724. (equal
  725. "| Headline | Time |
  726. |--------------+---------|
  727. | *Total time* | *52:00* |
  728. |--------------+---------|
  729. | Foo | 52:00 |
  730. | \\_ Bar | 26:00 |"
  731. (org-test-with-temp-text
  732. "* Foo
  733. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  734. ** Bar
  735. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  736. (test-org-clock-clocktable-contents ":compact t :level t")))))
  737. (ert-deftest test-org-clock/clocktable/properties ()
  738. "Test \":properties\" parameter in Clock table."
  739. ;; Include a new column with list properties.
  740. (should
  741. (equal
  742. "| A | Headline | Time |
  743. |---+--------------+---------|
  744. | | *Total time* | *26:00* |
  745. |---+--------------+---------|
  746. | 1 | Foo | 26:00 |"
  747. (org-test-with-temp-text
  748. "* Foo
  749. :PROPERTIES:
  750. :A: 1
  751. :END:
  752. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  753. (test-org-clock-clocktable-contents ":properties (\"A\")"))))
  754. (should
  755. (equal
  756. "| A | Headline | Time | |
  757. |---+--------------+---------+-------|
  758. | | *Total time* | *52:00* | |
  759. |---+--------------+---------+-------|
  760. | | Foo | 52:00 | |
  761. | 1 | \\_ Bar | | 26:00 |"
  762. (org-test-with-temp-text
  763. "* Foo
  764. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  765. ** Bar
  766. :PROPERTIES:
  767. :A: 1
  768. :END:
  769. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  770. (test-org-clock-clocktable-contents ":properties (\"A\")"))))
  771. ;; Handle missing properties.
  772. (should
  773. (equal
  774. "| A | Headline | Time |
  775. |---+--------------+---------|
  776. | | *Total time* | *26:00* |
  777. |---+--------------+---------|
  778. | 1 | Foo | 26:00 |"
  779. (org-test-with-temp-text
  780. "* Foo
  781. :PROPERTIES:
  782. :A: 1
  783. :END:
  784. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  785. (test-org-clock-clocktable-contents ":properties (\"A\")")))))
  786. (ert-deftest test-org-clock/clocktable/tcolumns ()
  787. "Test \":tcolumns\" parameter in Clock table."
  788. ;; When :tcolumns is smaller than the deepest headline level, lump
  789. ;; lower levels in the last column.
  790. (should
  791. (equal
  792. "| Headline | Time |
  793. |--------------+---------|
  794. | *Total time* | *52:00* |
  795. |--------------+---------|
  796. | Foo | 52:00 |
  797. | \\_ Bar | 26:00 |"
  798. (org-test-with-temp-text
  799. "* Foo
  800. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  801. ** Bar
  802. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  803. (test-org-clock-clocktable-contents ":tcolumns 1"))))
  804. ;; :tcolumns cannot create more columns than the deepest headline
  805. ;; level.
  806. (should
  807. (equal
  808. "| Headline | Time | |
  809. |--------------+---------+-------|
  810. | *Total time* | *52:00* | |
  811. |--------------+---------+-------|
  812. | Foo | 52:00 | |
  813. | \\_ Bar | | 26:00 |"
  814. (org-test-with-temp-text
  815. "* Foo
  816. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  817. ** Bar
  818. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  819. (test-org-clock-clocktable-contents ":tcolumns 3"))))
  820. ;; Pathological case: when no headline contributes to the total
  821. ;; time, there is only one time column.
  822. (should
  823. (equal "| Headline | Time |
  824. |--------------+--------|
  825. | *Total time* | *0:00* |"
  826. (org-test-with-temp-text
  827. "* Foo
  828. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 11:09] => 0:00
  829. ** Bar
  830. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 13:09] => 0:00"
  831. (test-org-clock-clocktable-contents ":tcolumns 2")))))
  832. (ert-deftest test-org-clock/clocktable/step ()
  833. "Test \":step\" parameter in Clock table."
  834. ;; Regression test: week crossing month boundary before :wstart
  835. ;; day-of-week.
  836. (should
  837. (equal "
  838. Weekly report starting on: [2017-09-25 Mon]
  839. | Headline | Time |
  840. |--------------+--------|
  841. | *Total time* | *1:00* |
  842. |--------------+--------|
  843. | Foo | 1:00 |"
  844. (org-test-with-temp-text
  845. "* Foo
  846. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  847. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
  848. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00"
  849. (let ((system-time-locale "en_US"))
  850. (test-org-clock-clocktable-contents
  851. ":step week :block 2017-09 :stepskip0 t")))))
  852. (should
  853. (equal "
  854. Weekly report starting on: [2017-10-01 Sun]
  855. | Headline | Time |
  856. |--------------+--------|
  857. | *Total time* | *2:00* |
  858. |--------------+--------|
  859. | Foo | 2:00 |
  860. Weekly report starting on: [2017-10-02 Mon]
  861. | Headline | Time |
  862. |--------------+--------|
  863. | *Total time* | *7:00* |
  864. |--------------+--------|
  865. | Foo | 7:00 |
  866. Weekly report starting on: [2017-10-09 Mon]
  867. | Headline | Time |
  868. |--------------+--------|
  869. | *Total time* | *5:00* |
  870. |--------------+--------|
  871. | Foo | 5:00 |
  872. "
  873. (org-test-with-temp-text
  874. "* Foo
  875. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  876. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
  877. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00
  878. CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] => 4:00
  879. CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] => 5:00"
  880. (let ((system-time-locale "en_US"))
  881. (test-org-clock-clocktable-contents
  882. ":step week :block 2017-10 :stepskip0 t")))))
  883. ;; :step day
  884. (should
  885. (equal "
  886. Daily report: [2017-10-02 Mon]
  887. | Headline | Time |
  888. |--------------+--------|
  889. | *Total time* | *3:00* |
  890. |--------------+--------|
  891. | Foo | 3:00 |
  892. Daily report: [2017-10-03 Tue]
  893. | Headline | Time |
  894. |--------------+--------|
  895. | *Total time* | *0:00* |
  896. Daily report: [2017-10-04 Wed]
  897. | Headline | Time |
  898. |--------------+--------|
  899. | *Total time* | *0:00* |
  900. Daily report: [2017-10-05 Thu]
  901. | Headline | Time |
  902. |--------------+--------|
  903. | *Total time* | *0:00* |
  904. Daily report: [2017-10-06 Fri]
  905. | Headline | Time |
  906. |--------------+--------|
  907. | *Total time* | *0:00* |
  908. Daily report: [2017-10-07 Sat]
  909. | Headline | Time |
  910. |--------------+--------|
  911. | *Total time* | *0:00* |
  912. Daily report: [2017-10-08 Sun]
  913. | Headline | Time |
  914. |--------------+--------|
  915. | *Total time* | *4:00* |
  916. |--------------+--------|
  917. | Foo | 4:00 |"
  918. (org-test-with-temp-text
  919. "* Foo
  920. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  921. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00
  922. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] => 3:00
  923. CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] => 4:00
  924. CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] => 5:00"
  925. (let ((system-time-locale "en_US"))
  926. (test-org-clock-clocktable-contents
  927. ":step day :block 2017-W40")))))
  928. ;; Regression test: take :tstart and :tend hours into consideration.
  929. (should
  930. (equal "
  931. Weekly report starting on: [2017-12-25 Mon]
  932. | Headline | Time |
  933. |--------------+--------|
  934. | *Total time* | *8:00* |
  935. |--------------+--------|
  936. | Foo | 8:00 |"
  937. (org-test-with-temp-text
  938. "* Foo
  939. CLOCK: [2017-12-27 Wed 08:00]--[2017-12-27 Wed 16:00] => 8:00"
  940. (let ((system-time-locale "en_US"))
  941. (test-org-clock-clocktable-contents
  942. (concat ":step week :tstart \"<2017-12-25 Mon>\" "
  943. ":tend \"<2017-12-27 Wed 23:59>\""))))))
  944. (should
  945. (equal "
  946. Daily report: [2017-12-27 Wed]
  947. | Headline | Time |
  948. |--------------+--------|
  949. | *Total time* | *8:00* |
  950. |--------------+--------|
  951. | Foo | 8:00 |"
  952. (org-test-with-temp-text
  953. "* Foo
  954. CLOCK: [2017-12-27 Wed 08:00]--[2017-12-27 Wed 16:00] => 8:00"
  955. (let ((system-time-locale "en_US"))
  956. (test-org-clock-clocktable-contents
  957. (concat ":step day :tstart \"<2017-12-25 Mon>\" "
  958. ":tend \"<2017-12-27 Wed 23:59>\" :stepskip0 t"))))))
  959. ;; Test :step week", without or with ":wstart" parameter.
  960. (should
  961. (equal "
  962. Weekly report starting on: [2012-03-26 Mon]
  963. | Headline | Time |
  964. |--------------+--------|
  965. | *Total time* | *8:00* |
  966. |--------------+--------|
  967. | Foo | 8:00 |
  968. Weekly report starting on: [2012-04-02 Mon]
  969. | Headline | Time |
  970. |--------------+--------|
  971. | *Total time* | *8:00* |
  972. |--------------+--------|
  973. | Foo | 8:00 |
  974. "
  975. (org-test-with-temp-text
  976. "* Foo
  977. CLOCK: [2012-03-29 Thu 08:00]--[2012-03-29 Thu 16:00] => 8:00
  978. CLOCK: [2012-04-03 Thu 08:00]--[2012-04-03 Thu 16:00] => 8:00"
  979. (let ((system-time-locale "en_US"))
  980. (test-org-clock-clocktable-contents
  981. ":step week :block 2012 :stepskip0 t")))))
  982. (should
  983. (equal "
  984. Weekly report starting on: [2012-03-29 Thu]
  985. | Headline | Time |
  986. |--------------+---------|
  987. | *Total time* | *16:00* |
  988. |--------------+---------|
  989. | Foo | 16:00 |
  990. "
  991. (org-test-with-temp-text
  992. "* Foo
  993. CLOCK: [2012-03-29 Thu 08:00]--[2012-03-29 Thu 16:00] => 8:00
  994. CLOCK: [2012-04-03 Thu 08:00]--[2012-04-03 Thu 16:00] => 8:00"
  995. (let ((system-time-locale "en_US"))
  996. (test-org-clock-clocktable-contents
  997. ":step week :wstart 4 :block 2012 :stepskip0 t")))))
  998. ;; Test ":step month" without and with ":mstart".
  999. (should
  1000. (equal "
  1001. Monthly report starting on: [2014-03-01 Sat]
  1002. | Headline | Time |
  1003. |--------------+--------|
  1004. | *Total time* | *8:00* |
  1005. |--------------+--------|
  1006. | Foo | 8:00 |
  1007. Monthly report starting on: [2014-04-01 Tue]
  1008. | Headline | Time |
  1009. |--------------+--------|
  1010. | *Total time* | *8:00* |
  1011. |--------------+--------|
  1012. | Foo | 8:00 |
  1013. "
  1014. (org-test-with-temp-text
  1015. "* Foo
  1016. CLOCK: [2014-03-04 Tue 08:00]--[2014-03-04 Tue 16:00] => 8:00
  1017. CLOCK: [2014-04-03 Thu 08:00]--[2014-04-03 Thu 16:00] => 8:00"
  1018. (let ((system-time-locale "en_US"))
  1019. (test-org-clock-clocktable-contents
  1020. ":step month :block 2014 :stepskip0 t")))))
  1021. (should
  1022. (equal "
  1023. Monthly report starting on: [2014-03-04 Tue]
  1024. | Headline | Time |
  1025. |--------------+---------|
  1026. | *Total time* | *16:00* |
  1027. |--------------+---------|
  1028. | Foo | 16:00 |
  1029. "
  1030. (org-test-with-temp-text
  1031. "* Foo
  1032. CLOCK: [2014-03-04 Tue 08:00]--[2014-03-04 Tue 16:00] => 8:00
  1033. CLOCK: [2014-04-03 Thu 08:00]--[2014-04-03 Thu 16:00] => 8:00"
  1034. (let ((system-time-locale "en_US"))
  1035. (test-org-clock-clocktable-contents
  1036. ":step month :mstart 4 :block 2014 :stepskip0 t")))))
  1037. ;; Test ":step year".
  1038. (should
  1039. (equal "
  1040. Annual report starting on: [2012-01-01 Sun]
  1041. | Headline | Time |
  1042. |--------------+--------|
  1043. | *Total time* | *8:00* |
  1044. |--------------+--------|
  1045. | Foo | 8:00 |
  1046. Annual report starting on: [2014-01-01 Wed]
  1047. | Headline | Time |
  1048. |--------------+--------|
  1049. | *Total time* | *8:00* |
  1050. |--------------+--------|
  1051. | Foo | 8:00 |
  1052. "
  1053. (org-test-with-temp-text
  1054. "* Foo
  1055. CLOCK: [2012-03-29 Thu 08:00]--[2012-03-29 Thu 16:00] => 8:00
  1056. CLOCK: [2014-03-04 Tue 08:00]--[2014-03-04 Tue 16:00] => 8:00"
  1057. (let ((system-time-locale "en_US"))
  1058. (test-org-clock-clocktable-contents
  1059. ":step year :block untilnow :stepskip0 t")))))
  1060. ;; Regression test: Respect DST
  1061. (should
  1062. (equal "
  1063. Daily report: [2018-10-29 Mon]
  1064. | Headline | Time |
  1065. |--------------+--------|
  1066. | *Total time* | *8:00* |
  1067. |--------------+--------|
  1068. | Foo | 8:00 |
  1069. "
  1070. (org-test-with-temp-text
  1071. "* Foo
  1072. CLOCK: [2018-10-29 Mon 08:00]--[2018-10-29 Mon 16:00] => 8:00"
  1073. (let ((system-time-locale "en_US"))
  1074. (test-org-clock-clocktable-contents
  1075. (concat ":step day "
  1076. ":stepskip0 t "
  1077. ":tstart \"2018-10-01\" "
  1078. ":tend \"2018-11-01\"")))))))
  1079. (ert-deftest test-org-clock/clocktable/extend-today-until ()
  1080. "Test assignment of clock time to days in presence of \"org-extend-today-until\"."
  1081. ;; Basic test of :block with org-extend-today-until - the report for
  1082. ;; 2017-09-30 should include the time clocked on 2017-10-01 before
  1083. ;; 04:00.
  1084. (should
  1085. (equal "| Headline | Time |
  1086. |--------------+--------|
  1087. | *Total time* | *2:00* |
  1088. |--------------+--------|
  1089. | Foo | 2:00 |"
  1090. (org-test-with-temp-text
  1091. "* Foo
  1092. CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] => 1:00
  1093. CLOCK: [2017-10-01 Sun 02:00]--[2017-10-01 Sun 03:00] => 1:00
  1094. CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] => 2:00"
  1095. (setq-local org-extend-today-until 4)
  1096. (let ((system-time-locale "en_US"))
  1097. (test-org-clock-clocktable-contents
  1098. ":block 2017-09-30")))))
  1099. ;; Week-length block - time on Monday before 04:00 should be
  1100. ;; assigned to previous week.
  1101. (should
  1102. (equal "
  1103. Weekly report starting on: [2017-10-01 Sun]
  1104. | Headline | Time |
  1105. |--------------+--------|
  1106. | *Total time* | *2:00* |
  1107. |--------------+--------|
  1108. | Foo | 2:00 |
  1109. Weekly report starting on: [2017-10-02 Mon]
  1110. | Headline | Time |
  1111. |--------------+--------|
  1112. | *Total time* | *2:00* |
  1113. |--------------+--------|
  1114. | Foo | 2:00 |
  1115. "
  1116. (org-test-with-temp-text
  1117. "* Foo
  1118. CLOCK: [2017-10-01 Sun 12:00]--[2017-10-01 Sun 13:00] => 1:00
  1119. CLOCK: [2017-10-02 Mon 02:00]--[2017-10-02 Mon 03:00] => 1:00
  1120. CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 13:00] => 2:00"
  1121. (setq-local org-extend-today-until 4)
  1122. (let ((system-time-locale "en_US"))
  1123. (test-org-clock-clocktable-contents
  1124. ":step week :block 2017-10 :stepskip0 t"))))))
  1125. (provide 'test-org-clock)
  1126. ;;; test-org-clock.el end here