Skip to content

Wrong Streak Record Date calculation #14

Description

@diegoVom

Hi,

I found that the Streak Record Date is not correctly calculated. To get it to work properly I had to apply the following patch in the function org-habit-stats--record-streak-full (see the comments in the code snippet):

(defun org-habit-stats--record-streak-full (history _history-rev _habit-data)
  (let ((record-streak 0)
        (record-day (org-today))
        (curr-streak 0)
        (curr-streak-start 0))
    (while history
      (let* ((next-pair (pop history))
             (curr-day (car next-pair))
             (curr-completed (cdr next-pair)))
        (if (= curr-completed 1)
            (progn
              (when (= curr-streak 0)
                (setq curr-streak-start curr-day))
              (setq curr-streak (1+ curr-streak)))
          (setq curr-streak 0))
        (when (> curr-streak record-streak)
          (setq record-streak curr-streak)
          ;; The patch consists in 1st adding this line            
          (setq record-day curr-day)
          ;; Then removing this one              
          ;; (setq record-day (+ curr-streak-start curr-streak -1))
          )))
    (cons record-streak record-day)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions