Skip to content

Commit 489b6b2

Browse files
committed
fix: use TimeWithZone for time type, but timezone doesn't affect any changes
1 parent 8e7df4a commit 489b6b2

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

lib/embulk/output/bigquery/value_converter_factory.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,13 @@ def string_converter
225225
}
226226
end
227227
when 'TIME'
228-
if @timestamp_format
229-
Proc.new {|val|
230-
next nil if val.nil?
231-
with_typecast_error(val) do |val|
232-
Time.strptime(val, @timestamp_format).strftime("%H:%M:%S.%6N")
233-
end
234-
}
235-
else
236-
Proc.new {|val|
237-
next nil if val.nil?
238-
Time.parse(val).strftime("%H:%M:%S.%6N")
239-
}
240-
end
228+
# TimeWithZone doesn't affect any change to the time value
229+
Proc.new {|val|
230+
next nil if val.nil?
231+
with_typecast_error(val) do |val|
232+
TimeWithZone.set_zone_offset(Time.parse(val), zone_offset).strftime("%H:%M:%S.%6N")
233+
end
234+
}
241235
when 'RECORD'
242236
Proc.new {|val|
243237
next nil if val.nil?

test/test_value_converter_factory.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,15 @@ def test_time
268268
assert_equal "00:03:22.000000", converter.call("00:03:22")
269269
assert_equal "15:22:00.000000", converter.call("3:22 PM")
270270
assert_equal "03:22:00.000000", converter.call("3:22 AM")
271-
272-
# Users must care of BQ datetime format by themselves with no timestamp_format
273-
converter = ValueConverterFactory.new(SCHEMA_TYPE, 'TIME').create_converter
274-
assert_equal nil, converter.call(nil)
275271
assert_equal "00:00:00.000000", converter.call("2016-02-26 00:00:00")
272+
273+
# TimeWithZone doesn't affect any change to the time value
274+
converter = ValueConverterFactory.new(
275+
SCHEMA_TYPE, 'TIME', timezone: 'Asia/Tokyo'
276+
).create_converter
277+
assert_equal "15:00:01.000000", converter.call("15:00:01")
278+
279+
assert_raise { converter.call('foo') }
276280
end
277281

278282
def test_record

0 commit comments

Comments
 (0)