Sterling Rose Design Blog
Rendering datetime in a user's timezone
Authored by Dana Jones
January 13, 2009 21:46
0 Comments
Tags: Rails date and time
Authored by Dana Jones
January 13, 2009 21:46
0 Comments
Tags: Rails date and time
We recently had a client who wanted to account for a user’s time zone when they entered dates for various fields. For example, if a user were to input a new bill, the bill entry date should default to the current date.
The solution to this problem involved 1) storing a user’s time zone in a string field in the User model, and 2) adjusting
For part 1, we used Rails’ built-in
For part 2, the solution was to add a method to the User model to get the user’s current date:
Read the whole post...Time.now is what we had been using, but that would only give the right date if you were on the correct side of the magic UTC dividing line. The solution to this problem involved 1) storing a user’s time zone in a string field in the User model, and 2) adjusting
Time.now for that time zone.For part 1, we used Rails’ built-in
time_zone_select method:<%= form.label :time_zone, "Time Zone" %>
<%= time_zone_select :time_zone, @user.time_zone, nil, :default =>
"Pacific Time (US & Canada)" %>For part 2, the solution was to add a method to the User model to get the user’s current date:
Does the world really need another Rails blog?
Authored by Dana Jones
January 05, 2009 16:28
2 Comments
Tags: announcements
Authored by Dana Jones
January 05, 2009 16:28
2 Comments
Tags: announcements
After a few weeks of coding it, I’ve finally kicked off my first purely “professional” weblog. I’ve been coding in Ruby on Rails for a little over a year now, and decided it was about time for me to start sharing some of the things I’ve learned and discovered and figured out.
This is not a news/announcements aggregation site. There are plenty of those out there, doing it much better than I have the time for.
So what are you likely to see here? Code snippets, tutorials (probably starting with a series on how to build a blog just like this one), obscure API documentation, mentions of plugins I’ve found useful or cool, etc. I plan to focus on some of the most commonly-used web functionality, with focus on doing things “the Rails Way” as much as possible.
This is not a news/announcements aggregation site. There are plenty of those out there, doing it much better than I have the time for.
So what are you likely to see here? Code snippets, tutorials (probably starting with a series on how to build a blog just like this one), obscure API documentation, mentions of plugins I’ve found useful or cool, etc. I plan to focus on some of the most commonly-used web functionality, with focus on doing things “the Rails Way” as much as possible.

