Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Apply Timezone To

Apply Timezone To

== When we have date/time values that are sensitive to timezones, and we wish to only store GMT date/time in databases, the usual routine is to:

  • declare ‘composed_of’ using TZInfo::Timezone
  • at after_find, convert the GMT values to timezone value
  • at before_save, convert the timezone value to GMT (and at after_save, convert the variable back to timezone value)

Instead of doing all these, just use

apply_timezone_to [:commence_at, :terminate_at]

This will make ‘commence_at’ and ‘terminate_at’ store GMT values in database, but work with timezone values everywhere else. The statement above assumes column ‘timezone’ contains the timezone string, e.g. ‘Asia/Singapore’. To specify your custom column, simply append to the declaration:

apply_timezone_to [:commence_at, :terminate_at], :tzname

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly

Users


See all details


Membership

+ Join this railsplugin

Record Maintainer

'None'