bubble-table icon indicating copy to clipboard operation
bubble-table copied to clipboard

Feature Request: Allow sorting by a 'Time' column

Open MaximilianSoerenPollak opened this issue 1 year ago • 1 comments

Currently sorting (in either direction) is available by sorting strings or numbers. I think a usecase that probably will happen also quite a bit would be to sort by a column that is a 'time.Time'.

Would this be some functionality that is interesting to add?

Not sure how it should / would work, maybe a new function or just integrating a test if it's a time into the current sorting func.

MaximilianSoerenPollak avatar Nov 02 '24 08:11 MaximilianSoerenPollak

The short answer is yes, that sounds useful to have available and shouldn't break any existing workflows that I could conceive of. Easiest thing to do would be to add a test to try it, and if it fails then we can add it in. It would be nice to have a test for that regardless, if you're willing to tinker.

I would generally expect this to already work, though. Sorting just tries to extract a string version of the inner value, which should be sortable as dates in Go are in a nice sortable ISO format: 2009-11-10 23:00:00 +0000 UTC m=+0.000000001

That being said, it's not perfect. If some times are in different timezones, for example, there may technically be some differences, but this feels like a weird edge case.

Also that being said, the current way is far from efficient. It has to turn each date into a full string, then compare the strings. It would be much faster if it was a direct comparison of time.Time values, so this may still be worth doing for performance reasons.

Evertras avatar Nov 02 '24 13:11 Evertras