workaround_active_job_time_serialization.rb 874 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Required workaround to serialize ActiveSupport::TimeWithZone, Time, Date and DateTime for ActiveJob
  2. # until Rails 6 is used. See:
  3. # - https://github.com/rails/rails/issues/18519
  4. # - https://github.com/rails/rails/pull/32026
  5. # - https://github.com/rails/rails/tree/6-0-stable/activejob/lib/active_job/serializers
  6. class ActiveSupport::TimeWithZone
  7. include GlobalID::Identification
  8. alias id iso8601
  9. def self.find(iso8601)
  10. Time.iso8601(iso8601).in_time_zone
  11. end
  12. end
  13. class Time
  14. include GlobalID::Identification
  15. alias id iso8601
  16. def self.find(iso8601)
  17. Time.iso8601(iso8601)
  18. end
  19. end
  20. class Date
  21. include GlobalID::Identification
  22. alias id iso8601
  23. def self.find(iso8601)
  24. Date.iso8601(iso8601)
  25. end
  26. end
  27. class DateTime
  28. include GlobalID::Identification
  29. alias id iso8601
  30. def self.find(iso8601)
  31. DateTime.iso8601(iso8601)
  32. end
  33. end