Timezone Fu plugin

Plugin details

timezone_fu makes it really easy to deal with multiple timezones within a Rails Model. The plugin-in assumes that there is a model attribute called timezone that can be used for conversion.

Websitehttp://hackd.wordpress.com/2007/11/23/sexy-time-zones-in-ruby-on-rails-with-timezone_fu/ Repositoryhttp://www.thrivesmart.com/open_source/timezone_fu/ Tags TimeZone, Time LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install http://www.thrivesmart.com/open_source/timezone_fu/

In the model there is one method to enable this plugin-in: has_timezone.

has_attachment(options = {})


This method takes the following hash options:
:fields => [ ] # array of fields you would like converted to local time automatically.
:time_format => A string formatted for strftime (used by the display methods)
:default_timezone => What timezone you want to use for conversions (used if the model's timezone attribute is empty.)

The plugin creates the following methods for each field passed in the fields array:
:field_name - accessor that returns the field value formatted in local time
:field_name=(val) - set the field's value to a time (in local time)
:utc_field_name - accessor that returns the field value formatted in UTC time.

Example Usage:

  class Event < ActiveRecord::Base
    has_timezone :fields => [ :start_datetime, :end_datetime]
  end
  
  event = Event.find(:first)
  => #"2007-11-21 15:00:00", "start_datetime"=>"2007-11-21 14:15:00", "timezone"=>"America/New_York"]
  
  >> event.start_datetime
  => Wed Nov 21 09:15:00 UTC 2007
  
  >> event.display_start_datetime
  => "Nov. 21, 2007 09:15 AM"
  
  >> event.utc_start_datetime
  => Wed Nov 21 14:15:00 UTC 2007

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: Guest, 5 months ago