andrewplummer/Sugar

How to custom format a time range

subz390 opened this issue · 3 comments

  • Have I missed something in the docs to custom format a range of time?
  • Date.range('00:00', '04:30').seconds() this is fine but I want to understand it in hours and mintues, or even in days, hours, minutes and seconds!
  • Date.range('00:00', '04:30').format('%Hh %Mm') produces a Date.range(...).format is not a function error.
  • so how do I present a range of time in a custom format using Sugar, thanks.

Hi, sorry for the delay... I'm showing Date.range('00:00', '04:30').hours() as working fine... a format method on a Date range isn't a thing now but it certainly could be! I'll mark this as an idea for a new feature.

no problem on the delay, thanks for responding. Of course I could use just hours, just minutes or just seconds. But in a real world application, for example a countdown timer would look silly displaying something like there is 24 hrs 600 min and 12654 seconds remaining it doesn't work like that. Can you imagine a marathon display board, you finished in 2hrs 934 min and 522345 seconds lol!!! You'd expect it to be like there is 24hrs 15 min and 5 seconds remaining. Maybe I'm missunderstanding something about how to use the library but I don't see any way to get the formatted output like that. So currently I get the time remaining result in seconds and then use another function to calculate the resulting hours minutes and seconds. Leaving out any zero results, like when we're down to less than 1 hour it puts out just the min and sec.

Gotcha... well in that regard all I can say is that the DateRange object itself is maybe not as mature as it potentially could be, and I'll definitely take this use case into consideration for the next iteration. For now you I'd say you can achieve what you want with some app-side logic and I'll see what I can do about taking this use case into consideration for an upcoming version... but to answer your immediate question yes for now you're going to have to roll this yourself...