Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure all time zones work for ActiveSupport::TimeWithZone #35

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ignore:
- 'lib/**/*':
- Style/ArgumentsForwarding
ruby_version: 2.7
format: progress
parallel: true
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
UniversalID::MessagePackFactory.register(
type: ActiveSupport::TimeWithZone,
packer: ->(obj, packer) do
packer.write obj.iso8601(9)
packer.write obj.zone
packer.write obj.to_time.utc
packer.write obj.time_zone.tzinfo.identifier
end,
unpacker: ->(unpacker) do
time = Time.parse(unpacker.read)
zone = unpacker.read
ActiveSupport::TimeWithZone.new time, ActiveSupport::TimeZone[zone]
utc = unpacker.read
tz = unpacker.read
utc.in_time_zone ActiveSupport::TimeZone[tz]
end
)

Expand Down
2 changes: 1 addition & 1 deletion lib/universalid/message_pack_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
require_relative "message_pack_types/ruby/composites/set"

# extensions
Dir["#{__dir__}/extensions/**/*.rb"].each { |f| require f }
Dir["#{__dir__}/extensions/**/*.rb"].sort.each { |f| require f }

UniversalID::MessagePackFactory.create_msgpack_pool
1 change: 1 addition & 0 deletions test/test_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require "minitest/reporters"
require "model_probe"
require "simplecov"
require "timecop"

# MiniTest setup
Minitest.parallel_executor = Minitest::Parallel::Executor.new([Etc.nprocessors, 1].max) # thread count
Expand Down
24 changes: 24 additions & 0 deletions test/universalid/extensions/active_support/time_with_zone_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class TimeWithZoneTest < Minitest::Test
def test_marshaling_with_universal_id_for_all_active_support_time_zones
month = ActiveSupport::TimeZone["UTC"].now.beginning_of_year

Timecop.freeze time do
11.times do |i|
ActiveSupport::TimeZone.all.each do |time_zone|
time = month.in_time_zone(time_zone).advance(days: rand(1..28), minutes: rand(1..59))

assert time.is_a?(ActiveSupport::TimeWithZone)

uri = URI::UID.build(time).to_s
decoded = URI::UID.parse(uri).decode

assert_equal time, decoded
end

month.advance months: 1
end
end
end
end
1 change: 1 addition & 0 deletions universalid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "simplecov"
s.add_development_dependency "sqlite3"
s.add_development_dependency "standard", ">= 1.32"
s.add_development_dependency "timecop"
end
Loading