Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Q/FR] Support for relative dates #4

Open
Fuco1 opened this issue Feb 26, 2019 · 3 comments
Open

[Q/FR] Support for relative dates #4

Fuco1 opened this issue Feb 26, 2019 · 3 comments
Milestone

Comments

@Fuco1
Copy link

Fuco1 commented Feb 26, 2019

Do you plan to support relative dates with a human readable instructions, like "last year" or "next month"... I would like to have something to parse these relative to today (or an argument passed in). But also it should understand input such as "2018" or "jan 2018" to give the specified intervals.

My current use-case is to make better reports for org-clock-budget where you could specify the intervals/periods with a simple query such as "last year" or "this week" and it will give you a report. This way users can view historical reports as well as the current ones.

It feels like it might be a separate package, "period" or something for returning the intervals specified by the query.

Edit: the inspiration comes from ledger https://github.com/ledger/ledger/blob/7c0ae5b02571e21f97d45f5d091cb78af9885713/src/times.cc and how it handles relative times. Maybe I will try to port it using ts as a backend.

@alphapapa
Copy link
Owner

alphapapa commented Mar 2, 2019 via email

@alphapapa
Copy link
Owner

@Fuco1 FYI, I just updated this package, fixing all warnings, adding tests, adding docs, and submitting to MELPA. Please let me know if you have any feedback.

@alphapapa
Copy link
Owner

alphapapa commented Aug 8, 2019

I think it may be possible to support this without implementing plain-language parsing. For example, the example added in e3e32eb shows a simple function that returns the timestamps at the beginning and end of the week containing a given timestamp. It would be easy to have similar functions for week-start, year-end, etc, and compose those into "last year," "last week," etc. Year start/end would be very easy with ts-apply, since the dates and times are always the same. Something like:

(defun ts-year-span (ts)
  (let* ((beg (ts-apply :month 1 :day 1 :hour 0 :minute 0 :second 0 ts))
         (end (ts-apply :month 12 :day 31 :hour 23 :minute 59 :second 59 ts)))
    (cons beg end)))

(-let (((beg . end) (ts-year-span (ts-now))))
  (cons (ts-format beg)
        (ts-format end)))
;;=> ("2019-01-01 00:00:00 -0600" . "2019-12-31 23:59:59 -0600")

@alphapapa alphapapa added this to the Future milestone Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants