cron - Rails/MySQL: Different user timezones -
question 1 - have app on shared hosting in dallas, tx...so database/web server set central time...i'm unable change this, utc off table.
my application records , displays date , time data user, every user in different time zone.
if configure app (config.time_zone = 'central time (us & canada)')
, allow users select timezone,
def user_time_zone(&block) time.use_zone(current_user.time_zone, &block) end
will ror display returned data in timezone of user's choice? or need evaluate data , modify accordingly before displayed?
question 1.1 - have related mailers send daily/weekly/monthly reports users. if run these using cron, need schedule jobs @ different time intervals allow timezones? in other words, if 1 job contains
when 'daily' @dates = params[:f]['date range'] = "#{date.current} - #{date.current}"
date.current 1 hour ahead on east coast, , 3 hours behind on west , forth. (still using server timezone of central), run 1 @ 11pm (for east) , 1 @ 2am (for west)?
any , advice/assistance appreciated. thanks!
for best results, application should written such time zone of computer running on not influence data or behavior.
that means working in utc in code. example, time.now.utc
instead of time.now
. see this post details ror.
it best practice set server time zone utc when possible, doesn't mean should rely on in code.
regarding second question, keep in mind every time zone has own concept of "day". see this site visualization.
you should run separate job @ midnight in each time zone aligning data to. applications (such stackexchange web sites) use single time zone (often utc) users. other applications adjust data each user according own time zone. need decide appropriate application.
when scheduling jobs, determine utc time each time zone's midnight aligns to. schedule job time. sure scheduler understands utc. don't try adjust server's local time zone, or might introduce error when local time zone goes through daylight saving time transitions.
make sure not scheduled job run @ correct time, report query uses correct time zone in determining utc range should run for.
note mean 2 users different time zones reporting on same data may end producing different results - because each of "days" different period.
Comments
Post a Comment