Module: ClassMethods

Defined in:
lib/active_record/connection_adapters/duckdb/timestamp_monkey_patch.rb

Constant Summary collapse

EPOCH_UTC =
Time.utc(1970, 1, 1).freeze

Instance Method Summary collapse

Instance Method Details

#_to_time(year, month, day, hour, minute, second, microsecond) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/active_record/connection_adapters/duckdb/timestamp_monkey_patch.rb', line 71

def _to_time(year, month, day, hour, minute, second, microsecond)
  if ActiveRecord.default_timezone == :utc
    Time.utc(year, month, day, hour, minute, second, microsecond)
  else
    super
  end
end

#_to_time_from_duckdb_time(hour, minute, second, microsecond) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/active_record/connection_adapters/duckdb/timestamp_monkey_patch.rb', line 79

def _to_time_from_duckdb_time(hour, minute, second, microsecond)
  if ActiveRecord.default_timezone == :utc
    Time.utc(1970, 1, 1, hour, minute, second, microsecond)
  else
    super
  end
end

#_to_time_from_duckdb_timestamp_ms(time) ⇒ Object



95
96
97
98
99
100
101
102
# File 'lib/active_record/connection_adapters/duckdb/timestamp_monkey_patch.rb', line 95

def _to_time_from_duckdb_timestamp_ms(time)
  if ActiveRecord.default_timezone == :utc
    tm = EPOCH_UTC + (time / 1000)
    Time.utc(tm.year, tm.month, tm.day, tm.hour, tm.min, tm.sec, time % 1000 * 1000)
  else
    super
  end
end

#_to_time_from_duckdb_timestamp_ns(time) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/active_record/connection_adapters/duckdb/timestamp_monkey_patch.rb', line 104

def _to_time_from_duckdb_timestamp_ns(time)
  if ActiveRecord.default_timezone == :utc
    tm = EPOCH_UTC + (time / 1_000_000_000)
    Time.utc(tm.year, tm.month, tm.day, tm.hour, tm.min, tm.sec, time % 1_000_000_000 / 1000)
  else
    super
  end
end

#_to_time_from_duckdb_timestamp_s(time) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/active_record/connection_adapters/duckdb/timestamp_monkey_patch.rb', line 87

def _to_time_from_duckdb_timestamp_s(time)
  if ActiveRecord.default_timezone == :utc
    EPOCH_UTC + time
  else
    super
  end
end