Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4492: timezone.patch

File timezone.patch, 4.8 kB (added by zenspider, 2 years ago)

timezone support for abstract and postgresql

  • active_record/connection_adapters/abstract/schema_definitions.rb

    old new  
    3737        case type 
    3838          when :integer       then Fixnum 
    3939          when :float         then Float 
     40          when :datetime_with_timezone then Time 
    4041          when :datetime      then Time 
    4142          when :date          then Date 
    4243          when :timestamp     then Time 
     
    5556          when :text      then value 
    5657          when :integer   then value.to_i rescue value ? 1 : 0 
    5758          when :float     then value.to_f 
     59          when :datetime_with_timezone then self.class.string_to_time(value) 
    5860          when :datetime  then self.class.string_to_time(value) 
    5961          when :timestamp then self.class.string_to_time(value) 
    6062          when :time      then self.class.string_to_dummy_time(value) 
     
    7173          when :text      then nil 
    7274          when :integer   then "(#{var_name}.to_i rescue #{var_name} ? 1 : 0)" 
    7375          when :float     then "#{var_name}.to_f" 
     76          when :datetime_with_timezone then "#{self.class.name}.string_to_time(#{var_name})" 
    7477          when :datetime  then "#{self.class.name}.string_to_time(#{var_name})" 
    7578          when :timestamp then "#{self.class.name}.string_to_time(#{var_name})" 
    7679          when :time      then "#{self.class.name}.string_to_dummy_time(#{var_name})" 
     
    108111 
    109112      def self.string_to_time(string) 
    110113        return string unless string.is_a?(String) 
    111         time_array = ParseDate.parsedate(string)[0..5
     114        time_array = ParseDate.parsedate(string)[0..6
    112115        # treat 0000-00-00 00:00:00 as nil 
    113116        Time.send(Base.default_timezone, *time_array) rescue nil 
    114117      end 
     
    141144              :integer 
    142145            when /float|double|decimal|numeric/i 
    143146              :float 
     147            when /datetime.with.timezone/i 
     148              :datetime_with_timezone 
    144149            when /datetime/i 
    145150              :datetime 
    146151            when /timestamp/i 
     
    207212      # The +type+ parameter must be one of the following values: 
    208213      # <tt>:primary_key</tt>, <tt>:string</tt>, <tt>:text</tt>, 
    209214      # <tt>:integer</tt>, <tt>:float</tt>, <tt>:datetime</tt>, 
    210       # <tt>:timestamp</tt>, <tt>:time</tt>, <tt>:date</tt>, 
    211       # <tt>:binary</tt>, <tt>:boolean</tt>. 
     215      # <tt>:datetime_with_timezone</tt>, <tt>:timestamp</tt>, 
     216      # <tt>:time</tt>, <tt>:date</tt>, <tt>:binary</tt>, 
     217      # <tt>:boolean</tt>. 
    212218      # 
    213219      # Available options are (none of these exists by default): 
    214220      # * <tt>:limit</tt>: 
  • active_record/connection_adapters/postgresql_adapter.rb

    old new  
    8989          :integer     => { :name => "integer" }, 
    9090          :float       => { :name => "float" }, 
    9191          :datetime    => { :name => "timestamp" }, 
     92          :datetime_with_timezone => { :name => "timestamp with timezone" }, 
    9293          :timestamp   => { :name => "timestamp" }, 
    9394          :time        => { :name => "time" }, 
    9495          :date        => { :name => "date" }, 
     
    457458        def translate_field_type(field_type) 
    458459          # Match the beginning of field_type since it may have a size constraint on the end. 
    459460          case field_type 
     461            when /^timestamp with time zone/i    then 'datetime_with_timezone' 
    460462            when /^timestamp/i    then 'datetime' 
    461463            when /^real|^money/i  then 'float' 
    462464            when /^interval/i     then 'string' 
  • active_record/migration.rb

    old new  
    6363  # * <tt>drop_table(name)</tt>: Drops the table called +name+. 
    6464  # * <tt>add_column(table_name, column_name, type, options)</tt>: Adds a new column to the table called +table_name+ 
    6565  #   named +column_name+ specified to be one of the following types: 
    66   #   :string, :text, :integer, :float, :datetime, :timestamp, :time, :date, :binary, :boolean. A default value can be specified 
     66  #   :string, :text, :integer, :float, :datetime, :datetime_with_timezone, :timestamp, :time, :date, :binary, :boolean. A default value can be specified 
    6767  #   by passing an +options+ hash like { :default => 11 }. 
    6868  # * <tt>rename_column(table_name, column_name, new_column_name)</tt>: Renames a column but keeps the type and content. 
    6969  # * <tt>change_column(table_name, column_name, type, options)</tt>:  Changes the column to a different type using the same