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

Filling dates with zeroes, and some other difficulties #11

Closed
contrapunctus-1 opened this issue May 16, 2020 · 2 comments
Closed

Filling dates with zeroes, and some other difficulties #11

contrapunctus-1 opened this issue May 16, 2020 · 2 comments

Comments

@contrapunctus-1
Copy link

Hi, thanks a lot for making ts.el. After writing so much haphazard, ad hoc date and time conversion code for Chronometrist, I was delighted to discover this library, with a great interface for conversion, very similar to a library I was planning to write myself.

Sadly, when I got around to using it, I ran into some showstoppers -

  1. (make-struct :year 2020 :month 1 :day 1) does not create a value for :unix. Which means I have to fill zeros for hours, minutes, and seconds.
  2. Calling ts-update on a timestamp twice results in "Wrong type argument: integerp, nil". e.g. if you use it on the argument of a function to prevent having to write (ts-update (make-ts ...)) in all call sites, you have to ensure it doesn't already have a :unix value.
  3. This can't be done by using ts-unix, because of what I perceive as another quirk -
(defvar myts (make-ts :day 2 :month 9 :year 2018)) ; => myts
myts ; => #s(ts nil nil nil 2 9 2018 nil nil nil nil nil nil nil nil nil nil nil)
(ts-unix myts) ; => 1589644050.4842834
(ts-format myts) ; => "2020-05-16 21:17:30 +0530" Yikes ._.

It's possible I'm not using it as envisioned (I'm not very experienced with languages outside of Elisp, especially with their date/time APIs). I'd be happy to be corrected in my usage.

If these are indeed perceived as areas for improvement, hopefully they can help making it a more mature library.

@alphapapa
Copy link
Owner

Hi,

Thanks for the kind words. Your package looks interesting, and I hope this can be helpful to you.

It seems that all of this stems from your item 1. But I'm not sure if filling with zeroes automatically would be the right thing to do. I tend to think that the user ought to do so explicitly, and that this error actually brought to your attention that that's necessary. If the fields were zeroed automatically, it could lead to assumptions and misunderstandings, which could lead to miscalculations, which would lead to other bug reports. :)

ts-format is just a thin wrapper around format-time-string, so you should understand its behavior and what values you are passing to it.

By the way, note that ts-update is documented as being non-destructive, so it is not intended to change the value of its argument. You need to update it yourself, e.g. (setf my-ts (ts-update my-ts)).

Does that help? Let me know what you think. Thanks.

contrapunctus-1 pushed a commit to contrapunctus-1/chronometrist that referenced this issue May 17, 2020
Sadly, it didn't go so well - pretty challenging, lots of debugging,
and plenty of tests failing. Left them some feedback -
alphapapa/ts.el#11
@contrapunctus-1
Copy link
Author

Thank you for your response. I've resorted to writing a helper function to work around it, and it seems like an acceptable solution to this issue.

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