Skip to content

Commit

Permalink
Upgrade encode-time callsites
Browse files Browse the repository at this point in the history
  • Loading branch information
bcc32 committed Jul 10, 2024
1 parent 1737c03 commit f9ac070
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
14 changes: 7 additions & 7 deletions ledger-complete.el
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ an alist (ACCOUNT-ELEMENT . NODE)."
(month (and month-string
(string-to-number month-string)))
(day (string-to-number day-string))
(dates (list (encode-time 0 0 0 day (or month this-month) this-year)
(dates (list (encode-time (list 0 0 0 day (or month this-month) this-year))
(if month
(encode-time 0 0 0 day month last-year)
(encode-time 0 0 0 day last-month last-month-year)))))
(encode-time (list 0 0 0 day month last-year))
(encode-time (list 0 0 0 day last-month last-month-year))))))
(let ((collection
(list (concat (ledger-format-date
(cl-find-if (lambda (date) (not (time-less-p now date))) dates))
Expand All @@ -257,17 +257,17 @@ an alist (ACCOUNT-ELEMENT . NODE)."
(let* ((tx-year (string-to-number tx-year-string))
(tx-month (string-to-number tx-month-string))
(tx-day (string-to-number tx-day-string))
(tx-date (encode-time 0 0 0 tx-day tx-month tx-year))
(tx-date (encode-time (list 0 0 0 tx-day tx-month tx-year)))
(next-month (if (< tx-month 12) (1+ tx-month) 1))
(next-year (1+ tx-year))
(next-month-year (if (< tx-month 12) tx-year next-year))
(month (and month-string
(string-to-number month-string)))
(day (string-to-number day-string))
(dates (list (encode-time 0 0 0 day (or month tx-month) tx-year)
(dates (list (encode-time (list 0 0 0 day (or month tx-month) tx-year))
(if month
(encode-time 0 0 0 day month next-year)
(encode-time 0 0 0 day next-month next-month-year)))))
(encode-time (list 0 0 0 day month next-year))
(encode-time (list 0 0 0 day next-month next-month-year))))))
(let ((collection
(list (concat (ledger-format-date
(cl-find-if (lambda (date) (not (time-less-p date tx-date))) dates))
Expand Down
12 changes: 6 additions & 6 deletions ledger-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ which part of the date string point is in."
;; automatically inferred from the other arguments, since the
;; appropriate DST value may differ from `time-old'.
(encode-time
0 ; second
0 ; minute
0 ; hour
(+ (if (eq date-cat 'day) n 0) (nth 3 time-old))
(+ (if (eq date-cat 'month) n 0) (nth 4 time-old))
(+ (if (eq date-cat 'year) n 0) (nth 5 time-old)))))
(list 0 ; second
0 ; minute
0 ; hour
(+ (if (eq date-cat 'day) n 0) (nth 3 time-old))
(+ (if (eq date-cat 'month) n 0) (nth 4 time-old))
(+ (if (eq date-cat 'year) n 0) (nth 5 time-old))))))
(replace-match (format-time-string (concat "%Y" date-separator "%m" date-separator "%d")
time-new)
'fixedcase
Expand Down
2 changes: 1 addition & 1 deletion ledger-schedule.el
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ date descriptor."
(string-match "[A-Za-z]" (cadr day-parts)))))
(day-of-week (ledger-schedule-encode-day-of-week
(substring (cadr day-parts) (string-match "[A-Za-z]" (cadr day-parts))))))
(ledger-schedule-constrain-every-count-day day-of-week increment (encode-time 0 0 0 base-day (car months) (car years))))
(ledger-schedule-constrain-every-count-day day-of-week increment (encode-time (list 0 0 0 base-day (car months) (car years)))))
(let ((count (string-to-number (substring (car day-parts) 0 1)))
(day-of-week (ledger-schedule-encode-day-of-week
(substring (car day-parts) (string-match "[A-Za-z]" (car day-parts))))))
Expand Down
12 changes: 6 additions & 6 deletions ledger-xact.el
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ MOMENT is an encoded date"
(if (and year (> (length year) 0))
(setq year (string-to-number year)))
(funcall callback start
;; TODO: upgrade all callsites
(encode-time 0 0 0 day month
(or year current-year))
(encode-time (list 0 0 0 day month
(or year current-year)))
state payee))))
(forward-line))))

Expand Down Expand Up @@ -184,9 +183,10 @@ Leave point on the first amount, if any, otherwise the first account."
"Try to parse DATE using `ledger-iso-date-regexp' and return a time value or nil."
(save-match-data
(when (string-match ledger-iso-date-regexp date)
(encode-time 0 0 0 (string-to-number (match-string 4 date))
(string-to-number (match-string 3 date))
(string-to-number (match-string 2 date))))))
(encode-time (list 0 0 0
(string-to-number (match-string 4 date))
(string-to-number (match-string 3 date))
(string-to-number (match-string 2 date)))))))

(defun ledger-add-transaction (transaction-text &optional insert-at-point)
"Use ledger xact TRANSACTION-TEXT to add a transaction to the buffer.
Expand Down
42 changes: 21 additions & 21 deletions test/complete-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,16 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=252"
"https://github.com/ledger/ledger-mode/issues/181"
:tags '(complete regress)
(ledger-tests-with-temp-file
"2019/06/28 Foobar
"2019/06/28 Foobar
Expenses:Baz 11.99 CAD
Assets:Cash
2019/06/20 Foo"
(goto-char (point-max))
(call-interactively 'completion-at-point)
(should
(equal (buffer-string)
"2019/06/28 Foobar
(goto-char (point-max))
(call-interactively 'completion-at-point)
(should
(equal (buffer-string)
"2019/06/28 Foobar
Expenses:Baz 11.99 CAD
Assets:Cash
Expand All @@ -185,13 +185,13 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=252"
"https://github.com/ledger/ledger-mode/issues/181"
:tags '(complete)
(ledger-tests-with-temp-file
"payee Foobar
"payee Foobar
2019/06/28 F"
(goto-char (point-max))
(call-interactively 'completion-at-point)
(should
(equal (buffer-string)
"payee Foobar
(goto-char (point-max))
(call-interactively 'completion-at-point)
(should
(equal (buffer-string)
"payee Foobar
2019/06/28 Foobar"))))

(eval-when-compile
Expand All @@ -203,16 +203,16 @@ http://bugs.ledger-cli.org/show_bug.cgi?id=252"
https://github.com/ledger/ledger-mode/issues/420"
:tags '(complete regress)
(ledger-tests-with-temp-file
"payee Foo Bar
"payee Foo Bar
payee Bar Baz
2019/06/28 Foo B"
(goto-char (point-max))
(let ((inhibit-interaction t)) ;require a unique match
(completion-at-point))
(should
(equal (buffer-string)
"payee Foo Bar
(goto-char (point-max))
(let ((inhibit-interaction t)) ;require a unique match
(completion-at-point))
(should
(equal (buffer-string)
"payee Foo Bar
payee Bar Baz
2019/06/28 Foo Bar"))))
Expand Down Expand Up @@ -372,7 +372,7 @@ account Expenses:Groceries
https://github.com/ledger/ledger-mode/issues/419"
:tags '(complete regress)
(let ((ledger-complete--current-time-for-testing ;2024-01-21
(encode-time 0 0 0 21 1 2024))
(encode-time '(0 0 0 21 1 2024)))
(ledger-default-date-format ledger-iso-date-format))
(ledger-tests-with-temp-file
"01-19"
Expand All @@ -394,7 +394,7 @@ https://github.com/ledger/ledger-mode/issues/419"
https://github.com/ledger/ledger-mode/issues/419"
:tags '(complete regress)
(let ((ledger-complete--current-time-for-testing ;2024-01-21
(encode-time 0 0 0 21 1 2024))
(encode-time '(0 0 0 21 1 2024)))
(ledger-default-date-format ledger-iso-date-format))
(ledger-tests-with-temp-file
"19"
Expand Down

0 comments on commit f9ac070

Please sign in to comment.