I have a rails app with a data model called 'jobs' and I'm faced with a critical design choice crossroads.

I don't know enough about Rails and its inner workings to be able to say for sure what I should do despite a complete read of the rails and ruby docs.

I want to be able to accurately display the age of a job record in days. So when a customer logs in, they can see that the job they submitted is 'x' days old.

Where does a rails app on Heroku get its time stamps? From Heroku? Or the customers system clock?

If a customer has a out of date system clock and submits a job, it could really mess up the sorting of their job list, not to mention me the overseer of job records.

Any advice out there?

EDIT: Just to be clear, i'm not asking how to list jobs by their date, but to which clock does a rails app on Heroku base it's records.

  • 1
    The clock on the server - it's all processed serverside. If the app blindly trusted the user's clock, very bad things could happen. – sevenseacat Jun 4 '14 at 1:06
  • You can see the effects with Stack Overflow. My "new day"'s always start at 8pm as I am in EST – Michael Durrant Jun 4 '14 at 10:47

The touch method updates the updated_at field and save the record. Looking at it's source code we can see it takes the timestamp from current_time_from_proper_timezone. Looking at it's source code we can see it uses a Time.now to fetch the time. Time.now is an alias to Time.new, which creates a Time object that according to the documentation "is initialized to the current system time if no argument is given".

Since all that runs on the server, it uses the local time of the server. So as long as you don't use JavaScript on the clients machines to calculate the durations, they should be accurate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.