Sterling Rose Design Blog
Perpetual Footer
Authored by Dana Jones
May 10, 2009 21:39
2 Comments
Tags: date and time Rails
Authored by Dana Jones
May 10, 2009 21:39
2 Comments
Tags: date and time Rails
I was spinning up a brand new client website that would (like most websites) include a copyright footer. I wanted to make sure I wouldn’t have to come back year after year and update the year span, so here is what I used:
It will display only 2009 as the copyright year until January 1, 2010, then it will start displaying a span (from 2009 through the current year). Simple.
Uses Rails 2.3.2
© 2009<%= "-#{Date.today.year}" if Date.today.year != 2009 %> ABC CompanyIt will display only 2009 as the copyright year until January 1, 2010, then it will start displaying a span (from 2009 through the current year). Simple.
Uses Rails 2.3.2
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:

