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

How to get month in ts-diff #17

Closed
azzamsa opened this issue Sep 4, 2020 · 2 comments
Closed

How to get month in ts-diff #17

azzamsa opened this issue Sep 4, 2020 · 2 comments

Comments

@azzamsa
Copy link

azzamsa commented Sep 4, 2020

I want to write a birthday app in different languages, one of them is Elisp.
The original implementation is written in Python.

The spec is:

  • Given the input of year-month-day. return N years, N months, N days

The original implementation:

#!/usr/bin/env python3

import datetime
from dateutil.relativedelta import relativedelta

current_dt = datetime.datetime.now()
birth_date = datetime.datetime.strptime("1996-11-28", "%Y-%m-%d")
birth_date_formatted = birth_date.strftime("%A, %d %B %Y ")
diff = relativedelta(current_dt, birth_date)

print(f"Your age: {diff.years} years, {diff.months} months, {diff.days} days")

Which will display: Your age: 23 years, 9 months, 7 days

Given the same spec, I try to implement it in Elisp with ts.el:

ELISP> (ts-human-format-duration (ts-diff (ts-now) (ts-parse "1996-11-28")))
"23 years, 286 days, 11 hours, 2 minutes, 52 seconds"

how to get the month out of it, with the days being "9 months, 7 days"?.


I am aware that some time library doesn't return the month as well. Worrying about its flexibility and non-absolute answers. Such is one month: 1) 28 days, 30, or 31.

any opinion on this regarding ts.el?

@alphapapa
Copy link
Owner

The ambiguities you mention would make it difficult to give an accurate answer in terms of months, and accounting for various methods would be complicated, so it hasn't been implemented.

I suppose someone could port the Python relativedelta module to Elisp. If one were to do that, it would probably be best proposed as a patch to Emacs itself.

What do you think? Thanks.

@azzamsa
Copy link
Author

azzamsa commented Sep 7, 2020

Yes, the best thing we have is to dig deeper into https://github.com/dateutil/dateutil.

Rust, and Elisp doesn't have the simmiliar library. I don't check for Go-lang.

@azzamsa azzamsa closed this as completed Sep 7, 2020
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