jiffy icon indicating copy to clipboard operation
jiffy copied to clipboard

Is there a way to get a difference between dates without specifying units?

Open MiguelSOliveira opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. Jiffy({ "year": 2007, "month": 1, "day": 28 }).diff([2017, 1, 29], Units.DAY); // 1

I would like to have a difference method that would choose the most logical units without me having to specify it.

Describe the solution you'd like For example:

  • Difference is 0.3 minutes => would display 18 seconds
  • Difference is 61 minutes => would display 1 hour and 1 minute
  • Difference is 26h42mins => would display 1 day, 2 hours and 42 minutes

Describe alternatives you've considered The only alternative right now that I can see is the relative time methods, but I don't want the "ago" suffix.

This would be very useful, in my opinion, for when you want to display the time something took to do, when you have the initial timestamp and the ending timestamp and want to see the difference between the two.

Thank you.

MiguelSOliveira avatar Aug 15 '20 20:08 MiguelSOliveira

@MiguelSOliveira This feature is not available in Jiffy, but will be cool to add it.

Do you have any ideas

jama5262 avatar Mar 01 '21 13:03 jama5262

Off the top of my head, it may be possible to retrieve the object as a string using toString() and then doing a split() on the string. Maybe that will work. You could refer to this link:

String .split() method

flutternoob avatar Apr 30 '21 19:04 flutternoob

https://github.com/jama5262/jiffy/pull/218

jama5262 avatar Mar 09 '23 12:03 jama5262