views:

95

answers:

0

I have a rails (2.3.4) application and want to send users a daily update via mail. To make things more comfortable, users can choose the time when they want their daily mail. My question: how should I store and more importantly lookup this time so as users' time zone, in particular daylight savings are respected?

Currently, we save a 'preferred_time' attribute (datetime, rails handles it as ActiveSupport::TimeWithZone) on the user object. So we could do something like

User.find(:all, :conditions => ['preferred_time >= ? and preferred_time <= ?', Time.zone.now, Time.zone.now + 5.minutes)

and run this query every 5 minutes. As this is done in the background, with Time.zone = UTC, this does not really work :-( The main problem: when the user sets this time during winter (dst = false), the offset to dst in summer is not respected.

Any idea?