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 custom format a time range #656

Open
subz390 opened this issue Aug 10, 2019 · 3 comments
Open

How to custom format a time range #656

subz390 opened this issue Aug 10, 2019 · 3 comments
Labels

Comments

@subz390
Copy link

subz390 commented Aug 10, 2019

  • 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.
@andrewplummer
Copy link
Owner

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.

@subz390
Copy link
Author

subz390 commented Aug 17, 2019

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.

@andrewplummer
Copy link
Owner

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants