File tree Expand file tree Collapse file tree 4 files changed +24
-3
lines changed
lib/active_record/connection_adapters/postgresql
test/cases/adapters/postgresql Expand file tree Collapse file tree 4 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1
1
## Rails 4.0.0 (unreleased) ##
2
2
3
+ * Fix postgresql adapter to handle BC timestamps correctly
4
+
5
+ HistoryEvent.create!(:name => "something", :occured_at => Date.new(0) - 5.years)
6
+
7
+ * Bogdan Gusiev*
8
+
3
9
* When running migrations on Postgresql, the ` :limit ` option for ` binary ` and ` text ` columns is silently dropped.
4
10
Previously, these migrations caused sql exceptions, because Postgresql doesn't support limits on these types.
5
11
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ def string_to_time(string)
8
8
case string
9
9
when 'infinity' ; 1.0 / 0.0
10
10
when '-infinity' ; -1.0 / 0.0
11
+ when / BC$/
12
+ super ( "-" + string . sub ( / BC$/ , "" ) )
11
13
else
12
14
super
13
15
end
Original file line number Diff line number Diff line change @@ -129,11 +129,15 @@ def quote_column_name(name) #:nodoc:
129
129
# Quote date/time values for use in SQL input. Includes microseconds
130
130
# if the value is a Time responding to usec.
131
131
def quoted_date ( value ) #:nodoc:
132
+ result = super
132
133
if value . acts_like? ( :time ) && value . respond_to? ( :usec )
133
- "#{ super } .#{ sprintf ( "%06d" , value . usec ) } "
134
- else
135
- super
134
+ result = "#{ result } .#{ sprintf ( "%06d" , value . usec ) } "
135
+ end
136
+
137
+ if value . year < 0
138
+ result = result . sub ( /^-/ , "" ) + " BC"
136
139
end
140
+ result
137
141
end
138
142
end
139
143
end
Original file line number Diff line number Diff line change @@ -75,6 +75,15 @@ def test_postgres_agrees_with_activerecord_about_precision
75
75
assert_equal '4' , pg_datetime_precision ( 'foos' , 'updated_at' )
76
76
end
77
77
78
+ def test_bc_timestamp
79
+ unless current_adapter? ( :PostgreSQLAdapter )
80
+ return skip ( "only tested on postgresql" )
81
+ end
82
+ date = Date . new ( 0 ) - 1 . second
83
+ Developer . create! ( :name => "aaron" , :updated_at => date )
84
+ assert_equal date , Developer . find_by_name ( "aaron" ) . updated_at
85
+ end
86
+
78
87
private
79
88
80
89
def pg_datetime_precision ( table_name , column_name )
You can’t perform that action at this time.
0 commit comments