ruby - Rails: Query database for users with specific time value while respect individual users time zone setting -


i have background job runs every 15 minutes , generates reminder emails. create query returns users have specific time saved , respect how timezone setting effects time.

so have user model stores:

  • :time: users reminder time, eg 17:00:00
  • :string: timezone, eg est

so if job runs @ 17:00:00 est, return users settings are:

  • reminder_time: 17:00:00, time_zone: est
  • reminder_time: 13:00:00, time_zone: pst

what best way build query? can done in 1 pass, relying on postgres handle work? have stagger it, group each time zone , doing math each on in ruby?

i have setup activerecord scope doesn't consider timezones, , trying add consideration now.

scope :receives_reminder_at, -> (time)   ready.where(reminder_time: time) end 

when dealing users in multiple timezones, easiest standardize on utc.

so store reminder_time in utc, way don't have worry tz when querying, since normalized utc. (assuming running servers utc. work expected). use tz offset in order adjust time viewing.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -