Patch #41954 » 0004-Support-time-offset-for-datetime-column-value.patch
| lib/tasks/extract_fixtures.rake | ||
|---|---|---|
| 20 | 20 | |
| 21 | 21 |
task :extract_fixtures => :environment do |
| 22 | 22 |
dir = ENV['DIR'] || './tmp/fixtures' |
| 23 |
time_offset = ENV['TIME_OFFSET'] || '' |
|
| 24 | ||
| 23 | 25 |
FileUtils.mkdir_p(dir) |
| 26 |
if time_offset.present? && !time_offset.match?(/^([+-](0[0-9]|1[0-4]):[0-5][0-9])$/) |
|
| 27 |
abort("Invalid TIME_OFFSET format. Use +HH:MM or -HH:MM (e.g. +09:00)")
|
|
| 28 |
end |
|
| 24 | 29 | |
| 25 | 30 |
skip_tables = ["schema_migrations", "ar_internal_metadata"] |
| 26 | 31 |
ActiveRecord::Base.establish_connection |
| ... | ... | |
| 38 | 43 |
if record[col.name] |
| 39 | 44 |
record[col.name] = ActiveRecord::Type.lookup(col.type).deserialize(record[col.name]) |
| 40 | 45 |
if col.type == :datetime && record[col.name].is_a?(Time) |
| 41 |
record[col.name] = record[col.name].getutc |
|
| 46 |
if time_offset.present? |
|
| 47 |
record[col.name] = record[col.name].localtime(time_offset) |
|
| 48 |
else |
|
| 49 |
record[col.name] = record[col.name].getutc |
|
| 50 |
end |
|
| 42 | 51 |
end |
| 43 | 52 |
end |
| 44 | 53 |
end |