Skip to content

Commit ae1db7d

Browse files
maxnikulinyantar92
authored andcommitted
Use `org-encode-time' helper macro
* lisp/ol.el (org-store-link): * lisp/org-agenda.el (org-agenda-get-timestamps) (org-agenda-get-progress, agenda-bulk-action): * lisp/org-capture.el (org-capture-fill-template): * lisp/org-clock.el (org-clock-get-sum-start) (org-clock-special-range, org-clocktable-shift) (org-clocktable-steps): * lisp/org-colview.el (org-colview-construct-allowed-dates): * lisp/org-datetree.el (org-datetree-find-iso-week-create) (org-datetree-insert-line): * lisp/org-element.el (org-element-timestamp-interpreter): * lisp/org-macro.el (org-macro--vc-modified-time): * lisp/org-macs.el (org-matcher-time): * lisp/org.el (org-current-time, org-current-effective-time) (org-add-planning-info, org-read-date, org-read-date-display) (org-read-date-analyze, org-eval-in-calendar) (org-calendar-select, org-display-custom-time) (org-calendar-select-mouse, org-time-string-to-time) (org-time-from-absolute, org-at-clock-log-p) (org-date-from-calendar, org-get-cursor-date) (org-timestamp-to-time): * testing/lisp/test-org-clock.el (org-test-clock-create-timestamp): * lisp/ox-icalendar.el (org-icalendar-convert-timestamp): Avoid direct calls of `encode-time', use `org-encode-time' instead. Org supports Emacs-26, but the recommended way to call `encode-time' changed in Emacs-27. In Emacs-29 DST and TZ elements of the single list arguments became optional. In Org it is still convenient to call the function with separate arguments without explicit DST and TZ arguments. The `org-encode-time' should mitigate attempts to modernize Org code directly in the Emacs repository.
1 parent 8908a1b commit ae1db7d

File tree

12 files changed

+108
-100
lines changed

12 files changed

+108
-100
lines changed

lisp/ol.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ non-nil."
16181618
(setq link
16191619
(format-time-string
16201620
(car org-time-stamp-formats)
1621-
(encode-time 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd))))
1621+
(org-encode-time 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd))))
16221622
(org-link-store-props :type "calendar" :date cd)))
16231623

16241624
((eq major-mode 'w3-mode)

lisp/org-agenda.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5758,7 +5758,7 @@ displayed in agenda view."
57585758
(substring
57595759
(format-time-string
57605760
(car org-time-stamp-formats)
5761-
(encode-time ; DATE bound by calendar
5761+
(org-encode-time ; DATE bound by calendar
57625762
0 0 0 (nth 1 date) (car date) (nth 2 date)))
57635763
1 11))
57645764
"\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
@@ -6030,7 +6030,7 @@ then those holidays will be skipped."
60306030
(substring
60316031
(format-time-string
60326032
(car org-time-stamp-formats)
6033-
(encode-time ; DATE bound by calendar
6033+
(org-encode-time ; DATE bound by calendar
60346034
0 0 0 (nth 1 date) (car date) (nth 2 date)))
60356035
1 11))))
60366036
(org-agenda-search-headline-for-time nil)
@@ -11119,8 +11119,8 @@ The prefix arg is passed through to the command if possible."
1111911119
(ignore-errors
1112011120
(let* ((date (calendar-gregorian-from-absolute
1112111121
(+ (org-today) distance)))
11122-
(time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
11123-
(nth 2 date))))
11122+
(time (org-encode-time
11123+
0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
1112411124
(org-agenda-schedule nil time))))))))
1112511125

1112611126
(?f

lisp/org-capture.el

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,10 @@ Store them in the capture property list."
10521052
prompt-time
10531053
;; Use 00:00 when no time is given for another
10541054
;; date than today?
1055-
(apply #'encode-time 0 0
1056-
org-extend-today-until
1057-
(cl-cdddr (decode-time prompt-time)))))
1055+
(org-encode-time
1056+
(apply #'list
1057+
0 0 org-extend-today-until
1058+
(cl-cdddr (decode-time prompt-time))))))
10581059
(time-to-days prompt-time)))
10591060
(t
10601061
;; Current date, possibly corrected for late night
@@ -1583,7 +1584,7 @@ Expansion occurs in a temporary Org mode buffer."
15831584
(time (let* ((c (or (org-capture-get :default-time) (current-time)))
15841585
(d (decode-time c)))
15851586
(if (< (nth 2 d) org-extend-today-until)
1586-
(encode-time 0 59 23 (1- (nth 3 d)) (nth 4 d) (nth 5 d))
1587+
(org-encode-time 0 59 23 (1- (nth 3 d)) (nth 4 d) (nth 5 d))
15871588
c)))
15881589
(v-t (format-time-string (org-time-stamp-format nil) time))
15891590
(v-T (format-time-string (org-time-stamp-format t) time))

lisp/org-clock.el

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ The time is always returned as UTC."
15191519
(day (nth 3 dt)))
15201520
(if (< hour org-extend-today-until) (setf (nth 3 dt) (1- day)))
15211521
(setf (nth 2 dt) org-extend-today-until)
1522-
(apply #'encode-time 0 0 (nthcdr 2 dt))))
1522+
(org-encode-time (apply #'list 0 0 (nthcdr 2 dt)))))
15231523
((or (equal cmt "all")
15241524
(and (or (not cmt) (equal cmt "auto"))
15251525
(not lr)))
@@ -2352,16 +2352,16 @@ have priority."
23522352
(let* ((start (pcase key
23532353
(`interactive (org-read-date nil t nil "Range start? "))
23542354
(`untilnow nil)
2355-
(_ (encode-time 0 m h d month y))))
2355+
(_ (org-encode-time 0 m h d month y))))
23562356
(end (pcase key
23572357
(`interactive (org-read-date nil t nil "Range end? "))
23582358
(`untilnow (current-time))
2359-
(_ (encode-time 0
2360-
m ;; (or m1 m)
2361-
(or h1 h)
2362-
(or d1 d)
2363-
(or month1 month)
2364-
(or y1 y)))))
2359+
(_ (org-encode-time 0
2360+
m ;; (or m1 m)
2361+
(or h1 h)
2362+
(or d1 d)
2363+
(or month1 month)
2364+
(or y1 y)))))
23652365
(text
23662366
(pcase key
23672367
((or `day `today) (format-time-string "%A, %B %d, %Y" start))
@@ -2429,14 +2429,14 @@ the currently selected interval size."
24292429
(cond
24302430
(d (setq ins (format-time-string
24312431
"%Y-%m-%d"
2432-
(encode-time 0 0 0 (+ d n) nil y)))) ;; m
2432+
(org-encode-time 0 0 0 (+ d n) nil y)))) ;; m
24332433
((and wp (string-match "w\\|W" wp) mw (> (length wp) 0))
24342434
(require 'cal-iso)
24352435
(setq date (calendar-gregorian-from-absolute
24362436
(calendar-iso-to-absolute (list (+ mw n) 1 y))))
24372437
(setq ins (format-time-string
24382438
"%G-W%V"
2439-
(encode-time 0 0 0 (nth 1 date) (car date) (nth 2 date)))))
2439+
(org-encode-time 0 0 0 (nth 1 date) (car date) (nth 2 date)))))
24402440
((and wp (string-match "q\\|Q" wp) mw (> (length wp) 0))
24412441
(require 'cal-iso)
24422442
; if the 4th + 1 quarter is requested we flip to the 1st quarter of the next year
@@ -2453,11 +2453,11 @@ the currently selected interval size."
24532453
(calendar-iso-to-absolute (org-quarter-to-date (+ mw n) y))))
24542454
(setq ins (format-time-string
24552455
(concat (number-to-string y) "-Q" (number-to-string (+ mw n)))
2456-
(encode-time 0 0 0 (nth 1 date) (car date) (nth 2 date)))))
2456+
(org-encode-time 0 0 0 (nth 1 date) (car date) (nth 2 date)))))
24572457
(mw
24582458
(setq ins (format-time-string
24592459
"%Y-%m"
2460-
(encode-time 0 0 0 1 (+ mw n) y))))
2460+
(org-encode-time 0 0 0 1 (+ mw n) y))))
24612461
(y
24622462
(setq ins (number-to-string (+ y n))))))
24632463
(t (user-error "Cannot shift clocktable block")))
@@ -2845,7 +2845,7 @@ a number of clock tables."
28452845
(pcase (if range (car range) (plist-get params :tstart))
28462846
((and (pred numberp) n)
28472847
(pcase-let ((`(,m ,d ,y) (calendar-gregorian-from-absolute n)))
2848-
(apply #'encode-time (list 0 0 org-extend-today-until d m y))))
2848+
(org-encode-time 0 0 org-extend-today-until d m y)))
28492849
(timestamp
28502850
(seconds-to-time
28512851
(org-matcher-time (or timestamp
@@ -2855,7 +2855,7 @@ a number of clock tables."
28552855
(pcase (if range (nth 1 range) (plist-get params :tend))
28562856
((and (pred numberp) n)
28572857
(pcase-let ((`(,m ,d ,y) (calendar-gregorian-from-absolute n)))
2858-
(apply #'encode-time (list 0 0 org-extend-today-until d m y))))
2858+
(org-encode-time 0 0 org-extend-today-until d m y)))
28592859
(timestamp (seconds-to-time (org-matcher-time timestamp))))))
28602860
(while (time-less-p start end)
28612861
(unless (bolp) (insert "\n"))
@@ -2867,20 +2867,21 @@ a number of clock tables."
28672867
;; Compute NEXT, which is the end of the current clock table,
28682868
;; according to step.
28692869
(let* ((next
2870-
(apply #'encode-time
2871-
(pcase-let
2872-
((`(,_ ,_ ,_ ,d ,m ,y ,dow . ,_) (decode-time start)))
2873-
(pcase step
2874-
(`day (list 0 0 org-extend-today-until (1+ d) m y))
2875-
(`week
2876-
(let ((offset (if (= dow week-start) 7
2877-
(mod (- week-start dow) 7))))
2878-
(list 0 0 org-extend-today-until (+ d offset) m y)))
2879-
(`semimonth (list 0 0 0
2880-
(if (< d 16) 16 1)
2881-
(if (< d 16) m (1+ m)) y))
2882-
(`month (list 0 0 0 month-start (1+ m) y))
2883-
(`year (list 0 0 org-extend-today-until 1 1 (1+ y)))))))
2870+
;; In Emacs-27 and Emacs-28 `encode-time' does not support 6 elements
2871+
;; list argument so `org-encode-time' can not be outside of `pcase'.
2872+
(pcase-let
2873+
((`(,_ ,_ ,_ ,d ,m ,y ,dow . ,_) (decode-time start)))
2874+
(pcase step
2875+
(`day (org-encode-time 0 0 org-extend-today-until (1+ d) m y))
2876+
(`week
2877+
(let ((offset (if (= dow week-start) 7
2878+
(mod (- week-start dow) 7))))
2879+
(org-encode-time 0 0 org-extend-today-until (+ d offset) m y)))
2880+
(`semimonth (org-encode-time 0 0 0
2881+
(if (< d 16) 16 1)
2882+
(if (< d 16) m (1+ m)) y))
2883+
(`month (org-encode-time 0 0 0 month-start (1+ m) y))
2884+
(`year (org-encode-time 0 0 org-extend-today-until 1 1 (1+ y))))))
28842885
(table-begin (line-beginning-position 0))
28852886
(step-time
28862887
;; Write clock table between START and NEXT.

lisp/org-colview.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ around it."
783783
(setq time-after (copy-sequence time))
784784
(setf (nth 3 time-before) (1- (nth 3 time)))
785785
(setf (nth 3 time-after) (1+ (nth 3 time)))
786-
(mapcar (lambda (x) (format-time-string fmt (apply #'encode-time x)))
786+
(mapcar (lambda (x) (format-time-string fmt (org-encode-time x)))
787787
(list time-before time time-after)))))
788788

789789
(defun org-columns-open-link (&optional arg)

lisp/org-datetree.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ will be built under the headline at point."
137137
(let* ((year (calendar-extract-year d))
138138
(month (calendar-extract-month d))
139139
(day (calendar-extract-day d))
140-
(time (encode-time 0 0 0 day month year))
140+
(time (org-encode-time 0 0 0 day month year))
141141
(iso-date (calendar-iso-from-absolute
142142
(calendar-absolute-from-gregorian d)))
143143
(weekyear (nth 2 iso-date))
@@ -197,14 +197,14 @@ inserted into the buffer."
197197
(when month
198198
(insert
199199
(if day
200-
(format-time-string "-%m-%d %A" (encode-time 0 0 0 day month year))
201-
(format-time-string "-%m %B" (encode-time 0 0 0 1 month year))))))
200+
(format-time-string "-%m-%d %A" (org-encode-time 0 0 0 day month year))
201+
(format-time-string "-%m %B" (org-encode-time 0 0 0 1 month year))))))
202202
(when (and day org-datetree-add-timestamp)
203203
(save-excursion
204204
(insert "\n")
205205
(org-indent-line)
206206
(org-insert-time-stamp
207-
(encode-time 0 0 0 day month year)
207+
(org-encode-time 0 0 0 day month year)
208208
nil
209209
(eq org-datetree-add-timestamp 'inactive))))
210210
(beginning-of-line))

lisp/org-element.el

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4046,12 +4046,12 @@ Assume point is at the beginning of the timestamp."
40464046
(/= minute-start minute-end)))))
40474047
(funcall
40484048
build-ts-string
4049-
(encode-time 0
4050-
(or minute-start 0)
4051-
(or hour-start 0)
4052-
(org-element-property :day-start timestamp)
4053-
(org-element-property :month-start timestamp)
4054-
(org-element-property :year-start timestamp))
4049+
(org-encode-time 0
4050+
(or minute-start 0)
4051+
(or hour-start 0)
4052+
(org-element-property :day-start timestamp)
4053+
(org-element-property :month-start timestamp)
4054+
(org-element-property :year-start timestamp))
40554055
(eq type 'active)
40564056
(and hour-start minute-start)
40574057
(and time-range-p hour-end)
@@ -4063,7 +4063,7 @@ Assume point is at the beginning of the timestamp."
40634063
(hour-end (org-element-property :hour-end timestamp)))
40644064
(concat
40654065
(funcall
4066-
build-ts-string (encode-time
4066+
build-ts-string (org-encode-time
40674067
0
40684068
(or minute-start 0)
40694069
(or hour-start 0)
@@ -4074,12 +4074,13 @@ Assume point is at the beginning of the timestamp."
40744074
(and hour-start minute-start))
40754075
"--"
40764076
(funcall build-ts-string
4077-
(encode-time 0
4078-
(or minute-end 0)
4079-
(or hour-end 0)
4080-
(org-element-property :day-end timestamp)
4081-
(org-element-property :month-end timestamp)
4082-
(org-element-property :year-end timestamp))
4077+
(org-encode-time
4078+
0
4079+
(or minute-end 0)
4080+
(or hour-end 0)
4081+
(org-element-property :day-end timestamp)
4082+
(org-element-property :month-end timestamp)
4083+
(org-element-property :year-end timestamp))
40834084
(eq type 'active-range)
40844085
(and hour-end minute-end)))))
40854086
(_ (org-element-property :raw-value timestamp)))))

lisp/org-macro.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ Return value as a string."
387387
(buffer-substring
388388
(point) (line-end-position)))))
389389
(when (cl-some #'identity time)
390-
(setq date (apply #'encode-time time))))))))
390+
(setq date (org-encode-time time))))))))
391391
(let ((proc (get-buffer-process buf)))
392392
(while (and proc (accept-process-output proc .5 nil t)))))
393393
(kill-buffer buf))

lisp/org-macs.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,8 +1460,8 @@ following special strings: \"<now>\", \"<today>\",
14601460
\"<tomorrow>\", and \"<yesterday>\".
14611461

14621462
Return 0. if S is not recognized as a valid value."
1463-
(let ((today (float-time (apply #'encode-time
1464-
(append '(0 0 0) (nthcdr 3 (decode-time)))))))
1463+
(let ((today (float-time (org-encode-time
1464+
(append '(0 0 0) (nthcdr 3 (decode-time)))))))
14651465
(save-match-data
14661466
(cond
14671467
((string= s "<now>") (float-time))

0 commit comments

Comments
 (0)