File: active_support_helper.rb

package info (click to toggle)
ruby-oj 3.16.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,208 kB
  • sloc: ansic: 20,079; ruby: 11,650; sh: 70; makefile: 17
file content (39 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require 'active_support/time'

module Oj
  # Exists only to handle the ActiveSupport::TimeWithZone.
  class ActiveSupportHelper
    def self.createTimeWithZone(utc, zone)
      ActiveSupport::TimeWithZone.new(utc - utc.gmt_offset, ActiveSupport::TimeZone[zone])
    end
  end
end

Oj.register_odd(ActiveSupport::TimeWithZone, Oj::ActiveSupportHelper, :createTimeWithZone, :utc, 'time_zone.name')

# This is a hack to work around an oddness with DateTime and the ActiveSupport
# that causes a hang when some methods are called from C. Hour, min(ute),
# sec(ond) and other methods are special but they can be called from C until
# activesupport/time is required. After that they can not be even though
# resond_to? returns true. By defining methods to call super the problem goes
# away. There is obviously some magic going on under the covers that I don't
# understand.
class DateTime
  def hour()
    super
  end
  def min()
    super
  end
  def sec()
    super
  end
  def sec_fraction()
    super
  end
  def offset()
    super
  end
end