Best practices for handling time calculations in Rails

Hey everyone, I’ve been working on a small tool https://calculateurheure.fr/ that helps users calculate time differences and durations pretty quickly. I built it with simplicity in mind, but now I’m thinking about how it could scale or integrate better with a Rails backend if I expand its features.

I’m curious how you would approach handling time calculations and user input in a Rails app, especially considering time zones, daylight saving changes, and performance when calculations get more complex. Would you rely mostly on built-in Ruby/Rails time helpers, or bring in specialized gems/services for accuracy and flexibility?

Also, from a practical standpoint, if you were turning a simple tool like this into a more full-featured Rails application (user accounts, saved calculations, maybe APIs), what would be your recommended structure or best practices early on?

Thanks in advance!

I would stick with the Rails data and time methods. From what I’ve seen, the methods are fine. The challenge is for the developer to understand their particular use case, and then use the methods correctly. The scope of what I mean by “understanding the use case” is a bit beyond what I can mention her. I’ll just say that the concept of “time” depends on what it is you’re using it for.

You asked whether you should “bring in specialized gems/services for accuracy and flexibility” and that makes me wonder a few things:

  • In what ways do you find the Rails methods inaccurate and inflexible?
  • What specialized gems or services are you thinking of?

I’m genuinely curious to hear what challenges you’re running into and the solutions/gems you’ve found.