rubysequel

How to convert output timezone per query in sequel ruby?


I wanted to be able to set timezone in each query depending on my user's preferred timezone without adding timezone conversion in each raw sql generated by my application.

I was able to query/retrieve the records in 'Asia/Manila' TZ using this config

Sequel.extension :named_timezones
Sequel.application_timezone = 'Asia/Manila'

Is it possible to set application_timezone per query so that I will pass the current application user's timezone in each request.


Solution

  • You probably want to use Sequel's thread_local_timezones extension: http://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/thread_local_timezones_rb.html

    This is per thread, not per query, but should hopefully still work for your needs.