Skip to content

Instantly share code, notes, and snippets.

@Envek
Last active September 2, 2015 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Envek/3cd94d76f1ccd84b0253 to your computer and use it in GitHub Desktop.
Save Envek/3cd94d76f1ccd84b0253 to your computer and use it in GitHub Desktop.
Bug report of incorrect parsing of time when assigning to time attributes.
# For Ruby on Rails master branch
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :bus_stop_schedules, force: true do |t|
t.time :arrival
end
end
class BusStopSchedule < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_time_with_utc_offset
sched = BusStopSchedule.new
sched.arrival = "2015-06-13T19:45:54+03:00"
assert_equal "2000-01-01T16:45:54Z", sched.arrival.iso8601
sched.arrival = "06:07:08+09:00"
assert_equal "2000-01-01T21:07:08Z", sched.arrival.iso8601
end
end
# For Ruby on Rails 4.1.x
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '~> 4.1.13'
gem 'sqlite3'
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :bus_stop_schedules, force: true do |t|
t.time :arrival
end
end
class BusStopSchedule < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_time_with_utc_offset
sched = BusStopSchedule.new
sched.arrival = "2015-06-13T19:45:54+03:00"
assert_equal "2000-01-01T16:45:54Z", sched.arrival.iso8601
sched.arrival = "06:07:08+09:00"
assert_equal "2000-01-01T21:07:08Z", sched.arrival.iso8601
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment